@@ -155,7 +155,7 @@ def download(self, index, subindex, data, force_segment=False):
155
155
fp .close ()
156
156
157
157
def open (self , index , subindex = 0 , mode = "rb" , encoding = "ascii" ,
158
- buffering = 1024 , size = None , block_transfer = False , force_segment = False ):
158
+ buffering = 1024 , size = None , block_transfer = False , force_segment = False , request_crc_support = True ):
159
159
"""Open the data stream as a file like object.
160
160
161
161
:param int index:
@@ -192,7 +192,7 @@ def open(self, index, subindex=0, mode="rb", encoding="ascii",
192
192
buffer_size = buffering if buffering > 1 else io .DEFAULT_BUFFER_SIZE
193
193
if "r" in mode :
194
194
if block_transfer :
195
- raw_stream = BlockUploadStream (self , index , subindex )
195
+ raw_stream = BlockUploadStream (self , index , subindex , request_crc_support = request_crc_support )
196
196
else :
197
197
raw_stream = ReadableStream (self , index , subindex )
198
198
if buffering :
@@ -201,7 +201,7 @@ def open(self, index, subindex=0, mode="rb", encoding="ascii",
201
201
return raw_stream
202
202
if "w" in mode :
203
203
if block_transfer :
204
- raw_stream = BlockDownloadStream (self , index , subindex , size )
204
+ raw_stream = BlockDownloadStream (self , index , subindex , size , request_crc_support = request_crc_support )
205
205
else :
206
206
raw_stream = WritableStream (self , index , subindex , size , force_segment )
207
207
if buffering :
@@ -446,7 +446,7 @@ class BlockUploadStream(io.RawIOBase):
446
446
447
447
crc_supported = False
448
448
449
- def __init__ (self , sdo_client , index , subindex = 0 ):
449
+ def __init__ (self , sdo_client , index , subindex = 0 , request_crc_support = True ):
450
450
"""
451
451
:param canopen.sdo.SdoClient sdo_client:
452
452
The SDO client to use for reading.
@@ -466,7 +466,9 @@ def __init__(self, sdo_client, index, subindex=0):
466
466
sdo_client .rx_cobid - 0x600 )
467
467
# Initiate Block Upload
468
468
request = bytearray (8 )
469
- command = REQUEST_BLOCK_UPLOAD | INITIATE_BLOCK_TRANSFER | CRC_SUPPORTED
469
+ command = REQUEST_BLOCK_UPLOAD | INITIATE_BLOCK_TRANSFER
470
+ if request_crc_support :
471
+ command |= CRC_SUPPORTED
470
472
struct .pack_into ("<BHBBB" , request , 0 ,
471
473
command , index , subindex , self .blksize , 0 )
472
474
response = sdo_client .request_response (request )
@@ -596,7 +598,7 @@ def readable(self):
596
598
class BlockDownloadStream (io .RawIOBase ):
597
599
"""File like object for block download."""
598
600
599
- def __init__ (self , sdo_client , index , subindex = 0 , size = None ):
601
+ def __init__ (self , sdo_client , index , subindex = 0 , size = None , request_crc_support = True ):
600
602
"""
601
603
:param canopen.sdo.SdoClient sdo_client:
602
604
The SDO client to use for communication.
@@ -614,7 +616,9 @@ def __init__(self, sdo_client, index, subindex=0, size=None):
614
616
self ._seqno = 0
615
617
self ._crc = sdo_client .crc_cls ()
616
618
self ._last_bytes_sent = 0
617
- command = REQUEST_BLOCK_DOWNLOAD | INITIATE_BLOCK_TRANSFER | CRC_SUPPORTED
619
+ command = REQUEST_BLOCK_DOWNLOAD | INITIATE_BLOCK_TRANSFER
620
+ if request_crc_support :
621
+ command |= CRC_SUPPORTED
618
622
request = bytearray (8 )
619
623
logger .info ("Initiating block download for 0x%X:%d" , index , subindex )
620
624
if size is not None :
0 commit comments