@@ -34,10 +34,10 @@ class SdoClient(collections.Mapping):
34
34
"""Handles communication with an SDO server."""
35
35
36
36
#: Max time in seconds to wait for response from server
37
- RESPONSE_TIMEOUT = 0.5
37
+ RESPONSE_TIMEOUT = 0.3
38
38
39
39
#: Max number of request retries before raising error
40
- MAX_RETRIES = 5
40
+ MAX_RETRIES = 3
41
41
42
42
def __init__ (self , node_id , od ):
43
43
#: Node ID
@@ -222,6 +222,45 @@ def set_data(self, data):
222
222
force_segment = self .od .data_type == objectdictionary .DOMAIN
223
223
self .sdo_node .download (self .od .index , self .od .subindex , data , force_segment )
224
224
225
+ def read (self , fmt = "raw" ):
226
+ """Alternative way of reading using a function instead of attributes.
227
+
228
+ May be useful for asynchronous reading.
229
+
230
+ :param str fmt:
231
+ How to return the value
232
+ - 'raw'
233
+ - 'phys'
234
+ - 'desc'
235
+
236
+ :returns:
237
+ The value of the variable.
238
+ """
239
+ if fmt == "raw" :
240
+ return self .raw
241
+ elif fmt == "phys" :
242
+ return self .phys
243
+ elif fmt == "desc" :
244
+ return self .desc
245
+
246
+ def write (self , value , fmt = "raw" ):
247
+ """Alternative way of writing using a function instead of attributes.
248
+
249
+ May be useful for asynchronous writing.
250
+
251
+ :param str fmt:
252
+ How to write the value
253
+ - 'raw'
254
+ - 'phys'
255
+ - 'desc'
256
+ """
257
+ if fmt == "raw" :
258
+ self .raw = value
259
+ elif fmt == "phys" :
260
+ self .phys = value
261
+ elif fmt == "desc" :
262
+ self .desc = value
263
+
225
264
def open (self , mode = "rb" , encoding = "ascii" , buffering = 112 ):
226
265
"""Open the data stream as a file like object.
227
266
@@ -286,11 +325,12 @@ def __init__(self, sdo_client, index, subindex=0):
286
325
self .sdo_client = sdo_client
287
326
self .command = REQUEST_SEGMENT_UPLOAD
288
327
328
+ logger .debug ("Reading 0x%X:%d from node %d" , index , subindex , sdo_client .id )
289
329
request = SDO_STRUCT .pack (REQUEST_UPLOAD , index , subindex )
290
330
request += b"\x00 \x00 \x00 \x00 "
291
331
response = sdo_client .send_request (request )
292
332
res_command , res_index , res_subindex = SDO_STRUCT .unpack (response [0 :4 ])
293
- res_data = response [4 :]
333
+ res_data = response [4 :8 ]
294
334
295
335
if res_command & 0xE0 != RESPONSE_UPLOAD :
296
336
raise SdoCommunicationError ("Unexpected response 0x%02X" % res_command )
@@ -312,6 +352,9 @@ def __init__(self, sdo_client, index, subindex=0):
312
352
self .exp_data = res_data [:self .size ]
313
353
elif res_command & SIZE_SPECIFIED :
314
354
self .size , = struct .unpack ("<L" , res_data )
355
+ logger .debug ("Using segmented transfer of %d bytes" , self .size )
356
+ else :
357
+ logger .debug ("Using segmented transfer" )
315
358
316
359
def read (self , size = - 1 ):
317
360
"""Read one segment which may be up to 7 bytes.
0 commit comments