我确实从 Lawicell 购买了 USB 转 CAN,使用本教程(http://pascal-walter.blogspot.com/2015/08/installing-lawicel-canusb-on-linux.html) 设备正在运行,但我无法使用 udev 规则自动检测到它(ubuntu 16 04 LTS)
USB 连接时触发 udev 规则:
#Lawicell CAN USB auto detect
ACTION=="add", ATTRS{serial}=="LW2ZV78N", RUN+="/etc/udev/scripts/start_slcand"
如果手动运行,脚本就会起作用(只有这个设备连接到我的笔记本电脑,sudo pkill slcand
拔掉电源时我会手动运行)
#!/bin/sh
#Add USB CAN
sleep 1
slcand -o -c -f -s6 /dev/ttyUSB* slcan0
sleep 2
ifconfig slcan0 up
日志中存在导致设备被移除的问题,但我不知道该怎么办。有人能帮忙吗?
Sep 11 19:52:02 elliot-Satellite-P300 kernel: [ 1168.356397] usb 6-1: new full-speed USB device number 7 using uhci_hcd
Sep 11 19:52:02 elliot-Satellite-P300 kernel: [ 1168.571681] usb 6-1: New USB device found, idVendor=0403, idProduct=6001
Sep 11 19:52:02 elliot-Satellite-P300 kernel: [ 1168.571690] usb 6-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Sep 11 19:52:02 elliot-Satellite-P300 kernel: [ 1168.571695] usb 6-1: Product: CANUSB
Sep 11 19:52:02 elliot-Satellite-P300 kernel: [ 1168.571700] usb 6-1: Manufacturer: LAWICEL
Sep 11 19:52:02 elliot-Satellite-P300 kernel: [ 1168.571704] usb 6-1: SerialNumber: LW2ZV78N
Sep 11 19:52:02 elliot-Satellite-P300 kernel: [ 1168.577727] ftdi_sio 6-1:1.0: FTDI USB Serial Device converter detected
Sep 11 19:52:02 elliot-Satellite-P300 kernel: [ 1168.577801] usb 6-1: Detected FT232RL
Sep 11 19:52:02 elliot-Satellite-P300 kernel: [ 1168.579780] usb 6-1: FTDI USB Serial Device converter now attached to ttyUSB0
Sep 11 19:52:02 elliot-Satellite-P300 mtp-probe: checking bus 6, device 7: "/sys/devices/pci0000:00/0000:00:1d.0/usb6/6-1"
Sep 11 19:52:03 elliot-Satellite-P300 mtp-probe: bus: 6, device: 7 was not an MTP device
Sep 11 19:52:04 elliot-Satellite-P300 slcand[4976]: starting on TTY device /dev/ttyUSB0
Sep 11 19:52:04 elliot-Satellite-P300 slcand[4977]: attached TTY /dev/ttyUSB0 to netdevice slcan0
Sep 11 19:52:04 elliot-Satellite-P300 NetworkManager[751]: nm_device_get_device_type: assertion 'NM_IS_DEVICE (self)' failed
Sep 11 19:52:04 elliot-Satellite-P300 NetworkManager[751]: <info> [1568224324.0234] manager: (slcan0): new Generic device (/org/freedesktop/NetworkManager/Devices/10)
Sep 11 19:52:04 elliot-Satellite-P300 NetworkManager[751]: <info> [1568224324.0520] devices added (path: /sys/devices/virtual/net/slcan0, iface: slcan0)
Sep 11 19:52:04 elliot-Satellite-P300 NetworkManager[751]: <info> [1568224324.0520] device added (path: /sys/devices/virtual/net/slcan0, iface: slcan0): no ifupdown configuration found.
Sep 11 19:52:08 elliot-Satellite-P300 slcand[5009]: starting on TTY device /dev/ttyUSB0
Sep 11 19:52:08 elliot-Satellite-P300 slcand[5010]: attached TTY /dev/ttyUSB0 to netdevice slcan0
Sep 11 19:52:11 elliot-Satellite-P300 slcand[5019]: starting on TTY device /dev/ttyUSB0
Sep 11 19:52:11 elliot-Satellite-P300 slcand[5020]: attached TTY /dev/ttyUSB0 to netdevice slcan0
Sep 11 19:52:14 elliot-Satellite-P300 slcand[5028]: starting on TTY device /dev/ttyUSB0
Sep 11 19:52:14 elliot-Satellite-P300 slcand[5029]: attached TTY /dev/ttyUSB0 to netdevice slcan0
Sep 11 19:52:16 elliot-Satellite-P300 NetworkManager[751]: <error> [1568224336.1011] platform-linux: do-change-link[11]: failure changing link: failure 19 (No such device)
Sep 11 19:52:16 elliot-Satellite-P300 NetworkManager[751]: <warn> [1568224336.1011] device (slcan0): failed to disable userspace IPv6LL address handling
Sep 11 19:52:16 elliot-Satellite-P300 NetworkManager[751]: <info> [1568224336.1108] devices removed (path: /sys/devices/virtual/net/slcan0, iface: slcan0)
答案1
- 删除这些
sleep
行,因为udev
它们会终止耗时较长的进程 - 删除,
ifconfig
因为如果失败,则表示设备添加失败。请/etc/network/interfaces
改用。