因工程需要,固定ttyUSB,参考:
https://blog.csdn.net/qq_25544855/article/details/79320556
KERNEL=="ttyUSB*", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", MODE:="0777", GROUP:="dialout", SYMLINK+="ch340g"
失败。
删除配置信息后在/dev下找不到ttyUSB*(注:本人使用ch340g,ubuntu16.04,内核版本:4.15.0-55-generic)
解决方法:可参考:https://blog.csdn.net/u010750137/article/details/57103002
$ make
$ sudo make load
#出现以下信息说明成功
modprobe usbserial
insmod ch34x.ko
成功!
20190802更新:
参考:https://blog.csdn.net/jiangchao3392/article/details/76227180
在/etc/udev/rule.d/ch34x.rules中输入:
KERNEL=="ttyUSB*", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", MODE:="0777", SYMLINK+="falling_prevention"
重新加载规则:
sudo udevadm control --reload
重启后,可以用pyserial使用串口:/dev/falling_prevention
from serial import Serial
def connect():
port="/dev/falling_prevention"
baudrate=9600
timeout=None
port = Serial(port=port, baudrate=baudrate, timeout=timeout, writeTimeout=timeout)
while not rospy.is_shutdown():
value = port.read(1)
但是输入:
KERNEL=="3-1:1.0", GROUP:="dialout", MODE:="0666", SYMLINK+="mcu_uart"
没有用。
但是我要使用两个以上的ch340,只能另想办法。
接下来参考:https://blog.csdn.net/Warnemuende/article/details/73920980,发现还有一条有用信息:devpath!
插拔不同的端口后查看信息:
$ udevadm info --attribute-walk /sys/class/tty/ttyUSB0 | grep devpath
Udevadm info starts with the device specified by the devpath and then
ATTRS{devpath}=="1"
ATTRS{devpath}=="0"
$ udevadm info --attribute-walk /sys/class/tty/ttyUSB0 |grep devpath
Udevadm info starts with the device specified by the devpath and then
ATTRS{devpath}=="2"
ATTRS{devpath}=="0"
实验发现不同端口对应的devpath不同,故可以用来区分端口:
加入规则:
KERNEL=="ttyUSB*", ATTRS{devpath}=="1",ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", MODE:="0777",SYMLINK+="falling_prevention"
KERNEL=="ttyUSB*", ATTRS{devpath}=="3",ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", MODE:="0777",SYMLINK+="imu"
重启后再次查看:
$ ls -l /dev | grep ttyUSB
lrwxrwxrwx 1 root root 7 Aug 2 14:46 falling_prevention -> ttyUSB0
crwxrwxrwx 1 root dialout 188, 0 Aug 2 14:46 ttyUSB0
成功。
udev资料:
https://blog.csdn.net/cokewei/article/details/8281239(待验证,后面试试)
树莓派usb资料:
https://blog.csdn.net/xqf1528399071/article/details/52191637
https://blog.csdn.net/qq_38441692/article/details/88314310