Skip to content

Commit 0e6e510

Browse files
authored
SDO client fixes (#408)
1 parent e3d2155 commit 0e6e510

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

canopen/sdo/client.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ def __init__(self, sdo_client, index, subindex=0, request_crc_support=True):
470470
self._crc = sdo_client.crc_cls()
471471
self._server_crc = None
472472
self._ackseq = 0
473+
self._error = False
473474

474475
logger.debug("Reading 0x%X:%d from node %d", index, subindex,
475476
sdo_client.rx_cobid - 0x600)
@@ -483,9 +484,12 @@ def __init__(self, sdo_client, index, subindex=0, request_crc_support=True):
483484
response = sdo_client.request_response(request)
484485
res_command, res_index, res_subindex = SDO_STRUCT.unpack_from(response)
485486
if res_command & 0xE0 != RESPONSE_BLOCK_UPLOAD:
487+
self._error = True
488+
self.sdo_client.abort(0x05040001)
486489
raise SdoCommunicationError("Unexpected response 0x%02X" % res_command)
487490
# Check that the message is for us
488491
if res_index != index or res_subindex != subindex:
492+
self._error = True
489493
raise SdoCommunicationError((
490494
"Node returned a value for 0x{:X}:{:d} instead, "
491495
"maybe there is another SDO client communicating "
@@ -537,6 +541,7 @@ def read(self, size=-1):
537541
self._crc.process(data)
538542
if self._done:
539543
if self._server_crc != self._crc.final():
544+
self._error = True
540545
self.sdo_client.abort(0x05040004)
541546
raise SdoCommunicationError("CRC is not OK")
542547
logger.info("CRC is OK")
@@ -556,6 +561,8 @@ def _retransmit(self):
556561
# We should be back in sync
557562
self._ackseq = seqno
558563
return response
564+
self._error = True
565+
self.sdo_client.abort(0x05040000)
559566
raise SdoCommunicationError("Some data were lost and could not be retransmitted")
560567

561568
def _ack_block(self):
@@ -571,9 +578,11 @@ def _end_upload(self):
571578
response = self.sdo_client.read_response()
572579
res_command, self._server_crc = struct.unpack_from("<BH", response)
573580
if res_command & 0xE0 != RESPONSE_BLOCK_UPLOAD:
581+
self._error = True
574582
self.sdo_client.abort(0x05040001)
575583
raise SdoCommunicationError("Unexpected response 0x%02X" % res_command)
576584
if res_command & 0x3 != END_BLOCK_TRANSFER:
585+
self._error = True
577586
self.sdo_client.abort(0x05040001)
578587
raise SdoCommunicationError("Server did not end transfer as expected")
579588
# Return number of bytes not used in last message
@@ -583,7 +592,7 @@ def close(self):
583592
if self.closed:
584593
return
585594
super(BlockUploadStream, self).close()
586-
if self._done:
595+
if self._done and not self._error:
587596
request = bytearray(8)
588597
request[0] = REQUEST_BLOCK_UPLOAD | END_BLOCK_TRANSFER
589598
self.sdo_client.send_request(request)

0 commit comments

Comments
 (0)