如何区分相同的USB转串口转换器? [英] How to distinguish identical USB-to-serial converter?

查看:75
本文介绍了如何区分相同的USB转串口转换器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 2 根相同的 USB 转串口适配器电缆(非常像

如何更改某些设置的字段以使两个适配器在 Python 上都可区分?例如,可以编写我自己的 serial_number 吗?

解决方案

如果这总是针对特定的串行设备,通常的方法是使用 udev 程序在/dev 中为您创建符号链接.如何执行此操作有很多不同的选项,或者基于它插入的物理端口,或者基于设备的属性(例如序列号).

基于 FTDI 的设备都有一个与它们相关联的序列号,但由于您的设备是 Prolific,它们没有序列号,因此这变得有点困难.但是,由于我们可以使用 udev 根据插入的位置创建符号链接,因此应该可以使用以下内容(将其放在 udev 看到的文件中,例如/etc/udev/rules.d/80-my-converter.规则):

SUBSYSTEM=="usb", KERNELS=="2-1.8.3", SYMLINK+="device_1"子系统=="usb", 内核=="2-1.8.1.3", SYMLINK+="device_2"

KERNELS 参数必须根据您将串行设备插入的确切位置而更改,并且将特定于您的系统.您可以通过运行以下命令来获取设备上的 udev 参数列表:

udevadm info -a -n/dev/ttyUSB2

此页面有关于编写 udev 规则的更多信息.

I have 2 identical USB-to-serial adapter cables (pretty much like this one) to connect a desktop PC under Ubuntu and some RS232 devices.

I develop a python software to pilot these devices.

I need to find a way to identify which one of the 2 adapters I am connected to.

I know about python's serial.tools.list_ports.comports() function, but all the settings are the exact same for both adapters (see capture below). Except the device, but it may change depending on the plugging order.

How can I change some settings' field to make both adapter pythonically distinguishable? Is it possible to write my own serial_number for example?

解决方案

If this is always for a specific serial device, the normal way to do this is to use the udev program to create symlinks for you in /dev. There's a lot of different options for how to do this, either based on what physical port it's plugged into or based off of attributes of the device(e.g. serial number).

FTDI based devices all have a serial number associated with them, but since yours is a Prolific they don't have a serial number, so this becomes a bit harder. However, since we can use udev to create a symlink based on where it is plugged in, something like the following should work(put this in a file seen by udev, e.g. /etc/udev/rules.d/80-my-converter.rules):

SUBSYSTEM=="usb", KERNELS=="2-1.8.3", SYMLINK+="device_1"
SUBSYSTEM=="usb", KERNELS=="2-1.8.1.3", SYMLINK+="device_2"

The KERNELS parameter will have to change depending on where exactly you plug the serial device into and will be specific to your system. You can get a list of the udev parameters on your device by running the following:

udevadm info -a -n /dev/ttyUSB2

This page has more information on writing udev rules.

这篇关于如何区分相同的USB转串口转换器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆