diff --git a/canopen/sdo/client.py b/canopen/sdo/client.py index 6d92588e..2a82ed12 100644 --- a/canopen/sdo/client.py +++ b/canopen/sdo/client.py @@ -669,6 +669,8 @@ def __init__(self, sdo_client, index, subindex=0, size=None, request_crc_support self._blksize, = struct.unpack_from("B", response, 4) logger.debug("Server requested a block size of %d", self._blksize) self.crc_supported = bool(res_command & CRC_SUPPORTED) + # Run this last, used later to determine if initialization was successful + self._initialized = True def write(self, b): """ @@ -784,6 +786,9 @@ def close(self): if self.closed: return super(BlockDownloadStream, self).close() + if not getattr(self, "_initialized", False): + # Don't do finalization if initialization was not successful + return if not self._done: logger.error("Block transfer was not finished") command = REQUEST_BLOCK_DOWNLOAD | END_BLOCK_TRANSFER diff --git a/canopen/sdo/server.py b/canopen/sdo/server.py index c6a4c27c..2947afd0 100644 --- a/canopen/sdo/server.py +++ b/canopen/sdo/server.py @@ -120,6 +120,10 @@ def request_aborted(self, data): def block_download(self, data): # We currently don't support BLOCK DOWNLOAD + # Unpack the index and subindex in order to send appropriate abort + command, index, subindex = SDO_STRUCT.unpack_from(data) + self._index = index + self._subindex = subindex logger.error("Block download is not supported") self.abort(0x05040001)