我正在使用 Ubuntu 17.10 和 tty-to-USB 适配器(将来会添加更多),因此打算为该适配器创建一个唯一的 udev 标识符。
我做到了系统盘:
Bus 007 Device 002: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
udevadm 信息 -a -n /dev/ttyUSB0 | grep '{serial}' | head -n1导致
ATTRS{serial}=="**0000:00:16.0**"
因此我这样做了sudo vi /etc/udev/rules.d/99-usb-serial.rules
SUBSYSTEM=="tty", ATTRS{idVendor}=="067b", ATTRS{idProduct}=="2303", ATTRS{serial}=="0000:00:16.0", SYMLINK+="ttyUSBComfoAir"
之后sudo udevadm 控制 --reload-rules && sudo udevadm 触发器我期望一些 /dev/ttyUSB....,但是ll /dev/ttyUSB*导致
crw-rw---- 1 root dialout 188, 0 Nov 20 18:04 /dev/ttyUSB0
仅当我省略ATTRS{序列号}有用.....
有什么想法吗??——因为添加更多这些适配器将需要序列号来区分适配器......
你好!由于我不太清楚相关部分是什么:我正在添加完整的输出......
looking at device '/devices/pci0000:00/0000:00:16.0/usb7/7-1/7-1:1.0/ttyUSB0/tty/ttyUSB0':
KERNEL=="ttyUSB0"
SUBSYSTEM=="tty"
DRIVER==""
looking at parent device '/devices/pci0000:00/0000:00:16.0/usb7/7-1/7-1:1.0/ttyUSB0':
KERNELS=="ttyUSB0"
SUBSYSTEMS=="usb-serial"
DRIVERS=="pl2303"
ATTRS{port_number}=="0"
looking at parent device '/devices/pci0000:00/0000:00:16.0/usb7/7-1/7-1:1.0':
KERNELS=="7-1:1.0"
SUBSYSTEMS=="usb"
DRIVERS=="pl2303"
ATTRS{authorized}=="1"
ATTRS{bAlternateSetting}==" 0"
ATTRS{bInterfaceClass}=="ff"
ATTRS{bInterfaceNumber}=="00"
ATTRS{bInterfaceProtocol}=="00"
ATTRS{bInterfaceSubClass}=="00"
ATTRS{bNumEndpoints}=="03"
ATTRS{supports_autosuspend}=="1"
looking at parent device '/devices/pci0000:00/0000:00:16.0/usb7/7-1':
KERNELS=="7-1"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{authorized}=="1"
ATTRS{avoid_reset_quirk}=="0"
ATTRS{bConfigurationValue}=="1"
ATTRS{bDeviceClass}=="00"
ATTRS{bDeviceProtocol}=="00"
ATTRS{bDeviceSubClass}=="00"
ATTRS{bMaxPacketSize0}=="64"
ATTRS{bMaxPower}=="100mA"
ATTRS{bNumConfigurations}=="1"
ATTRS{bNumInterfaces}==" 1"
ATTRS{bcdDevice}=="0400"
ATTRS{bmAttributes}=="80"
ATTRS{busnum}=="7"
ATTRS{configuration}==""
ATTRS{devnum}=="2"
ATTRS{devpath}=="1"
ATTRS{idProduct}=="2303"
ATTRS{idVendor}=="067b"
ATTRS{ltm_capable}=="no"
ATTRS{manufacturer}=="Prolific Technology Inc. "
ATTRS{maxchild}=="0"
ATTRS{product}=="USB-Serial Controller D"
ATTRS{quirks}=="0x0"
ATTRS{removable}=="unknown"
ATTRS{speed}=="12"
ATTRS{urbnum}=="258959"
ATTRS{version}==" 1.10"
looking at parent device '/devices/pci0000:00/0000:00:16.0/usb7':
KERNELS=="usb7"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{authorized}=="1"
ATTRS{authorized_default}=="1"
ATTRS{avoid_reset_quirk}=="0"
ATTRS{bConfigurationValue}=="1"
ATTRS{bDeviceClass}=="09"
ATTRS{bDeviceProtocol}=="00"
ATTRS{bDeviceSubClass}=="00"
ATTRS{bMaxPacketSize0}=="64"
ATTRS{bMaxPower}=="0mA"
ATTRS{bNumConfigurations}=="1"
ATTRS{bNumInterfaces}==" 1"
ATTRS{bcdDevice}=="0413"
ATTRS{bmAttributes}=="e0"
ATTRS{busnum}=="7"
ATTRS{configuration}==""
ATTRS{devnum}=="1"
ATTRS{devpath}=="0"
ATTRS{idProduct}=="0001"
ATTRS{idVendor}=="1d6b"
ATTRS{interface_authorized_default}=="1"
ATTRS{ltm_capable}=="no"
ATTRS{manufacturer}=="Linux 4.13.0-16-generic ohci_hcd"
ATTRS{maxchild}=="4"
ATTRS{product}=="OHCI PCI host controller"
ATTRS{quirks}=="0x0"
ATTRS{removable}=="unknown"
ATTRS{serial}=="0000:00:16.0"
ATTRS{speed}=="12"
ATTRS{urbnum}=="36"
ATTRS{version}==" 1.10"
looking at parent device '/devices/pci0000:00/0000:00:16.0':
KERNELS=="0000:00:16.0"
SUBSYSTEMS=="pci"
DRIVERS=="ohci-pci"
ATTRS{broken_parity_status}=="0"
ATTRS{class}=="0x0c0310"
ATTRS{consistent_dma_mask_bits}=="32"
ATTRS{d3cold_allowed}=="0"
ATTRS{device}=="0x4397"
ATTRS{dma_mask_bits}=="32"
ATTRS{driver_override}=="(null)"
ATTRS{enable}=="1"
ATTRS{irq}=="18"
ATTRS{local_cpulist}=="0-1"
ATTRS{local_cpus}=="3"
ATTRS{msi_bus}=="1"
ATTRS{numa_node}=="-1"
ATTRS{revision}=="0x00"
ATTRS{subsystem_device}=="0x8496"
ATTRS{subsystem_vendor}=="0x1043"
ATTRS{vendor}=="0x1002"
looking at parent device '/devices/pci0000:00':
KERNELS=="pci0000:00"
SUBSYSTEMS==""
DRIVERS==""
答案1
据我所知,你只能将一个特定孩子的信息与父母的信息结合起来。在你的行中
SUBSYSTEM=="tty", ATTRS{idVendor}=="067b", ATTRS{idProduct}=="2303", ATTRS{serial}=="0000:00:16.0", SYMLINK+="ttyUSBComfoAir"
你结合这个孩子的信息
looking at parent device '/devices/pci0000:00/0000:00:16.0/usb7/7-1':
还有这个孩子
looking at parent device '/devices/pci0000:00/0000:00:16.0/usb7':`
如果您看前者,则没有包含 ATTRS(serial),如果您看后者,则没有包含 ATTRS(idVendor/idProduct)。
答案2
Udev 规则不支持来自多个父节点的混合条件。
- 叶/目标节点:
SUBSYSTEM=="tty"
- 父节点:
ATTRS{idVendor}=="067b", ATTRS{idProduct}=="2303"
- 另一个父节点:
ATTRS{serial}=="0000:00:16.0"
- 叶/目标节点:
这是许多没有串行的 rs232 适配器的已知问题。通常,用户为特定适配器选择固定的 USB 端口,并为该特定端口设置 udev 规则。
其他选项,一些 PL2303 芯片可以使用自定义序列甚至 vid/pid 进行重新编程。工具是免费提供的,但它需要一个适配器,为芯片提供 6.5v 的编程电压(正常模式为 5v)。