Skip to content

Ability to specify block size in block upload #603

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions canopen/sdo/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,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:
Expand Down Expand Up @@ -201,14 +201,16 @@ 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.
"""
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:
Expand Down Expand Up @@ -463,11 +465,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.
Expand All @@ -477,14 +477,17 @@ 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
self.pos = 0
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)
Expand Down
Loading