The first message is fine, but for example if the last byte (madonnee.bytes.byte7) is equal to 0x3C, all the message after that will always end with 0x3C even if I send a message like that
So for that exemple, the last 4 bytes will be 0x00,0x01,0x02 and 0x3C
The problem only appears when I send 8 bytes.
I don't know how this is possible because if I copy/paste that exact same line in a file where I only send that message it's working fine. The bug only appears when I try to send multiple messages.
I've attached a draft of my code in python if you want to give it a shot and maybe help me to fin the mistake.
PS: sorry for my poor english.
the code:
# simple pyCan Example for can4linuximportpyCanimporttimeimportctypesprint'....... swig-python wrapper loaded'# setting the device numberdevice=0defaultBaudrate='250'# open the can interface /dev/can1# but before, set the baud rate if other than defaulttry:fileBaud=open('/proc/sys/dev/Can/Baud','r+')baudRates=fileBaud.read().split()baudRates[device]=defaultBaudratefileBaud.write(' '.join(baudRates))fileBaud.close()exceptIOError:print'Could not set the new bitrate 'exit()exceptIndexError:print'No proper entry for bitrate of can'+str(device)+' found.'exit()print'....... bit rate changed'print'open can'+str(device)+' none blocking'can_fd=pyCan.open(device)ifcan_fd==-1:print'error opening CAN device /dev/can'+str(device)exit()classbyteStruct(ctypes.Structure):_fields_=[("byte0",ctypes.c_ubyte),("byte1",ctypes.c_ubyte),("byte2",ctypes.c_ubyte),("byte3",ctypes.c_ubyte),("byte4",ctypes.c_ubyte),("byte5",ctypes.c_ubyte),("byte6",ctypes.c_ubyte),("byte7",ctypes.c_ubyte)]classintStruct(ctypes.Structure):_fields_=[("int0",ctypes.c_short),("int1",ctypes.c_short),("int2",ctypes.c_short),("int3",ctypes.c_short)]classfloatStruct(ctypes.Structure):_fields_=[("float0",ctypes.c_float),("float1",ctypes.c_float)]classcanData(ctypes.Union):_fields_=[("bytes",byteStruct),("ints",intStruct),("floats",floatStruct)]madonnee=canData()madonnee.ints.int0=1024madonnee.ints.int1=2000madonnee.bytes.byte4=0b00000100madonnee.bytes.byte5=0b00000001ID=hex(0b00000000010)pyCan.send(can_fd,8,'%s:%s,%s,%s,%s,%s,%s,0x00,0x00'%(ID,hex(madonnee.bytes.byte0),hex(madonnee.bytes.byte1),hex(madonnee.bytes.byte2),hex(madonnee.bytes.byte3),hex(madonnee.bytes.byte4),hex(madonnee.bytes.byte5)))time.sleep(0.001)#print(1)madonnee.floats.float0=0.0015madonnee.floats.float1=0.01ID=hex(0b00000010010)#pyCan.send(can_fd,8,'%s:%s,%s,%s,%s,%s,%s,%s,%s' % (ID,hex(madonnee.bytes.byte0),hex(madonnee.bytes.byte1),hex(madonnee.bytes.byte2),hex(madonnee.bytes.byte3),hex(madonnee.bytes.byte4),hex(madonnee.bytes.byte5),hex(madonnee.bytes.byte6),hex(madonnee.bytes.byte7)))time.sleep(0.001)#time.sleep(1)#print(2)madonnee.floats.float0=0.1madonnee.floats.float1=0.01ID=hex(0b00000100010)pyCan.send(can_fd,8,'%s:%s,%s,%s,%s,%s,%s,%s,%s'%(ID,hex(madonnee.bytes.byte0),hex(madonnee.bytes.byte1),hex(madonnee.bytes.byte2),hex(madonnee.bytes.byte3),hex(madonnee.bytes.byte4),hex(madonnee.bytes.byte5),hex(madonnee.bytes.byte6),hex(madonnee.bytes.byte7)))print'%s:%s,%s,%s,%s,%s,%s,%s,%s'%(ID,hex(madonnee.bytes.byte0),hex(madonnee.bytes.byte1),hex(madonnee.bytes.byte2),hex(madonnee.bytes.byte3),hex(madonnee.bytes.byte4),hex(madonnee.bytes.byte5),hex(madonnee.bytes.byte6),hex(madonnee.bytes.byte7))time.sleep(0.001)#time.sleep(1)#print(3)madonnee.floats.float0=15madonnee.floats.float1=0ID=hex(0b00000110010)pyCan.send(can_fd,8,'%s:%s,%s,%s,%s,%s,%s,%s,%s'%(ID,hex(madonnee.bytes.byte0),hex(madonnee.bytes.byte1),hex(madonnee.bytes.byte2),hex(madonnee.bytes.byte3),hex(madonnee.bytes.byte4),hex(madonnee.bytes.byte5),hex(madonnee.bytes.byte6),hex(madonnee.bytes.byte7)))time.sleep(0.001)#time.sleep(1)#print(4)madonnee.floats.float0=30madonnee.floats.float1=0ID=hex(0b00001000010)time.sleep(0.001)pyCan.send(can_fd,8,'%s:%s,%s,%s,%s,%s,%s,%s,%s'%(ID,hex(madonnee.bytes.byte0),hex(madonnee.bytes.byte1),hex(madonnee.bytes.byte2),hex(madonnee.bytes.byte3),hex(madonnee.bytes.byte4),hex(madonnee.bytes.byte5),hex(madonnee.bytes.byte6),hex(madonnee.bytes.byte7)))#time.sleep(1)#print(5)time.sleep(0.001)madonnee.floats.float0=0.00005madonnee.floats.float1=0.01ID=hex(0b00001010010)time.sleep(0.001)#pyCan.send(can_fd,8,'%d:%d,%d,%d,%d,%d,%d,%d,%d' % (ID,madonnee.bytes.byte0,madonnee.bytes.byte1,madonnee.bytes.byte2,madonnee.bytes.byte3,madonnee.bytes.byte4,madonnee.bytes.byte5,madonnee.bytes.byte6,madonnee.bytes.byte7))#pyCan.send(can_fd,8,"0x52:0x17,0xB7,0x51,0x38,0x0A,0xD7,0x23,0x3C")pyCan.send(can_fd,8,'%s:%s,%s,%s,%s,%s,%s,%s,%s'%(ID,hex(madonnee.bytes.byte0),hex(madonnee.bytes.byte1),hex(madonnee.bytes.byte2),hex(madonnee.bytes.byte3),hex(madonnee.bytes.byte4),hex(madonnee.bytes.byte5),hex(madonnee.bytes.byte6),hex(madonnee.bytes.byte7)))myvalue='%s:%s,%s,%s,%s,%s,%s,%s,0x55'%(ID,hex(madonnee.bytes.byte0),madonnee.bytes.byte1,madonnee.bytes.byte2,madonnee.bytes.byte3,madonnee.bytes.byte4,madonnee.bytes.byte5,madonnee.bytes.byte6)#print ('%s:%d,%s,%s,%s,%s,%s,%s,%s' % (ID,madonnee.bytes.byte0,madonnee.bytes.byte1,madonnee.bytes.byte2,madonnee.bytes.byte3,madonnee.bytes.byte4,madonnee.bytes.byte5,madonnee.bytes.byte6,madonnee.bytes.byte7))#time.sleep(1)#pyCan.send(can_fd,8,"0x52:0x17,0xB7,0x51,0x38,0x0A,0xD7,0x23,0x3C")#while 1:# time.sleep(1)#print(6)madonnee.floats.float0=0ID=hex(0b00001100010)time.sleep(0.001)pyCan.send(can_fd,8,'%s:%s,%s,%s,%s,0x00,0x01,0x02,0x03'%(ID,hex(madonnee.bytes.byte0),hex(madonnee.bytes.byte1),hex(madonnee.bytes.byte2),hex(madonnee.bytes.byte3)))#time.sleep(1)#print(7)madonnee.floats.float0=87.92madonnee.floats.float1=72ID=hex(0b00010000010)#8time.sleep(0.001)pyCan.send(can_fd,8,'%s:%s,%s,%s,%s,%s,%s,0x32,0x42'%(ID,hex(madonnee.bytes.byte0),hex(madonnee.bytes.byte1),hex(madonnee.bytes.byte2),hex(madonnee.bytes.byte3),hex(madonnee.bytes.byte4),hex(madonnee.bytes.byte5)))#time.sleep(1)#print(8)print'%s:%s,%s,%s,%s,%s,%s,%s,%s'%(ID,hex(madonnee.bytes.byte0),hex(madonnee.bytes.byte1),hex(madonnee.bytes.byte2),hex(madonnee.bytes.byte3),hex(madonnee.bytes.byte4),hex(madonnee.bytes.byte5),hex(madonnee.bytes.byte6),hex(madonnee.bytes.byte7))while1:time.sleep(1)madonnee.floats.float0=1madonnee.floats.float1=0#100ID=hex(0b00010010010)#9time.sleep(0.001)pyCan.send(can_fd,8,'%s:%s,%s,%s,%s,%s,%s,%s,%s'%(ID,hex(madonnee.bytes.byte0),hex(madonnee.bytes.byte1),hex(madonnee.bytes.byte2),hex(madonnee.bytes.byte3),hex(madonnee.bytes.byte4),hex(madonnee.bytes.byte5),hex(madonnee.bytes.byte6),hex(madonnee.bytes.byte7)))#time.sleep(1)#print(9)time.sleep(0.001)madonnee.ints.int0=0b10000000001madonnee.ints.int1=0b10000010001ID=hex(0b00010100010)#10pyCan.send(can_fd,8,'%s:%s,%s,%s,%s,%s,%s,%s,%s'%(ID,hex(madonnee.bytes.byte0),hex(madonnee.bytes.byte1),hex(madonnee.bytes.byte2),hex(madonnee.bytes.byte3),hex(madonnee.bytes.byte4),hex(madonnee.bytes.byte5),hex(madonnee.bytes.byte6),hex(madonnee.bytes.byte7)))#time.sleep(1)#print(10)madonnee.floats.float0=1madonnee.floats.float1=1ID=hex(0b00011100010)time.sleep(0.001)pyCan.send(can_fd,8,'%s:%s,%s,%s,%s,%s,%s,%s,%s'%(ID,hex(madonnee.bytes.byte0),hex(madonnee.bytes.byte1),hex(madonnee.bytes.byte2),hex(madonnee.bytes.byte3),hex(madonnee.bytes.byte4),hex(madonnee.bytes.byte5),hex(madonnee.bytes.byte6),hex(madonnee.bytes.byte7)))#time.sleep(1)#print(11)madonnee.floats.float0=50madonnee.floats.float1=0ID=hex(0b00011110010)time.sleep(0.001)pyCan.send(can_fd,8,'%s:%s,%s,%s,%s,%s,%s,%s,%s'%(ID,hex(madonnee.bytes.byte0),hex(madonnee.bytes.byte1),hex(madonnee.bytes.byte2),hex(madonnee.bytes.byte3),hex(madonnee.bytes.byte4),hex(madonnee.bytes.byte5),hex(madonnee.bytes.byte6),hex(madonnee.bytes.byte7)))#time.sleep(1)#print(12)madonnee.floats.float0=800madonnee.floats.float1=2ID=hex(0b00100000010)time.sleep(0.001)pyCan.send(can_fd,8,'%s:%s,%s,%s,%s,%s,%s,%s,%s'%(ID,hex(madonnee.bytes.byte0),hex(madonnee.bytes.byte1),hex(madonnee.bytes.byte2),hex(madonnee.bytes.byte3),hex(madonnee.bytes.byte4),hex(madonnee.bytes.byte5),hex(madonnee.bytes.byte6),hex(madonnee.bytes.byte7)))#time.sleep(1)#print(13)madonnee.floats.float0=500madonnee.floats.float1=4ID=hex(0b00100010010)time.sleep(0.001)pyCan.send(can_fd,8,'%s:%s,%s,%s,%s,%s,%s,%s,%s'%(ID,hex(madonnee.bytes.byte0),hex(madonnee.bytes.byte1),hex(madonnee.bytes.byte2),hex(madonnee.bytes.byte3),hex(madonnee.bytes.byte4),hex(madonnee.bytes.byte5),hex(madonnee.bytes.byte6),hex(madonnee.bytes.byte7)))#time.sleep(1)#print(14)madonnee.floats.float0=0.1madonnee.floats.float1=0.003ID=hex(0b00011010010)time.sleep(0.001)pyCan.send(can_fd,8,'%s:%s,%s,%s,%s,%s,%s,%s,%s'%(ID,hex(madonnee.bytes.byte0),hex(madonnee.bytes.byte1),hex(madonnee.bytes.byte2),hex(madonnee.bytes.byte3),hex(madonnee.bytes.byte4),hex(madonnee.bytes.byte5),hex(madonnee.bytes.byte6),hex(madonnee.bytes.byte7)))#time.sleep(1)#print(15)madonnee.floats.float0=0.000madonnee.floats.float1=0.000ID=hex(0b000100010010)time.sleep(0.001)pyCan.send(can_fd,8,'%s:%s,%s,%s,%s,%s,%s,%s,%s'%(ID,hex(madonnee.bytes.byte0),hex(madonnee.bytes.byte1),hex(madonnee.bytes.byte2),hex(madonnee.bytes.byte3),hex(madonnee.bytes.byte4),hex(madonnee.bytes.byte5),hex(madonnee.bytes.byte6),hex(madonnee.bytes.byte7)))pyCan.close(can_fd)exit()
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
can you please check:
- if the can4linux is compiled with the correct settings and the correct settings are used
- if the python swig library is compiled using the same settings as used for the can4linux driver.
we have just tested the current code, but not on BananaPI, but on a desktop PC, and could not reproduce your problem.
here the results of your test:
Received with ret=1: 1457692844.446517 id=2/0x00000002
len=8 flags=0x00 : bD ( 8): 00 04 d0 07 04 01 00 00
Received with ret=1: 1457692844.448726 id=34/0x00000022
len=8 flags=0x00 : bD ( 8): cd cc cc 3d 0a d7 23 3c
Received with ret=1: 1457692844.449857 id=50/0x00000032
len=8 flags=0x00 : bD ( 8): 00 00 70 41 00 00 00 00
Received with ret=1: 1457692844.452057 id=66/0x00000042
len=8 flags=0x00 : bD ( 8): 00 00 f0 41 00 00 00 00
Received with ret=1: 1457692844.454238 id=82/0x00000052
len=8 flags=0x00 : bD ( 8): 17 b7 51 38 0a d7 23 3c
Received with ret=1: 1457692844.455344 id=98/0x00000062
len=8 flags=0x00 : bD ( 8): 00 00 00 00 00 01 02 03
Received with ret=1: 1457692844.456420 id=130/0x00000082
len=8 flags=0x00 : bD ( 8): 0a d7 af 42 00 00 32 3c
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The structure split 87.92 into 4 bytes (from 0 to 3), same goes with 72.
So this code send me back 0x42, the last bytes is supposed to be 42 but in your code it's 0x3C and that is the problem.
Maybe I made a mistake in my code (I don't have a lot experience in python) but it seems that you did reproduce the mistake.
If I print the 8 bytes, 87.92 and 72 I have (0x0A,0xD7,0xAF,0x42,0x00,0X00,0x90,0x42) and you got
I just tested the Python code on my Bananpi. All works well.
I now used the can4linux-examples/pyCan-example.py extended with some more pyCan.send() statements.
typical BananaPi can4linux is compiled without long frame support for CANFD,
without setting -DCANFD in the Makefile
/proc/sys/dev/Can/framelength:8
The same should be valid when compiling the examples
and of course the Python wrapper.
To test the problem with CAN messages with 8 byte data frame length and last byte 0x3c
I added some test frames to send, but all in the simple format like
pyCan.send(can_fd, 8,'0x100:0xaa, 1, 2, 3, 4, 0x11, 0x22, 0x33, 0x3c')
Hi,
I'am using can4linux r518 on a bananapi (I'm using raspbian, bananian and also bananian on a banana pro).
My problem is very simple, I'm sending 8 bytes with this command:
The first message is fine, but for example if the last byte (madonnee.bytes.byte7) is equal to 0x3C, all the message after that will always end with 0x3C even if I send a message like that
So for that exemple, the last 4 bytes will be 0x00,0x01,0x02 and 0x3C
The problem only appears when I send 8 bytes.
I don't know how this is possible because if I copy/paste that exact same line in a file where I only send that message it's working fine. The bug only appears when I try to send multiple messages.
I've attached a draft of my code in python if you want to give it a shot and maybe help me to fin the mistake.
PS: sorry for my poor english.
the code:
can you please check:
- if the can4linux is compiled with the correct settings and the correct settings are used
- if the python swig library is compiled using the same settings as used for the can4linux driver.
we have just tested the current code, but not on BananaPI, but on a desktop PC, and could not reproduce your problem.
here the results of your test:
Received with ret=1: 1457692844.446517 id=2/0x00000002
len=8 flags=0x00 : bD ( 8): 00 04 d0 07 04 01 00 00
Received with ret=1: 1457692844.448726 id=34/0x00000022
len=8 flags=0x00 : bD ( 8): cd cc cc 3d 0a d7 23 3c
Received with ret=1: 1457692844.449857 id=50/0x00000032
len=8 flags=0x00 : bD ( 8): 00 00 70 41 00 00 00 00
Received with ret=1: 1457692844.452057 id=66/0x00000042
len=8 flags=0x00 : bD ( 8): 00 00 f0 41 00 00 00 00
Received with ret=1: 1457692844.454238 id=82/0x00000052
len=8 flags=0x00 : bD ( 8): 17 b7 51 38 0a d7 23 3c
Received with ret=1: 1457692844.455344 id=98/0x00000062
len=8 flags=0x00 : bD ( 8): 00 00 00 00 00 01 02 03
Received with ret=1: 1457692844.456420 id=130/0x00000082
len=8 flags=0x00 : bD ( 8): 0a d7 af 42 00 00 32 3c
I'm sorry but I think there is a mistake
The structure split 87.92 into 4 bytes (from 0 to 3), same goes with 72.
So this code send me back 0x42, the last bytes is supposed to be 42 but in your code it's 0x3C and that is the problem.
Maybe I made a mistake in my code (I don't have a lot experience in python) but it seems that you did reproduce the mistake.
If I print the 8 bytes, 87.92 and 72 I have (0x0A,0xD7,0xAF,0x42,0x00,0X00,0x90,0x42) and you got
So there is 2 wrong bytes.
Is it possible for you to print madonne.bytes.byteX to what you got?
Last edit: FRIKHA Walid 2016-03-12
Walid,
I just tested the Python code on my Bananpi. All works well.
I now used the can4linux-examples/pyCan-example.py extended with some more pyCan.send() statements.
typical BananaPi can4linux is compiled without long frame support for CANFD,
without setting -DCANFD in the Makefile
/proc/sys/dev/Can/framelength:8
The same should be valid when compiling the examples
and of course the Python wrapper.
you have to install:
(for me it is Python 2.7.6-8ubuntu0.2)
and compile with
make pyCan USECANFD=
To test the problem with CAN messages with 8 byte data frame length and last byte 0x3c
I added some test frames to send, but all in the simple format like
pyCan.send(can_fd, 8,'0x100:0xaa, 1, 2, 3, 4, 0x11, 0x22, 0x33, 0x3c')
The result on the bus is:
1457894182.699766 256/0x00000100 : bD ( 8): 01 02 03 04 11 22 33 00
1457894182.700709 256/0x00000100 : bD ( 8): 02 02 03 04 11 22 33 3c
1457894182.701661 256/0x00000100 : bD ( 8): 03 02 03 04 11 22 33 01
1457894182.702612 256/0x00000100 : bD ( 8): 04 02 03 04 11 22 33 3c
1457894182.703557 256/0x00000100 : bD ( 8): 05 02 03 04 11 22 33 03
1457894182.704508 256/0x00000100 : bD ( 8): 06 02 03 04 11 22 33 3c
1457894182.705462 256/0x00000100 : bD ( 8): 07 02 03 04 11 22 33 04
1457894182.706404 256/0x00000100 : bD ( 8): 08 02 03 04 11 22 33 3c
1457894182.707347 256/0x00000100 : bD ( 8): 09 02 03 04 11 22 33 55
1457894182.708293 256/0x00000100 : bD ( 8): 0a 02 03 04 11 22 33 aa
As expected from the source code:
So it seems that
- you did not compile correctly
- or your Python code is not correct
Thank you very much for you explanation. I'll try again.