@@ -156,7 +156,7 @@ def download(self, index, subindex, data, force_segment=False):
156
156
fp .close ()
157
157
158
158
def open (self , index , subindex = 0 , mode = "rb" , encoding = "ascii" ,
159
- buffering = 1024 , size = None , block_transfer = False , force_segment = False ):
159
+ buffering = 1024 , size = None , block_transfer = False , force_segment = False , request_crc_support = True ):
160
160
"""Open the data stream as a file like object.
161
161
162
162
:param int index:
@@ -186,14 +186,16 @@ def open(self, index, subindex=0, mode="rb", encoding="ascii",
186
186
If block transfer should be used.
187
187
:param bool force_segment:
188
188
Force use of segmented download regardless of data size.
189
-
189
+ :param bool request_crc_support:
190
+ If crc calculation should be requested when using block transfer
191
+
190
192
:returns:
191
193
A file like object.
192
194
"""
193
195
buffer_size = buffering if buffering > 1 else io .DEFAULT_BUFFER_SIZE
194
196
if "r" in mode :
195
197
if block_transfer :
196
- raw_stream = BlockUploadStream (self , index , subindex )
198
+ raw_stream = BlockUploadStream (self , index , subindex , request_crc_support = request_crc_support )
197
199
else :
198
200
raw_stream = ReadableStream (self , index , subindex )
199
201
if buffering :
@@ -202,7 +204,7 @@ def open(self, index, subindex=0, mode="rb", encoding="ascii",
202
204
return raw_stream
203
205
if "w" in mode :
204
206
if block_transfer :
205
- raw_stream = BlockDownloadStream (self , index , subindex , size )
207
+ raw_stream = BlockDownloadStream (self , index , subindex , size , request_crc_support = request_crc_support )
206
208
else :
207
209
raw_stream = WritableStream (self , index , subindex , size , force_segment )
208
210
if buffering :
@@ -447,14 +449,16 @@ class BlockUploadStream(io.RawIOBase):
447
449
448
450
crc_supported = False
449
451
450
- def __init__ (self , sdo_client , index , subindex = 0 ):
452
+ def __init__ (self , sdo_client , index , subindex = 0 , request_crc_support = True ):
451
453
"""
452
454
:param canopen.sdo.SdoClient sdo_client:
453
455
The SDO client to use for reading.
454
456
:param int index:
455
457
Object dictionary index to read from.
456
458
:param int subindex:
457
459
Object dictionary sub-index to read from.
460
+ :param bool request_crc_support:
461
+ If crc calculation should be requested when using block transfer
458
462
"""
459
463
self ._done = False
460
464
self .sdo_client = sdo_client
@@ -467,7 +471,9 @@ def __init__(self, sdo_client, index, subindex=0):
467
471
sdo_client .rx_cobid - 0x600 )
468
472
# Initiate Block Upload
469
473
request = bytearray (8 )
470
- command = REQUEST_BLOCK_UPLOAD | INITIATE_BLOCK_TRANSFER | CRC_SUPPORTED
474
+ command = REQUEST_BLOCK_UPLOAD | INITIATE_BLOCK_TRANSFER
475
+ if request_crc_support :
476
+ command |= CRC_SUPPORTED
471
477
struct .pack_into ("<BHBBB" , request , 0 ,
472
478
command , index , subindex , self .blksize , 0 )
473
479
response = sdo_client .request_response (request )
@@ -597,7 +603,7 @@ def readable(self):
597
603
class BlockDownloadStream (io .RawIOBase ):
598
604
"""File like object for block download."""
599
605
600
- def __init__ (self , sdo_client , index , subindex = 0 , size = None ):
606
+ def __init__ (self , sdo_client , index , subindex = 0 , size = None , request_crc_support = True ):
601
607
"""
602
608
:param canopen.sdo.SdoClient sdo_client:
603
609
The SDO client to use for communication.
@@ -607,6 +613,8 @@ def __init__(self, sdo_client, index, subindex=0, size=None):
607
613
Object dictionary sub-index to read from.
608
614
:param int size:
609
615
Size of data in number of bytes if known in advance.
616
+ :param bool request_crc_support:
617
+ If crc calculation should be requested when using block transfer
610
618
"""
611
619
self .sdo_client = sdo_client
612
620
self .size = size
@@ -615,7 +623,9 @@ def __init__(self, sdo_client, index, subindex=0, size=None):
615
623
self ._seqno = 0
616
624
self ._crc = sdo_client .crc_cls ()
617
625
self ._last_bytes_sent = 0
618
- command = REQUEST_BLOCK_DOWNLOAD | INITIATE_BLOCK_TRANSFER | CRC_SUPPORTED
626
+ command = REQUEST_BLOCK_DOWNLOAD | INITIATE_BLOCK_TRANSFER
627
+ if request_crc_support :
628
+ command |= CRC_SUPPORTED
619
629
request = bytearray (8 )
620
630
logger .info ("Initiating block download for 0x%X:%d" , index , subindex )
621
631
if size is not None :
0 commit comments