Skip to content

Commit 8d9aa6c

Browse files
sveinseacolomb
andauthored
Prevent warnings if SDO setup fails (#590)
Co-authored-by: André Colomb <[email protected]>
1 parent 80349e1 commit 8d9aa6c

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

canopen/sdo/client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,8 @@ def __init__(self, sdo_client, index, subindex=0, size=None, request_crc_support
667667
self._blksize, = struct.unpack_from("B", response, 4)
668668
logger.debug("Server requested a block size of %d", self._blksize)
669669
self.crc_supported = bool(res_command & CRC_SUPPORTED)
670+
# Run this last, used later to determine if initialization was successful
671+
self._initialized = True
670672

671673
def write(self, b):
672674
"""
@@ -782,6 +784,9 @@ def close(self):
782784
if self.closed:
783785
return
784786
super(BlockDownloadStream, self).close()
787+
if not getattr(self, "_initialized", False):
788+
# Don't do finalization if initialization was not successful
789+
return
785790
if not self._done:
786791
logger.error("Block transfer was not finished")
787792
command = REQUEST_BLOCK_DOWNLOAD | END_BLOCK_TRANSFER

canopen/sdo/server.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ def request_aborted(self, data):
124124

125125
def block_download(self, data):
126126
# We currently don't support BLOCK DOWNLOAD
127+
# Unpack the index and subindex in order to send appropriate abort
128+
command, index, subindex = SDO_STRUCT.unpack_from(data)
129+
self._index = index
130+
self._subindex = subindex
127131
logger.error("Block download is not supported")
128132
self.abort(0x05040001)
129133

0 commit comments

Comments
 (0)