I want to start slcand
(the userspace daemon for the serial line CAN interface driver) when my Lawicel CanUSB dongle is plugged in. I followed Pascal Walter's step-by-step guide and all seems to work (slcan0 is there and i can bind(2)), except I never actually receive anything (only outgoing messages are visible in candump
and Wireshark).
The udev rule looks as follows:
# Lawicel CANUSB moduleACTION=="add", ENV{ID_MODEL}=="CANUSB", ENV{SUBSYSTEM}=="tty", RUN+="/usr/bin/logger [udev] Lawicel CANUSB detected - running slcan_add.sh!", RUN+="/usr/local/bin/slcan_add.sh $kernel"ACTION=="remove", ENV{ID_MODEL}=="CANUSB", ENV{SUBSYSTEM}=="usb", RUN+="/usr/bin/logger [udev] Lawicel CANUSB removed - running slcan_remove.sh!", RUN+="/usr/local/bin/slcan_remove.sh"
with /usr/local/bin/slcan_add.sh
#!/bin/sh# Bind the USBCAN deviceslcand -o -c -f -s8 /dev/$1 slcan0sleep 2ifconfig slcan0 up
and /usr/local/bin/slcan_remove.sh
#!/bin/sh# Remove the USBCAN devicepkill slcand
However when I manually execute sudo /usr/local/bin/slcan_remove.sh && sudo /usr/local/bin/slcan_add.sh ttyUSB0
, everything works as expected and I can see all CAN messages with candump slcan0
).
The interface looks just the same as with udev. ip link show slcan0
gives:
91: slcan0: <NOARP,UP,LOWER_UP> mtu 16 qdisc pfifo_fast state UNKNOWN mode DEFAULT group default qlen 10
The NetworkManager has a problem with slcan0, but that appears also when creating slcan0 manually as described above. The output of tail -f /var/log/syslog
when plugging in is:
May 26 18:29:18 laurenz-T440p logger: [udev] Lawicel CANUSB detected - running slcan_add.shMay 26 18:29:18 laurenz-T440p slcand[14924]: starting on TTY device /dev/ttyUSB0May 26 18:29:18 laurenz-T440p slcand[14925]: attached TTY /dev/ttyUSB0 to netdevice slcan0May 26 18:29:18 laurenz-T440p slcand[14925]: netdevice slcan0 renamed to slcan0May 26 18:29:18 laurenz-T440p NetworkManager[866]: SCPlugin-Ifupdown: devices added (path: /sys/devices/virtual/net/slcan0, iface: slcan0)May 26 18:29:18 laurenz-T440p NetworkManager[866]: SCPlugin-Ifupdown: device added (path: /sys/devices/virtual/net/slcan0, iface: slcan0): no ifupdown configuration found.May 26 18:29:18 laurenz-T440p NetworkManager[866]: <warn> /sys/devices/virtual/net/slcan0: couldn't determine device driver; ignoring...
ps -fauxw | grep can
(manual start as above):
root 1221 0.0 0.0 4336 100 ? Ss 11:38 0:00 \_ slcand -o -c -f -s8 /dev/ttyUSB0 slcan0
ps -fauxw | grep can
(re-plugging triggered udev start):
root 1362 0.0 0.0 4336 96 ? Ss 11:45 0:00 slcand -o -c -f -s8 /dev/ttyUSB0 slcan0
What could the problem with udev be? How can I fix it?
Update: Ok, so I added an Ixxat USB-to-CAN V2 and installed its SocketCan driver. It has the same problem: Tx fine, Rx not working.
Interestingly, I can just plug the two together (120R in the middle). Then I run candump -d -e -c -x -t absolute any,0:0,#FFFFFFFF
in one Terminal. In another, I send CAN frames with cansend can0 000#
(Send one frame with CanID 0, length 0 via can0 (the Ixxat adapter)). The result depends on if I started the slcand manually or via udev.
Manual (as described above):
$ candump -d -e -c -x -t absolute any,0:0,#FFFFFFFF(1464614442.246548) can0 TX - - 000 [0] (1464614442.249320) slcan0 RX - - 000 [0]
Via Udev:
$ candump -d -e -c -x -t absolute any,0:0,#FFFFFFFF (1464614643.800545) can0 RX - - 20000020 [8] 00 00 00 00 00 00 00 00 ERRORFRAME no-acknowledgement-on-tx (1464614643.807361) can0 RX - - 20000020 [8] 00 00 00 00 00 00 00 00 ERRORFRAME no-acknowledgement-on-tx (1464614643.814058) can0 RX - - 20000020 [8] 00 00 00 00 00 00 00 00 ERRORFRAME no-acknowledgement-on-tx (1464614643.820840) can0 RX - - 20000020 [8] 00 00 00 00 00 00 00 00 ERRORFRAME no-acknowledgement-on-tx[and so on...]
Here is my lsmod | grep can
:
vcan 16384 0 slcan 16384 1 can_dev 24576 2 ixx_pci,ixx_usbcan_raw 20480 0 can 45056 1 can_raw
I'm on a Ubuntu 14.04 machine with a 4.4 kernel. uname -rv
:
4.4.0-21-generic #37~14.04.1-Ubuntu SMP Wed Apr 20 16:33:38 UTC 2016