Linux:如何强制 USB 设备使用相同的 ttyUSB 编号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7986034/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 06:58:31  来源:igfitidea点击:

Linux: how to force a USB device to use the same ttyUSB number

linuxubuntuserial-portusb

提问by Johny

I have an USB modem that I use on Ubuntu. I have also a program which communicate with this device using its ttyUSBxxnumber.

我有一个在 Ubuntu 上使用的 USB 调制解调器。我还有一个程序可以使用它的ttyUSBxx号码与这个设备进行通信。

My problem is that every time I unplug/plug the device again, or when I reboot my PC, the device gets a new ttyUSBnumber, for example: ttyUSB0or ttyUSB1.

我的问题是,每次我再次拔出/插入设备时,或者当我重新启动 PC 时,设备都会获得一个新ttyUSB号码,例如:ttyUSB0ttyUSB1

How can I force this device to always use the same number (say: ttyUSB0)?

如何强制此设备始终使用相同的号码(例如:)ttyUSB0

回答by laher

udevis Linux's dynamic device manager. udevpersists information about devices you plug in, and you can modify this information so that it adds a specific 'symlink' in the directory for this device.

udev是 Linux 的动态设备管理器。udev保留有关您插入的设备的信息,您可以修改此信息,以便在此设备的目录中添加特定的“符号链接”。

Now, your usb modem's definition should be inside the folder /etc/udev/rules.d/, and the filename will be something like 50-udev.rules. The file contains one line per device, (you can use a number of tools to help identify the correct line. See below link on using udevinfo)

现在,您的 USB 调制解调器的定义应该在文件夹内/etc/udev/rules.d/,文件名将类似于50-udev.rules. 该文件每个设备包含一行,(您可以使用多种工具来帮助识别正确的行。请参阅以下有关使用的链接udevinfo

Now, you can edit the relevant line, or even better, create another file and copy the relevant line into it. The filename should start with a lower number (e.g. 49-my-modem.rules), so that it gets loaded first. You need to add the following to the end of the line:

现在,您可以编辑相关行,或者更好的是,创建另一个文件并将相关行复制到其中。文件名应以较小的数字开头(例如49-my-modem.rules),以便首先加载。您需要将以下内容添加到行尾:

, SYMLINK="ttyUSBmodem"

Now, your device should come up as /dev/ttyUSBmodem(aswell as the dynamically assinged /dev/ttyUSB[0-9])

现在,您的设备应该出现/dev/ttyUSBmodem(以及动态分配的 /dev/ttyUSB[0-9])

For more help with identifying the correct line and the whole process, see here: http://noctis.de/archives/16-HowTo-fixed-name-for-a-udev-device.html

有关识别正确行和整个过程的更多帮助,请参见此处:http: //noctis.de/archives/16-HowTo-fixed-name-for-a-udev-device.html

HTH

HTH