I have two PCAN-USB devices attached to each other to test Python code to send CAN packets (code below). I use `candump can0` and `candump can1` in separate shells and use a third shell to send my test frames. I'm using `socketcan` with `python-can 4.2.2`.
If I send on either can0 or can1 I see the packets printed by `candump` but I get a mysterious frame with ID 0x200. Then then the interface apparently errors out and goes down. In the case below, I send a single packet to 0x0F0.
$ candump can0
can0 0F0 [8] 00 19 00 01 03 01 04 00
can0 200 [8] 00 08 00 00 00 00 60 00
$ ip link
7: can1: <NO-CARRIER,NOARP,UP,ECHO> mtu 16 qdisc pfifo_fast state DOWN mode DEFAULT group default qlen 10
link/can
8: can0: <NO-CARRIER,NOARP,UP,ECHO> mtu 16 qdisc pfifo_fast state DOWN mode DEFAULT group default qlen 10
link/can
$ ip -details -statistics link show can0
8: can0: <NO-CARRIER,NOARP,UP,ECHO> mtu 16 qdisc pfifo_fast state DOWN mode DEFAULT group default qlen 10
link/can promiscuity 0 allmulti 0 minmtu 0 maxmtu 0
can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0
bitrate 50000 sample-point 0.875
tq 1250 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1 brp 10
pcan_usb: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp_inc 1
clock 8000000
re-started bus-errors arbit-lost error-warn error-pass bus-off
0 0 0 1 0 1 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 tso_max_size 65536 tso_max_segs 65535 gro_max_size 65536 parentbus usb parentdev 1-3:1.0
RX: bytes packets errors dropped missed mcast
0 0 0 0 0 0
TX: bytes packets errors dropped carrier collsns
8 1 0 1 0 0
Code: Select all
RECEIVER_ID = 0x0F0
TRANSMITTER_ID = 0x0F1
FILTERS_0 = [
{"can_id": RECEIVER_ID, "can_mask": 0x7FF, "extended": False},
]
FILTERS_1 = [
{"can_id": TRANSMITTER_ID, "can_mask": 0x7FF, "extended": False},
]
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="CAN Prototype")
parser.add_argument(
"--receive",
"-r",
action="store_true",
)
parser.add_argument(
"--bus",
"-b",
type=int,
default=0,
choices=(0, 1),
)
parser.add_argument(
"--count",
"-c",
type=int,
default=1,
)
arguments = parser.parse_args()
if arguments.receive:
print("Receiving")
with can.Bus("can0", "socketcan", can_filters=FILTERS_0) as bus:
while True:
message = bus.recv()
print(message.data)
else:
print("Transmitting")
with can.Bus(f"can{arguments.bus}", "socketcan", can_filters=FILTERS_1) as bus:
for i in range(arguments.count):
message = can.Message(
arbitration_id=RECEIVER_ID,
data=[0, 25, 0, 1, 3, 1, 4, i],
is_extended_id=False
)
try:
bus.send(message)
print(f"Message {i} sent on {bus.channel_info}")
except can.CanError:
print("Message NOT sent")
time.sleep(1)
$ uname -a
Linux bobby 6.11.0-17-generic #17~24.04.2-Ubuntu SMP PREEMPT_DYNAMIC Mon Jan 20 22:48:29 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
$ lsmod | grep peak
peak_usb 65536 0
can_dev 53248 1 peak_usb