Skip to content

Conversation

@christiansandberg
Copy link
Member

Addresses part of issue #14.

Intended usage:

data = b'A really really long string...'
fp = node.sdo['Some Variable'].open('wb', size=len(data), block_transfer=True)
fp.write(data)
fp.close()

@christiansandberg
Copy link
Member Author

@obbardc, could you test block download according to the code example above?

Could you also enable logging (see #27) and also log the CAN traffic.

Return None if data could not be sent
Add debug messages
Add some block transfer abort codes
@christiansandberg christiansandberg changed the title SDO block download SDO block transfer May 4, 2017
@christiansandberg
Copy link
Member Author

@obbardc, are you also able to test block upload? It's done in a similar way:

fp = node.sdo['Some Variable'].open('rb', block_transfer=True)
data = fp.read()
fp.close()

@obbardc
Copy link

obbardc commented May 5, 2017

Hi @christiansandberg

I have managed to try the block out on my hardware today. It starts downloading, then times out after a few writes... It could be down to my hardware, though. It's a proprietary piece of hardware so I have no control over the code.

with open("test.img", "rb") as inputHandle:
    data = inputHandle.read()

print "Writing Application"
fp = node.sdo[0x1F50][1].open('wb', size=len(data), block_transfer=True)
fp.write(data)
fp.close()
print "Writing Application End"
INFO:canopen.sdo:Initiating block download for 0x1F50:1
DEBUG:canopen.sdo:Expected size of data is 790984 bytes
DEBUG:can.socketcan.ctypes:Packing a can frame
DEBUG:can.socketcan.ctypes:Data: ÆPÈ

DEBUG:can.socketcan.ctypes:Type: <type 'bytearray'>
DEBUG:can.socketcan.ctypes:sizeof frame: 16
DEBUG:can.socketcan.ctypes:Receiving a message
DEBUG:can.socketcan.ctypes:Trying to read a msg
DEBUG:canopen.sdo:Server requested a block size of 8
DEBUG:can.socketcan.ctypes:Packing a can frame
DEBUG:can.socketcan.ctypes:Data: ÷¶ÀP9
DEBUG:can.socketcan.ctypes:Type: <type 'bytearray'>
DEBUG:can.socketcan.ctypes:sizeof frame: 16
DEBUG:can.socketcan.ctypes:Packing a can frame
DEBUG:can.socketcan.ctypes:Data: ¯
H
DEBUG:can.socketcan.ctypes:Type: <type 'bytearray'>
DEBUG:can.socketcan.ctypes:sizeof frame: 16
DEBUG:can.socketcan.ctypes:Packing a can frame
DEBUG:can.socketcan.ctypes:Data:10227
DEBUG:can.socketcan.ctypes:Type: <type 'bytearray'>
DEBUG:can.socketcan.ctypes:sizeof frame: 16
DEBUG:can.socketcan.ctypes:Packing a can frame
DEBUG:can.socketcan.ctypes:Data: 844
DEBUG:can.socketcan.ctypes:Type: <type 'bytearray'>
DEBUG:can.socketcan.ctypes:sizeof frame: 16
DEBUG:can.socketcan.ctypes:Packing a can frame
DEBUG:can.socketcan.ctypes:Data:
DEBUG:can.socketcan.ctypes:Type: <type 'bytearray'>
DEBUG:can.socketcan.ctypes:sizeof frame: 16
PuTTYDEBUG:can.socketcan.ctypes:Packing a can frame
DEBUG:can.socketcan.ctypes:Data:
DEBUG:can.socketcan.ctypes:Type: <type 'bytearray'>
DEBUG:can.socketcan.ctypes:sizeof frame: 16
DEBUG:can.socketcan.ctypes:Packing a can frame
DEBUG:can.socketcan.ctypes:Data: 0
DEBUG:can.socketcan.ctypes:Type: <type 'bytearray'>
DEBUG:can.socketcan.ctypes:sizeof frame: 16
DEBUG:can.socketcan.ctypes:Packing a can frame
DEBUG:can.socketcan.ctypes:Data:.1.0
DEBUG:can.socketcan.ctypes:Type: <type 'bytearray'>
DEBUG:can.socketcan.ctypes:sizeof frame: 16
DEBUG:canopen.sdo:Waiting for acknowledgement of last block...
DEBUG:can.socketcan.ctypes:Receiving a message
DEBUG:can.socketcan.ctypes:Trying to read a msg
DEBUG:canopen.sdo:All 8 sequences were received successfully
DEBUG:canopen.sdo:Server requested a block size of 8
DEBUG:can.socketcan.ctypes:Packing a can frame
DEBUG:can.socketcan.ctypes:Data:
DEBUG:can.socketcan.ctypes:Type: <type 'bytearray'>
DEBUG:can.socketcan.ctypes:sizeof frame: 16
DEBUG:can.socketcan.ctypes:Packing a can frame
DEBUG:can.socketcan.ctypes:Data:
DEBUG:can.socketcan.ctypes:Type: <type 'bytearray'>
DEBUG:can.socketcan.ctypes:sizeof frame: 16
DEBUG:can.socketcan.ctypes:Packing a can frame
DEBUG:can.socketcan.ctypes:Data:
DEBUG:can.socketcan.ctypes:Type: <type 'bytearray'>
DEBUG:can.socketcan.ctypes:sizeof frame: 16
DEBUG:can.socketcan.ctypes:Packing a can frame
DEBUG:can.socketcan.ctypes:Data: ÿÿÿÿ
DEBUG:can.socketcan.ctypes:Type: <type 'bytearray'>
DEBUG:can.socketcan.ctypes:sizeof frame: 16
DEBUG:can.socketcan.ctypes:Packing a can frame
DEBUG:can.socketcan.ctypes:Data: ÿÿÿÿÿÿÿ
DEBUG:can.socketcan.ctypes:Type: <type 'bytearray'>
DEBUG:can.socketcan.ctypes:sizeof frame: 16
PuTTYDEBUG:can.socketcan.ctypes:Packing a can frame
DEBUG:can.socketcan.ctypes:Data: ÿÿÿÿÿÿÿ
DEBUG:can.socketcan.ctypes:Type: <type 'bytearray'>
DEBUG:can.socketcan.ctypes:sizeof frame: 16
DEBUG:can.socketcan.ctypes:Packing a can frame
DEBUG:can.socketcan.ctypes:Data: ÿÿÿÿÿÿÿ
DEBUG:can.socketcan.ctypes:Type: <type 'bytearray'>
DEBUG:can.socketcan.ctypes:sizeof frame: 16
DEBUG:can.socketcan.ctypes:Packing a can frame
DEBUG:can.socketcan.ctypes:Data:ÿÿÿÿÿÿÿ
DEBUG:can.socketcan.ctypes:Type: <type 'bytearray'>
DEBUG:can.socketcan.ctypes:sizeof frame: 16
DEBUG:canopen.sdo:Waiting for acknowledgement of last block...
DEBUG:can.socketcan.ctypes:Receiving a message
DEBUG:can.socketcan.ctypes:Trying to read a msg
DEBUG:canopen.sdo:All 8 sequences were received successfully
DEBUG:canopen.sdo:Server requested a block size of 8
DEBUG:can.socketcan.ctypes:Packing a can frame
DEBUG:can.socketcan.ctypes:Data: ÿÿÿÿÿÿÿ
DEBUG:can.socketcan.ctypes:Type: <type 'bytearray'>
DEBUG:can.socketcan.ctypes:sizeof frame: 16
DEBUG:can.socketcan.ctypes:Packing a can frame
DEBUG:can.socketcan.ctypes:Data: ÿÿÿÿÿÿÿ
DEBUG:can.socketcan.ctypes:Type: <type 'bytearray'>
DEBUG:can.socketcan.ctypes:sizeof frame: 16
DEBUG:can.socketcan.ctypes:Packing a can frame
DEBUG:can.socketcan.ctypes:Data: ÿÿZ`
DEBUG:can.socketcan.ctypes:Type: <type 'bytearray'>
DEBUG:can.socketcan.ctypes:sizeof frame: 16
DEBUG:can.socketcan.ctypes:Packing a can frame
DEBUG:can.socketcan.ctypes:Data:XHP
DEBUG:can.socketcan.ctypes:Type: <type 'bytearray'>
DEBUG:can.socketcan.ctypes:sizeof frame: 16
DEBUG:can.socketcan.ctypes:Packing a can frame
DEBUG:can.socketcan.ctypes:Data: |h¦N
DEBUG:can.socketcan.ctypes:Type: <type 'bytearray'>
PuTTYDEBUG:can.socketcan.ctypes:sizeof frame: 16
DEBUG:can.socketcan.ctypes:Receiving a message
DEBUG:can.socketcan.ctypes:Packing a can frame
DEBUG:can.socketcan.ctypes:Trying to read a msg
DEBUG:can.socketcan.ctypes:Data:  Ãù
DEBUG:can.socketcan.ctypes:Type: <type 'bytearray'>
DEBUG:can.socketcan.ctypes:sizeof frame: 16
DEBUG:can.socketcan.ctypes:Packing a can frame
DEBUG:can.socketcan.ctypes:Data: dÃ
DEBUG:can.socketcan.ctypes:Type: <type 'bytearray'>
DEBUG:can.socketcan.ctypes:sizeof frame: 16
DEBUG:can.socketcan.ctypes:Packing a can frame
DEBUG:can.socketcan.ctypes:Data:ùh
DEBUG:can.socketcan.ctypes:Type: <type 'bytearray'>
DEBUG:can.socketcan.ctypes:sizeof frame: 16
DEBUG:canopen.sdo:Waiting for acknowledgement of last block...
Traceback (most recent call last):
  File "test/canopen_test.py", line 83, in <module>
    fp.write(data)
  File "/home/pi/canopen/canopen/sdo.py", line 755, in write
    self.send(data)
  File "/home/pi/canopen/canopen/sdo.py", line 785, in send
    self._block_ack()
  File "/home/pi/canopen/canopen/sdo.py", line 792, in _block_ack
    response = self.sdo_client.read_response()
  File "/home/pi/canopen/canopen/sdo.py", line 107, in read_response
    raise SdoAbortedError(abort_code)
canopen.sdo.SdoAbortedError: Code 0x08000000, General error
DEBUG:can.socketcan.ctypes:Packing a can frame
DEBUG:can.socketcan.ctypes:Data:
DEBUG:can.socketcan.ctypes:Type: <type 'bytearray'>
DEBUG:can.socketcan.ctypes:sizeof frame: 16
DEBUG:canopen.sdo:Waiting for acknowledgement of last block...

@christiansandberg
Copy link
Member Author

Well, it's positive that two blocks were received successfully. Maybe you could compare a CAN trace with one that's working? If you could get more details on the error that would also be great.

Start sending some abort codes from client on errors
Add block transfer to docs
@christiansandberg christiansandberg merged commit db0cef3 into master Aug 12, 2017
@christiansandberg christiansandberg deleted the block-download branch October 9, 2017 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants