Skip to content

Commit 1f28869

Browse files
author
Janis Ita
committed
added argument for block transfer to enable/disable CRC Support
1 parent 287c1b5 commit 1f28869

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

canopen/sdo/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def set_data(self, data):
112112
self.sdo_node.download(self.od.index, self.od.subindex, data, force_segment)
113113

114114
def open(self, mode="rb", encoding="ascii", buffering=1024, size=None,
115-
block_transfer=False):
115+
block_transfer=False, request_crc_support=True):
116116
"""Open the data stream as a file like object.
117117
118118
:param str mode:
@@ -141,4 +141,4 @@ def open(self, mode="rb", encoding="ascii", buffering=1024, size=None,
141141
A file like object.
142142
"""
143143
return self.sdo_node.open(self.od.index, self.od.subindex, mode,
144-
encoding, buffering, size, block_transfer)
144+
encoding, buffering, size, block_transfer, request_crc_support=request_crc_support)

canopen/sdo/client.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def download(self, index, subindex, data, force_segment=False):
155155
fp.close()
156156

157157
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):
159159
"""Open the data stream as a file like object.
160160
161161
:param int index:
@@ -192,7 +192,7 @@ def open(self, index, subindex=0, mode="rb", encoding="ascii",
192192
buffer_size = buffering if buffering > 1 else io.DEFAULT_BUFFER_SIZE
193193
if "r" in mode:
194194
if block_transfer:
195-
raw_stream = BlockUploadStream(self, index, subindex)
195+
raw_stream = BlockUploadStream(self, index, subindex, request_crc_support=request_crc_support)
196196
else:
197197
raw_stream = ReadableStream(self, index, subindex)
198198
if buffering:
@@ -201,7 +201,7 @@ def open(self, index, subindex=0, mode="rb", encoding="ascii",
201201
return raw_stream
202202
if "w" in mode:
203203
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)
205205
else:
206206
raw_stream = WritableStream(self, index, subindex, size, force_segment)
207207
if buffering:
@@ -446,7 +446,7 @@ class BlockUploadStream(io.RawIOBase):
446446

447447
crc_supported = False
448448

449-
def __init__(self, sdo_client, index, subindex=0):
449+
def __init__(self, sdo_client, index, subindex=0, request_crc_support=True):
450450
"""
451451
:param canopen.sdo.SdoClient sdo_client:
452452
The SDO client to use for reading.
@@ -466,7 +466,9 @@ def __init__(self, sdo_client, index, subindex=0):
466466
sdo_client.rx_cobid - 0x600)
467467
# Initiate Block Upload
468468
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
470472
struct.pack_into("<BHBBB", request, 0,
471473
command, index, subindex, self.blksize, 0)
472474
response = sdo_client.request_response(request)
@@ -596,7 +598,7 @@ def readable(self):
596598
class BlockDownloadStream(io.RawIOBase):
597599
"""File like object for block download."""
598600

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):
600602
"""
601603
:param canopen.sdo.SdoClient sdo_client:
602604
The SDO client to use for communication.
@@ -614,7 +616,9 @@ def __init__(self, sdo_client, index, subindex=0, size=None):
614616
self._seqno = 0
615617
self._crc = sdo_client.crc_cls()
616618
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
618622
request = bytearray(8)
619623
logger.info("Initiating block download for 0x%X:%d", index, subindex)
620624
if size is not None:

0 commit comments

Comments
 (0)