Open Jef-GB opened 1 year ago
I have found a workaround but I feel like it is not the way to go. By changing the BLOCK_SIZE
to be equal to the FILESIZE
the transfer does complete. This does somehow defeat the purpose of the while loop in the example and does load as far as I know, everything to be transferred into memory.
FIRMWARE_PATH = './notebooks/firmware.bin'
FILESIZE = os.path.getsize(FIRMWARE_PATH)
BLOCK_SIZE = FILESIZE
print(FILESIZE) # Size = 20473 bytes
with open(FIRMWARE_PATH, 'rb') as infile, \
interface._node.sdo.open(index=0x2000, subindex=0x2, mode='wb', buffering=BLOCK_SIZE,
size=FILESIZE, block_transfer=True) as outfile:
data = infile.read(BLOCK_SIZE)
if data:
outfile.write(data)
It does work with my expected file size but is not optimal if it all gets loaded into memory.
The problem is that the library makes use of the buffering functionality in io.BufferedWriter. If you want full control I think it is better that you try to set buffering=0 and BLOCK_SIZE = 7. Otherwise set the buffering argument to something dividable by 7.
The Goal
I am trying to write a file from my Windows device to an embedded controller via CANopen. To transfer the file I am using the CiA301 defined Block transfers as implemented in this stack. I have created a script to write to the bus, making use of the block download example from the documentation.
The Problem
Running this code correctly starts a block transfer resulting in correct data on the bus (This has been validated using PCAN-View). After transferring 1 ore sometimes a few block of data, an error gets thrown on the python side resulting in ending the transfer.
A BlockingIOError gets thrown resulting in the transfer to be aborted. I sadly enough do not have any other CANopen devices supporting block transfers to fully rule out the embedded side, but the responses from the device follow the CANopen specification. Transferring of small files (2 lines of text) does seem to work, bigger files result in this error (An EDS has been used for this test).
Any ideas what could be the issue, what I am doing wrong or what could be a solution?