數(shù)據(jù)資源網(wǎng)站如何做企業(yè)策劃咨詢公司
綁定端口
- 打開終端,輸入以下命令查看USB端口信息:
udevadm info -a -n /dev/ttyUSB0
執(zhí)行后,可以看到部分輸出如下:
找到第一個(gè),a-b:c格式的KERNELS,記住這個(gè)值,后面會(huì)用到。
lin@lin-B660M-D2H-DDR4:~$ udevadm info -a -n /dev/ttyUSB0Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.looking at device '/devices/pci0000:00/0000:00:14.0/usb1/1-11/1-11.1/1-11.1:1.0/ttyUSB0/tty/ttyUSB0':KERNEL=="ttyUSB0"SUBSYSTEM=="tty"DRIVER==""looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1/1-11/1-11.1/1-11.1:1.0':KERNELS=="1-11.1:1.0"SUBSYSTEMS=="usb"DRIVERS=="ch341"ATTRS{bInterfaceNumber}=="00"ATTRS{bInterfaceSubClass}=="01"ATTRS{bAlternateSetting}==" 0"ATTRS{authorized}=="1"ATTRS{bInterfaceClass}=="ff"ATTRS{bInterfaceProtocol}=="02"ATTRS{supports_autosuspend}=="1"ATTRS{bNumEndpoints}=="03"
其中需要用到的信息有:
- KERNELS==“1-11.1:1.0”
同樣的,另一個(gè)端口如下:
- KERNELS==“1-11.2:1.0”
- 添加udev規(guī)則:
sudo vim /etc/udev/rules.d/test_usb.rules
添加以下內(nèi)容:
如果是/dev/ttyUSB*
,則KERNEL要改為KERNEL=="ttyUSB*"
:
如果是/dev/video*
,則KERNEL要改為KERNEL=="video*"
:
KERNEL=="ttyUSB*", KERNELS=="1-11.2:1.0", MODE:="0777", SYMLINK+="ttyUSB_test_back"
KERNEL=="ttyUSB*", KERNELS=="1-11.1:1.0", MODE:="0777", SYMLINK+="ttyUSB_test_front"
保存并退出,執(zhí)行以下命令:
sudo udevadm control --reload-rules
sudo udevadm trigger
sudo service udev reload
sudo service udev restart
- 重啟后,就可以通過以下命令查看端口號(hào):
ls /dev/ttyUSB*
輸出:
/dev/ttyUSB0 /dev/ttyUSB1 /dev/ttyUSB_test_back /dev/ttyUSB_test_front