查看串口的详细信息
linux
udevadm info --name=/dev/ttyUSB0
结果:
LINUX
P: /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0/ttyUSB0/tty/ttyUSB0
N: ttyUSB0
L: 0
S: serial/by-id/usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_0001-if00-port0
S: serial/by-path/platform-fd500000.pcie-pci-0000:01:00.0-usb-0:1.2:1.0-port0
S: device2
E: DEVPATH=/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0/ttyUSB0/tty/ttyUSB0
E: DEVNAME=/dev/ttyUSB0
E: MAJOR=188
E: MINOR=0
E: SUBSYSTEM=tty
E: USEC_INITIALIZED=366284608
E: ID_BUS=usb
E: ID_VENDOR_ID=10c4
E: ID_MODEL_ID=ea60
E: ID_PCI_CLASS_FROM_DATABASE=Serial bus controller
E: ID_PCI_SUBCLASS_FROM_DATABASE=USB controller
E: ID_PCI_INTERFACE_FROM_DATABASE=XHCI
E: ID_VENDOR_FROM_DATABASE=Silicon Labs
E: ID_MODEL_FROM_DATABASE=CP210x UART Bridge
E: ID_VENDOR=Silicon_Labs
E: ID_VENDOR_ENC=Silicon\x20Labs
E: ID_MODEL=CP2102_USB_to_UART_Bridge_Controller
E: ID_MODEL_ENC=CP2102\x20USB\x20to\x20UART\x20Bridge\x20Controller
E: ID_REVISION=0100
E: ID_SERIAL=Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_0001
E: ID_SERIAL_SHORT=0001
E: ID_TYPE=generic
E: ID_USB_INTERFACES=:ff0000:
E: ID_USB_INTERFACE_NUM=00
E: ID_USB_DRIVER=cp210x
E: ID_PATH=platform-fd500000.pcie-pci-0000:01:00.0-usb-0:1.2:1.0
E: ID_PATH_TAG=platform-fd500000_pcie-pci-0000_01_00_0-usb-0_1_2_1_0
E: ID_MM_CANDIDATE=1
E: DEVLINKS=/dev/serial/by-id/usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_0001-if00-port0 /dev/serial/by-path/platform-fd500000.pcie-pci-0000:01:00.0-usb-0:1.2:1.0-port0 /dev/device2
E: TAGS=:systemd:
通过id固定串口名称
通过lsusb
查看串口设备的id,id为1a86和7523
在/etc/udev/rules.d
的10-local.rules文件中添加
linux
ACTION=="add", KERNEL=="ttyUSB*", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", MODE:="0777",SYMLINK+="serialname"
保存关闭,重启服务sudo /etc/init.d/udev restart
,reboot重启最好
通过USB口位置固定名称
还是借鉴一下本文
如果插入扩展坞扩展USB口,也能这么配置,比如把编号1-1.1的USB口扩展成4个USB口
重新配置rules文件,注释之前的1.1.1那行配置,再添加4行
linux
# KERNEL=="ttyUSB*",KERNELS=="1-1.1",MODE:="0777",SYMLINK+="device1"
KERNEL=="ttyUSB*",KERNELS=="1-1.1.1",MODE:="0777",SYMLINK+="device11"
KERNEL=="ttyUSB*",KERNELS=="1-1.1.2",MODE:="0777",SYMLINK+="device12"
KERNEL=="ttyUSB*",KERNELS=="1-1.1.3",MODE:="0777",SYMLINK+="device13"
KERNEL=="ttyUSB*",KERNELS=="1-1.1.4",MODE:="0777",SYMLINK+="device14"
Permission denied: '/dev/ttyUSB0'
sudo usermod -aG dialout username
(username为用户民)
把用户名加入了dialout用户组,因tty设备隶属于dialout用户组,重启系统