From 0a1b0f7e64f4d7e784d2595d9d657238afe58eee Mon Sep 17 00:00:00 2001 From: Christian Sandberg Date: Thu, 3 Nov 2016 15:58:49 +0100 Subject: [PATCH] Update number of unused bytes in last SDO segment. Fixes #4. --- canopen/sdo.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/canopen/sdo.py b/canopen/sdo.py index 7366f507..f4adde1d 100644 --- a/canopen/sdo.py +++ b/canopen/sdo.py @@ -164,8 +164,12 @@ def download(self, index, subindex, data): for pos in range(0, length, 7): request[1:8] = data[pos:pos + 7] if pos + 7 >= length: + # No more data after this message request[0] |= 1 + # Specify number of bytes in that do not contain segment data + request[0] |= (8 - len(request)) << 1 response = self.send_request(request.ljust(8, b'\x00')) + # Toggle bit for next request request[0] ^= 0x10 if response[0] & 0xE0 != RESPONSE_SEGMENT_DOWNLOAD: raise SdoCommunicationError("Unexpected response")