Canbus only send single data

My Jetson nano with MCP2515 has already sent data with my other devices, and i write a .py to use it, showing as followed

import os
import time
import can

os.system('sudo ip link set can0 type can bitrate 500000') # can0500K
os.system('sudo ifconfig can0 up') # can0 up

can0 = can.interface.Bus(channel = 'can0', bustype = 'socketcan_ctypes')# socketcan_native

# msg = can.Message(arbitration_id=0x601, data=[0x2F, 00, 20, 00, 01, 00, 00, 00])
# can0.send(msg)

DATA_LIST = [
    [0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
    [0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
]

for data in DATA_LIST:
    msg = can.Message(arbitration_id=0x601, data=data)
    can0.send(msg)
    time.sleep(0.1)

os.system('sudo ifconfig can0 down')

But my device can only receive 1 data, and i don’t know why and how to deal with?

Any useful suggestions? Thanks a lot!

Hi 1030789164,

Are you using the devkit or custom board for Jetson Nano?
What’s your Jetpack version in use?

Do you mean the “Jetson Nano” or your CAN device?

Is there any error showing in dmesg?

Hi KevinFFF
I’m using the Jetson NANO developer kit B01, Jetpack 4.6.1;
my device is a USB-CAN module, the left part of the picture I showed is the result;
you can see I only can receive one message; but my python code has two msgs in DATA_LIST;
I don’t know what’s the problem.
So could you give me some guide, Thank you~!

Hello KevinFFF

I update my python code, add the receive function

import os
import can

os.system('sudo ip link set can0 type can bitrate 500000') # can0500K
os.system('sudo ifconfig can0 up') # can0 up

# can0 = can.interface.Bus(channel = 'can0', bustype = 'socketcan_ctypes')# socketcan_native

def send_message(bus, msg):
    try:
        bus.send(msg)
        print(f"Sent: {msg}")
    except can.CanError as e:
        print(f"Error sending message: {e}")

def receive_messages(bus):
    try:
        while True:
            msg = bus.recv(1.0)
            if msg is not None:
                print(f"Received: {msg}")
    except KeyboardInterrupt:
        pass


if __name__ == '__main__':
    try:
        can0 = can.interface.Bus(channel = 'can0', bustype = 'socketcan_ctypes')

        msg = can.Message(arbitration_id=0x123, data=[0x11, 0x22, 0x33, 0x44])
        msg1 = can.Message(arbitration_id=0x123, data=[0x55, 0x66, 0x77, 0x88])

        send_message(can0, msg)
        send_message(can0, msg1)

        receive_messages(can0)

    except can.CanError as e:
        print(f"Error accessing CAN bus: {e}")

    finally:
        os.system('sudo ifconfig can0 down')

I find something new, when I run this .py above, my PC(USB2CAN, communicate with my NANO B01 kit) get 1 msg

And I let my PC send 1 msg (this case is 2F) to my NANO


I get the second msg!!

So I want to know if CAN in NANO must send 1 msg and receive 1 msg; then send 1, receive 1, send, receive…

Hope for your reply~! Thank you!

I don’t think so.

Could you use cangen can0 from your host to check if there’s similar behavior?

the loopback on mode


I check some blogs, maybe the reason is can buffer space? or the acknowledge/request mode?
Do you have some experience about debug the CAN-bus?
Or some advice about the .py code, thanks~!

There is no update from you for a period, assuming this is not an issue any more.
Hence we are closing this topic. If need further support, please open a new one.
Thanks

How do you get the “write: No buffer space available” issue?

Please share the result of the following command on your board.

$ sudo ip -d -s link show can0