From 2101f770af59e5752e27e8376b0a3ecfaaefe892 Mon Sep 17 00:00:00 2001 From: Beemo123 <41196244+Beemo123@users.noreply.github.com> Date: Mon, 21 Jul 2025 10:22:47 +0100 Subject: [PATCH 1/2] Ability to specify block size in block upload Removed hard coded blocksize value in the "BlockUploadStream" class. Introduced a default value, but added it as a parameter that can be passed in so that block size can be specified when performing an Upload. --- canopen/sdo/client.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/canopen/sdo/client.py b/canopen/sdo/client.py index 3f88f645..387deefd 100644 --- a/canopen/sdo/client.py +++ b/canopen/sdo/client.py @@ -1,5 +1,6 @@ import io -import logging +import + logging import queue import struct import time @@ -169,7 +170,7 @@ def download( fp.write(data) def open(self, index, subindex=0, mode="rb", encoding="ascii", - buffering=1024, size=None, block_transfer=False, force_segment=False, request_crc_support=True): + buffering=1024, size=None, block_transfer=False, force_segment=False, request_crc_support=True, blksize=127): """Open the data stream as a file like object. :param int index: @@ -201,6 +202,8 @@ def open(self, index, subindex=0, mode="rb", encoding="ascii", Force use of segmented download regardless of data size. :param bool request_crc_support: If crc calculation should be requested when using block transfer + :param int blksize: + Size of block in number of segments. Default is 127. :returns: A file like object. @@ -208,7 +211,7 @@ def open(self, index, subindex=0, mode="rb", encoding="ascii", buffer_size = buffering if buffering > 1 else io.DEFAULT_BUFFER_SIZE if "r" in mode: if block_transfer: - raw_stream = BlockUploadStream(self, index, subindex, request_crc_support=request_crc_support) + raw_stream = BlockUploadStream(self, index, subindex, request_crc_support=request_crc_support, blksize=blksize) else: raw_stream = ReadableStream(self, index, subindex) if buffering: @@ -463,11 +466,9 @@ class BlockUploadStream(io.RawIOBase): #: Total size of data or ``None`` if not specified size = None - blksize = 127 - crc_supported = False - def __init__(self, sdo_client, index, subindex=0, request_crc_support=True): + def __init__(self, sdo_client, index, subindex=0, request_crc_support=True, blksize=127): """ :param canopen.sdo.SdoClient sdo_client: The SDO client to use for reading. @@ -477,6 +478,8 @@ def __init__(self, sdo_client, index, subindex=0, request_crc_support=True): Object dictionary sub-index to read from. :param bool request_crc_support: If crc calculation should be requested when using block transfer + :param int blksize: + Size of block in number of segments. Default is 127. """ self._done = False self.sdo_client = sdo_client @@ -484,7 +487,8 @@ def __init__(self, sdo_client, index, subindex=0, request_crc_support=True): self._crc = sdo_client.crc_cls() self._server_crc = None self._ackseq = 0 - self._error = False + self._error = False + self.blksize = blksize logger.debug("Reading 0x%04X:%02X from node %d", index, subindex, sdo_client.rx_cobid - 0x600) From 6db81c78a57894919e0b88ff01ed4d0f4c97663d Mon Sep 17 00:00:00 2001 From: Beemo123 <41196244+Beemo123@users.noreply.github.com> Date: Mon, 21 Jul 2025 10:30:50 +0100 Subject: [PATCH 2/2] Newline Typo fix Accidentally hit enter between "import" and "logging" on line 2.. oops! --- canopen/sdo/client.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/canopen/sdo/client.py b/canopen/sdo/client.py index 387deefd..861bd35a 100644 --- a/canopen/sdo/client.py +++ b/canopen/sdo/client.py @@ -1,6 +1,5 @@ import io -import - logging +import logging import queue import struct import time