Skip to content

Commit 8beeba4

Browse files
committed
Avoid duplicate SDO abort messages on timeout.
For each call to SdoClient.read_response(), the timeout abort message can either be sent immediately before raising the exception, or it is sent later, after the exception has been handled e.g. by a retry. Add a boolean parameter to the function, which is usually False to skip the immediate transmission of an SDO abort. Only two cases actually need it, passing the option as True.
1 parent 080d873 commit 8beeba4

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

canopen/sdo/client.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,13 @@ def send_request(self, request):
6464
else:
6565
break
6666

67-
def read_response(self):
67+
def read_response(self, timeout_abort: bool = False):
6868
try:
6969
response = self.responses.get(
7070
block=True, timeout=self.RESPONSE_TIMEOUT)
7171
except queue.Empty:
72-
self.abort(0x0504_0000)
72+
if timeout_abort:
73+
self.abort(0x0504_0000)
7374
raise SdoCommunicationError("No SDO response received")
7475
res_command, = struct.unpack_from("B", response)
7576
if res_command == RESPONSE_ABORTED:
@@ -86,7 +87,7 @@ def request_response(self, sdo_request):
8687
self.send_request(sdo_request)
8788
# Wait for node to respond
8889
try:
89-
return self.read_response()
90+
return self.read_response(timeout_abort=False)
9091
except SdoCommunicationError as e:
9192
retries_left -= 1
9293
if not retries_left:
@@ -526,7 +527,7 @@ def read(self, size=-1):
526527
return self.readall()
527528

528529
try:
529-
response = self.sdo_client.read_response()
530+
response = self.sdo_client.read_response(timeout_abort=False)
530531
except SdoCommunicationError:
531532
response = self._retransmit()
532533
res_command, = struct.unpack_from("B", response)
@@ -562,7 +563,7 @@ def _retransmit(self):
562563
end_time = time.time() + self.sdo_client.RESPONSE_TIMEOUT
563564
self._ack_block()
564565
while time.time() < end_time:
565-
response = self.sdo_client.read_response()
566+
response = self.sdo_client.read_response(timeout_abort=False)
566567
res_command, = struct.unpack_from("B", response)
567568
seqno = res_command & 0x7F
568569
if seqno == self._ackseq + 1:
@@ -582,7 +583,7 @@ def _ack_block(self):
582583
self._ackseq = 0
583584

584585
def _end_upload(self):
585-
response = self.sdo_client.read_response()
586+
response = self.sdo_client.read_response(timeout_abort=True)
586587
res_command, self._server_crc = struct.unpack_from("<BH", response)
587588
if res_command & 0xE0 != RESPONSE_BLOCK_UPLOAD:
588589
self._error = True
@@ -740,7 +741,7 @@ def tell(self):
740741

741742
def _block_ack(self):
742743
logger.debug("Waiting for acknowledgement of last block...")
743-
response = self.sdo_client.read_response()
744+
response = self.sdo_client.read_response(timeout_abort=True)
744745
res_command, ackseq, blksize = struct.unpack_from("BBB", response)
745746
if res_command & 0xE0 != RESPONSE_BLOCK_DOWNLOAD:
746747
self.sdo_client.abort(0x0504_0001)

0 commit comments

Comments
 (0)