Skip to content

Commit d043743

Browse files
committed
Prevent warnings if SDO setup fails
1 parent 7ddb19b commit d043743

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
@@ -669,6 +669,8 @@ def __init__(self, sdo_client, index, subindex=0, size=None, request_crc_support
669669
self._blksize, = struct.unpack_from("B", response, 4)
670670
logger.debug("Server requested a block size of %d", self._blksize)
671671
self.crc_supported = bool(res_command & CRC_SUPPORTED)
672+
# Run this last, used later to determine if initialization was successful
673+
self._initialized = True
672674

673675
def write(self, b):
674676
"""
@@ -784,6 +786,9 @@ def close(self):
784786
if self.closed:
785787
return
786788
super(BlockDownloadStream, self).close()
789+
if not hasattr(self, "_initialized"):
790+
# Don't do finalization if initialization was not successful
791+
return
787792
if not self._done:
788793
logger.error("Block transfer was not finished")
789794
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
@@ -120,6 +120,10 @@ def request_aborted(self, data):
120120

121121
def block_download(self, data):
122122
# We currently don't support BLOCK DOWNLOAD
123+
# Unpack the index and subindex in order to send appropriate abort
124+
command, index, subindex = SDO_STRUCT.unpack_from(data)
125+
self._index = index
126+
self._subindex = subindex
123127
logger.error("Block download is not supported")
124128
self.abort(0x05040001)
125129

0 commit comments

Comments
 (0)