rahmanuh
Posts: 3
Joined: Mon Jan 21, 2019 7:12 am

SLCAN failed to serialize CAN message

Wed Jul 10, 2019 7:09 am

Hi all,

First, I will tell a short story about my problem. Currently I am sending a CAN command to my CAN device in infinite loop. But at some point, my CAN device does not response the command (I made my CAN device only recognize registered command). After long debugging it, I found that somehow the serial message is having character lost. That makes the CAN frame that being serialized is not correctly sent to my CAN device.

Here is my setup
CANTimeoutSetup.png
CANTimeoutSetup.png (14.84 KiB) Viewed 134 times
On my Rpi, I set the SLCAN by:

Code: Select all

stty -F /dev/ttyAMA0 -echo crtscts 1000000 
sleep 1
/home/pi/can-stuff/rpirtscts/rpirtscts on --> enable rtccts
sleep 1
modprobe slcan
sleep 1
slcand -o -f -s8 -t hw -S 1000000 /dev/ttyAMA0  --> I need 1M baudrate
sleep 1
ip link set up slcan0
sleep 1
ip link set slcan0 txqueuelen 10000
sleep 1
echo 1146880 > /proc/sys/net/core/rmem_max
echo 1146880 > /proc/sys/net/core/wmem_max
To send the CAN message, I use python script with python-can library (https://python-can.readthedocs.io/en/master/api.html). In my script, I use 2 threads, 1 is for sending command and the other one is for reading the response. In the code below, I send 9 CAN frames. Here is the code snippet.

Code: Select all

	bus0 = can.interface.Bus(bustype='socketcan', 
								channel='slcan0', 
								bitrate=1000000)
								
	cmd_msg = []

	cmd_msg.append(can.Message(arbitration_id=0x601, 
						data=[0x42, 0x00, 0x00, 0x00, 0x76, 0x02, 0x00, 0x00], 
						extended_id=False))
	
	cmd_msg.append(can.Message(arbitration_id=0x601, 
						data=[0x01, 0x00, 0xD0, 0x00, 0x01, 0x00, 0x00, 0x00], 
						extended_id=False))

	cmd_msg.append(can.Message(arbitration_id=0x601, 
						data=[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], 
						extended_id=False))
	
	cmd_msg.append(can.Message(arbitration_id=0x601, 
						data=[0x00, 0x00, 0xD0, 0x12, 0x63, 0x41, 0x01, 0x00], 
						extended_id=False))

	cmd_msg.append(can.Message(arbitration_id=0x601, 
						data=[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], 
						extended_id=False))
	
	cmd_msg.append(can.Message(arbitration_id=0x601, 
						data=[0x00, 0x00, 0x00, 0x00, 0xD0, 0x12, 0x63, 0x41], 
						extended_id=False))

	cmd_msg.append(can.Message(arbitration_id=0x601, 
						data=[0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], 
						extended_id=False))
	
	cmd_msg.append(can.Message(arbitration_id=0x601, 
						data=[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD0, 0x12], 
						extended_id=False))
	
	cmd_msg.append(can.Message(arbitration_id=0x601, 
						data=[0x63, 0x41, 0x57, 0x51], 
						extended_id=False))

Here is the serial data when I got no response from my CAN device:
t60184200000076020000
t60180100D00001000000
t60180000000000000000
t60180000D01263410100
t60180000000000000000
t601800000000D0126341
t60180100000000000000
t6018000000000000D012
t601463415751
t60184200000076020000
t60180100D00001000000
t60180000000000000000
t60180000D012634101t60180000000000000000 --> character lost
t601800000000D0126341
t60180100000000000000
t6018000000000000D012
t601463415751
sometime it gets:
t60184200000076020000
t60180100D00001000000
t60180000000000000000
t60180000D01263410100
t60180000000000000000
t601800000000D0126341
t60180100000000000000
t6018000000000000D012
t601463415751
t60184200000076020000
t60180100D00001000000
t60180000000000000000
t60180000D01263410100
t601800000000000 --> character lost
t601800000000D0126341
t60180100000000000000
t6018000000000000D012
t601463415751
Do any of you experience the same thing with me?
Or do you have any thoughts about my problem?

Best regards,
Rahmanu

Return to “Troubleshooting”