Skip to content

Commit ef81481

Browse files
author
sascha
committed
parameters: added PASSYS_STRING128, its maybe used for PARSYS_SYSNAME; parser: added join_comm_thread and add_callback_and_block
git-svn-id: http://isvn/svn/rep_IEP-I000261_LINUX-KERNEL/01_Entwicklung/trunk/10_Entwicklung/28_SW_Komponente_XCOM/30_IMPL/XCOM_Client_Python/dependencies/ixcom-public@12242 fa3a88b2-825e-5648-bb98-bb0d4e3c2968
1 parent 71f56ef commit ef81481

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

ixcom/parameters.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ class PARSYS_STRING64_Payload(DefaultParameterPayload):
1414
PayloadItem(name = 'str', dimension = 64, datatype = 's')
1515
])
1616

17+
class PARSYS_STRING128_Payload(DefaultParameterPayload):
18+
parameter_payload = Message([
19+
PayloadItem(name = 'str', dimension = 128, datatype = 's')
20+
])
21+
1722
@parameter(0)
1823
class PARSYS_PRJNUM_Payload(PARSYS_STRING_Payload):
1924
pass

ixcom/parser.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,13 @@ def add_subscriber(self, subscriber):
165165
def add_callback(self, callback):
166166
self.callbacks += [callback]
167167

168+
def add_callback_and_block(self, callback):
169+
'''Add a callback function and joins the communication thread.
170+
Call stop() in a callback function the stop the communication thread and continue.
171+
'''
172+
self.callbacks += [callback]
173+
self.join_comm_thread.join()
174+
168175
def remove_callback(self, callback):
169176
self.callbacks.remove(callback)
170177

@@ -217,12 +224,21 @@ def __init__(self, host, port=GENERAL_PORT, timeout = WAIT_TIME_FOR_RESPONSE):
217224

218225
self.add_subscriber(self)
219226

220-
221227
def _create_socket_and_connect(self):
222228
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
223229
self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
224230
self.sock.connect((self.host, self.port))
225231

232+
def join_comm_thread(self):
233+
'''Join the communication thread
234+
Blocks the calling location until the communications thread terminates.
235+
Can e.g. be used if callbacks have been set up, logs have been requested and we just want to
236+
leave the program running like this until the communications with the device stop.
237+
Args:
238+
self
239+
'''
240+
self._comm_thread.join()
241+
226242
def stop(self):
227243
self._stop_event.set()
228244
self._comm_thread.join()

0 commit comments

Comments
 (0)