Skip to content

Commit 2101f77

Browse files
authored
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.
1 parent 0130eb8 commit 2101f77

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

canopen/sdo/client.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import io
2-
import logging
2+
import
3+
logging
34
import queue
45
import struct
56
import time
@@ -169,7 +170,7 @@ def download(
169170
fp.write(data)
170171

171172
def open(self, index, subindex=0, mode="rb", encoding="ascii",
172-
buffering=1024, size=None, block_transfer=False, force_segment=False, request_crc_support=True):
173+
buffering=1024, size=None, block_transfer=False, force_segment=False, request_crc_support=True, blksize=127):
173174
"""Open the data stream as a file like object.
174175
175176
:param int index:
@@ -201,14 +202,16 @@ def open(self, index, subindex=0, mode="rb", encoding="ascii",
201202
Force use of segmented download regardless of data size.
202203
:param bool request_crc_support:
203204
If crc calculation should be requested when using block transfer
205+
:param int blksize:
206+
Size of block in number of segments. Default is 127.
204207
205208
:returns:
206209
A file like object.
207210
"""
208211
buffer_size = buffering if buffering > 1 else io.DEFAULT_BUFFER_SIZE
209212
if "r" in mode:
210213
if block_transfer:
211-
raw_stream = BlockUploadStream(self, index, subindex, request_crc_support=request_crc_support)
214+
raw_stream = BlockUploadStream(self, index, subindex, request_crc_support=request_crc_support, blksize=blksize)
212215
else:
213216
raw_stream = ReadableStream(self, index, subindex)
214217
if buffering:
@@ -463,11 +466,9 @@ class BlockUploadStream(io.RawIOBase):
463466
#: Total size of data or ``None`` if not specified
464467
size = None
465468

466-
blksize = 127
467-
468469
crc_supported = False
469470

470-
def __init__(self, sdo_client, index, subindex=0, request_crc_support=True):
471+
def __init__(self, sdo_client, index, subindex=0, request_crc_support=True, blksize=127):
471472
"""
472473
:param canopen.sdo.SdoClient sdo_client:
473474
The SDO client to use for reading.
@@ -477,14 +478,17 @@ def __init__(self, sdo_client, index, subindex=0, request_crc_support=True):
477478
Object dictionary sub-index to read from.
478479
:param bool request_crc_support:
479480
If crc calculation should be requested when using block transfer
481+
:param int blksize:
482+
Size of block in number of segments. Default is 127.
480483
"""
481484
self._done = False
482485
self.sdo_client = sdo_client
483486
self.pos = 0
484487
self._crc = sdo_client.crc_cls()
485488
self._server_crc = None
486489
self._ackseq = 0
487-
self._error = False
490+
self._error = False
491+
self.blksize = blksize
488492

489493
logger.debug("Reading 0x%04X:%02X from node %d", index, subindex,
490494
sdo_client.rx_cobid - 0x600)

0 commit comments

Comments
 (0)