我有很多 USB 转串口设备,每个都有很多端口,上面提到的解决方案对我来说并没有完全做到。
在我的情况下,USB“内核”还不够,但我找到了端口号。
我知道我现在提出的建议可能被认为是一种疯狂的黑客攻击,但它对我有用......
现在......
我真的很高兴看到一个更优雅的建议来完成类似的事情..
所以...基于之前的答案形式 Ilya Matveychikov
文件:/etc/udev/rules.d/usb-parse-devpath.sh
#!/bin/bash
DEVNUM=$(echo "${1}" | rev | cut -d'/' -f4 | rev | tr -d '-' | tr -d '.' | tr -d ':')
PORTNUM=$(/sbin/udevadm info -a --path=${1} | grep "ATTRS{port_number}" | head -1 | cut -d'"' -f2)
PRODUCT=$(/sbin/udevadm info -a --path=${1} | grep "ATTRS{product}" | head -1 | cut -d'"' -f2 | tr -d '/' | tr ' ' '_')
NEWID="ttyUSB_${PRODUCT}_${DEVNUM}${PORTNUM}"
#echo "${NEWID} :: $1" >> /tmp/DEBUG_udev.txt
echo "$NEWID"
和文件:/etc/udev/rules.d/99-usb-serial.rules
ACTION=="add", KERNEL=="ttyUSB[0-9]*", PROGRAM="/etc/udev/rules.d/usb-parse-devpath.sh %p", SYMLINK+="TTYUSBs/%c"
结果如下所示:
# ls -l /dev/TTYUSBs
lrwxrwxrwx. 1 root root 11 Jan 5 18:46 ttyUSB_Edgeport416_435100 -> ../ttyUSB20
lrwxrwxrwx. 1 root root 11 Jan 5 18:46 ttyUSB_Edgeport416_435101 -> ../ttyUSB21
lrwxrwxrwx. 1 root root 11 Jan 5 18:46 ttyUSB_Edgeport416_435102 -> ../ttyUSB22
lrwxrwxrwx. 1 root root 11 Jan 5 18:46 ttyUSB_Edgeport416_435103 -> ../ttyUSB23
lrwxrwxrwx. 1 root root 11 Jan 5 18:46 ttyUSB_Edgeport416_435104 -> ../ttyUSB24
lrwxrwxrwx. 1 root root 11 Jan 5 18:46 ttyUSB_Edgeport416_435105 -> ../ttyUSB25
lrwxrwxrwx. 1 root root 11 Jan 5 18:46 ttyUSB_Edgeport416_435106 -> ../ttyUSB26
lrwxrwxrwx. 1 root root 11 Jan 5 18:46 ttyUSB_Edgeport416_435107 -> ../ttyUSB27
lrwxrwxrwx. 1 root root 11 Jan 5 18:46 ttyUSB_Edgeport416_436100 -> ../ttyUSB28
lrwxrwxrwx. 1 root root 11 Jan 5 18:46 ttyUSB_Edgeport416_436101 -> ../ttyUSB29
lrwxrwxrwx. 1 root root 11 Jan 5 18:46 ttyUSB_Edgeport416_436102 -> ../ttyUSB30
lrwxrwxrwx. 1 root root 11 Jan 5 18:46 ttyUSB_Edgeport416_436103 -> ../ttyUSB31
lrwxrwxrwx. 1 root root 11 Jan 5 18:46 ttyUSB_Edgeport416_436104 -> ../ttyUSB32
lrwxrwxrwx. 1 root root 11 Jan 5 18:46 ttyUSB_Edgeport416_436105 -> ../ttyUSB33
lrwxrwxrwx. 1 root root 11 Jan 5 18:46 ttyUSB_Edgeport416_436106 -> ../ttyUSB34
lrwxrwxrwx. 1 root root 11 Jan 5 18:46 ttyUSB_Edgeport416_436107 -> ../ttyUSB35
lrwxrwxrwx. 1 root root 11 Jan 5 18:46 ttyUSB_Edgeport4_4341100 -> ../ttyUSB38
lrwxrwxrwx. 1 root root 11 Jan 5 18:46 ttyUSB_Edgeport4_4341101 -> ../ttyUSB39
lrwxrwxrwx. 1 root root 11 Jan 5 18:46 ttyUSB_Edgeport4_4342100 -> ../ttyUSB36
lrwxrwxrwx. 1 root root 11 Jan 5 18:46 ttyUSB_Edgeport4_4342101 -> ../ttyUSB37
lrwxrwxrwx. 1 root root 10 Jan 5 18:46 ttyUSB_Edgeport8_421100 -> ../ttyUSB2
lrwxrwxrwx. 1 root root 10 Jan 5 18:46 ttyUSB_Edgeport8_421101 -> ../ttyUSB3
lrwxrwxrwx. 1 root root 10 Jan 5 18:46 ttyUSB_Edgeport8_422100 -> ../ttyUSB4
lrwxrwxrwx. 1 root root 10 Jan 5 18:46 ttyUSB_Edgeport8_422101 -> ../ttyUSB5
lrwxrwxrwx. 1 root root 11 Jan 5 18:46 ttyUSB_Edgeport8_423100 -> ../ttyUSB18
lrwxrwxrwx. 1 root root 11 Jan 5 18:46 ttyUSB_Edgeport8_423101 -> ../ttyUSB19
lrwxrwxrwx. 1 root root 10 Jan 5 18:46 ttyUSB_Edgeport8_424100 -> ../ttyUSB0
lrwxrwxrwx. 1 root root 10 Jan 5 18:46 ttyUSB_Edgeport8_424101 -> ../ttyUSB1
lrwxrwxrwx. 1 root root 10 Jan 5 18:46 ttyUSB_Keyspan_USA-49WG_431100 -> ../ttyUSB6
lrwxrwxrwx. 1 root root 10 Jan 5 18:46 ttyUSB_Keyspan_USA-49WG_431101 -> ../ttyUSB7
lrwxrwxrwx. 1 root root 10 Jan 5 18:46 ttyUSB_Keyspan_USA-49WG_431102 -> ../ttyUSB8
lrwxrwxrwx. 1 root root 10 Jan 5 18:46 ttyUSB_Keyspan_USA-49WG_431103 -> ../ttyUSB9
lrwxrwxrwx. 1 root root 11 Jan 5 18:46 ttyUSB_Keyspan_USA-49WG_432100 -> ../ttyUSB10
lrwxrwxrwx. 1 root root 11 Jan 5 18:46 ttyUSB_Keyspan_USA-49WG_432101 -> ../ttyUSB11
lrwxrwxrwx. 1 root root 11 Jan 5 18:46 ttyUSB_Keyspan_USA-49WG_432102 -> ../ttyUSB12
lrwxrwxrwx. 1 root root 11 Jan 5 18:46 ttyUSB_Keyspan_USA-49WG_432103 -> ../ttyUSB13
lrwxrwxrwx. 1 root root 11 Jan 5 18:46 ttyUSB_Keyspan_USA-49WG_433100 -> ../ttyUSB14
lrwxrwxrwx. 1 root root 11 Jan 5 18:46 ttyUSB_Keyspan_USA-49WG_433101 -> ../ttyUSB15
lrwxrwxrwx. 1 root root 11 Jan 5 18:46 ttyUSB_Keyspan_USA-49WG_433102 -> ../ttyUSB16
lrwxrwxrwx. 1 root root 11 Jan 5 18:46 ttyUSB_Keyspan_USA-49WG_433103 -> ../ttyUSB17