I am using a Lawicel CAN adapter to connect to a sensor, and would like to setup a udev rule to avoid the manual can setup.
The manual can setup:
sudo slcand -o -c -f -s6 /dev/ttyUSB0 slcan0
sudo ifconfig slcan0 up
Running candump slcan0
shows, by printing data, that the connection works.
I am thus following a guide to setting up the udev rule from link. But this doesn't work. The udev rule is
# Lawicel CANUSB module
ACTION=="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"
and the slcan_add.sh
script is
#!/bin/sh
# Bind the USBCAN device
slcand -o -c -f -s6 /dev/$1 slcan0
sleep 2
ifconfig slcan0 up
then I reload the rules and restart udev, and tail -f /var/log/syslog
returns the following
morten@thinkpad:~$ tail -f /var/log/syslog
Oct 7 10:56:21 thinkpad kernel: [ 1580.917239] usb 1-1: Detected FT232RL
Oct 7 10:56:21 thinkpad kernel: [ 1580.918002] usb 1-1: FTDI USB Serial Device converter now attached to ttyUSB0
Oct 7 10:56:21 thinkpad mtp-probe: checking bus 1, device 10: "/sys/devices/pci0000:00/0000:00:14.0/usb1/1-1"
Oct 7 10:56:21 thinkpad mtp-probe: bus: 1, device: 10 was not an MTP device
Oct 7 10:56:21 thinkpad root: [udev] Lawicel CANUSB detected - running slcan_add.sh!
Oct 7 10:56:21 thinkpad slcand[5967]: starting on TTY device /dev/ttyUSB0
Oct 7 10:56:21 thinkpad slcand[5968]: attached TTY /dev/ttyUSB0 to netdevice slcan0
Oct 7 10:56:21 thinkpad slcand[5968]: netdevice slcan0 renamed to slcan0
Oct 7 10:56:21 thinkpad NetworkManager[649]: <info> [1633596981.6497] manager: (slcan0): new Generic device (/org/freedesktop/NetworkManager/Devices/8)
Oct 7 10:56:21 thinkpad systemd-udevd[5954]: ethtool: autonegotiation is unset or enabled, the speed and duplex are not writable.
Oct 7 10:56:23 thinkpad snapd[668]: hotplug.go:199: hotplug device add event ignored, enable experimental.hotplug
Oct 7 10:56:23 thinkpad mtp-probe: checking bus 1, device 10: "/sys/devices/pci0000:00/0000:00:14.0/usb1/1-1"
Oct 7 10:56:23 thinkpad mtp-probe: bus: 1, device: 10 was not an MTP device
Oct 7 10:56:26 thinkpad ModemManager[791]: <info> [base-manager] couldn't check support for device '/sys/devices/pci0000:00/0000:00:14.0/usb1/1-1': not supported by any plugin
Oct 7 10:56:27 thinkpad gnome-shell[1997]: Removing a network device that was not added
Oct 7 10:56:27 thinkpad gnome-shell[1426]: Removing a network device that was not added
and candump slcan0
returns SIOCGIFINDEX: No such device
. How should I fix this?
NOTE: Using ubuntu 20.04.
EDIT: The udev rule properly recognizes the device and runs the script, so the udev rule should work I figure. If I manually set the usb port and run the shell script with sudo ./sclan_add.sh
then it also works, displaying the following in tail -f /var/log/syslog
Oct 7 12:53:26 agrirobot slcand[20933]: starting on TTY device /dev/ttyUSB0
Oct 7 12:53:26 agrirobot slcand[20934]: attached TTY /dev/ttyUSB0 to netdevice slcan0
Oct 7 12:53:26 agrirobot slcand[20934]: netdevice slcan0 renamed to slcan0
Oct 7 12:53:26 agrirobot NetworkManager[649]: <info> [1633604006.8360] manager: (slcan0): new Generic device (/org/freedesktop/NetworkManager/Devices/22)
Oct 7 12:53:26 agrirobot systemd-udevd[20936]: ethtool: autonegotiation is unset or enabled, the speed and duplex are not writable.
I can't really see what the problem is with the udev rule calling the shell script, but for some reason this makes the difference.
lsblk | grep dev
. – Cbhihe Oct 08 '21 at 07:13$kernel
is a misnomer. It is in fact the "device" name, which you can get per my modified comment. – Cbhihe Oct 08 '21 at 07:15ttyUSB0
or what? – Morten Nissov Oct 08 '21 at 07:16starting on TTY device /dev/ttyUSB0
you'll see it does actually start the device. Also when I tried to start it manually I confirmed that the dev port is correct.The problem in setting up the can interface comes from elsewhere.
– Morten Nissov Oct 08 '21 at 07:22snapd[668]:
line – Morten Nissov Oct 08 '21 at 07:22