A few years ago I had to solve the following problem. Several similar USB devices are connected to the host running FreeBSD. Host software works with them through character device files. It is clear that when randomly switching USB laces or when restarting a host, the character device files are numbered (in general) not in the same order as when they were first connected. In my case, USB devices are interface converters on which RS-485 buses with devices hang. There are no opportunities to automatically determine from the devices in the tire which tires are hung on which port there is not. Thus, it is not clear which character device files to which physical devices correspond at the moment. Who is interested in the decision, please under the cat. Despite the specificity of the task, the method is universal.
Idea. When connecting a USB device, determine the file name of the character device that was issued by the system (type ttyUx), manufacturer, type, s / n device and create a link in / dev with a predefined name for this s / n pointing to the already known ttyUx. So Our software will always work with well-known character device file names — predefined links that correspond to a specific device.
Implementation.')
In order to find out more about the USB device:
usbconfig dump_device_desc ... ugen1.2: <USB-Serial Controller Prolific Technology Inc.> at usbus1, cfg=0 md=HOST spd=FULL (12Mbps) pwr=ON bLength = 0x0012 bDescriptorType = 0x0001 bcdUSB = 0x0110 bDeviceClass = 0x0000 bDeviceSubClass = 0x0000 bDeviceProtocol = 0x0000 bMaxPacketSize0 = 0x0040 idVendor = 0x067b idProduct = 0x2303 bcdDevice = 0xa7d4 iManufacturer = 0x0001 <Prolific Technology Inc.> iProduct = 0x0002 <USB-Serial Controller> iSerialNumber = 0x0003 <0000A7D4> bNumConfigurations = 0x0001 ...
Editing /etc/devd.conf. We write something like:
I think the meaning of this record is clear. It remains to “draw” uplcom2ttyU, which will create that very single link, in the example - / dev / icpcon1. For each device, you need to make a corresponding entry in devd.conf. Do not forget to change the name of the link (I have / dev / icpcon1) in two places: attach, detach - we want the link to disappear with the device disconnected.
cat /usr/local/bin/uplcom2ttyU
It can be seen that the uplcom entry is changed to ttyU, since in / dev the system creates exactly ttyUx, where x is the same as the uplcom number.
That's all. However, until now, a holistic description of the solution to a similar problem is not found on the Internet. Is it only my posts on the forum of one well-known resource.