1

on my embedded machine two USB devices are mounted on a similar /dev file: /dev/ttyACMx. A device is a POS device; the other one is a printer.

I don't know which device will be ttyACM0 or ttyACM1: my guess is that I cannot suppose a particular order.

So, once detected the presence of ttyACM0 and ttyACM1, how can I know which USB device is tied to tty* file?

I checked with lsusb and usb-device but I'm not able to connect the information.

Thanks

1 Answer 1

3

As root, the outputs of udevadm info -q all -a -n /dev/ttyACM0 will output all properties that can be used to identify the /dev/ttyACM0 device. Also try omitting the -a option to see the environment variables that may be generated by existing udev rules, in case those rules do some sort of active probing of the device.

If there is a difference with the outputs for /dev/ttyACM0 and /dev/ttyACM1, then that difference can probably be used to identify which is which.

Note that /dev/ttyACM* may indicate that these devices are originally RS-232 serial devices with just a generic USB-to-serial converter chip added to make them compatible with USB. If so, the amount of available information depends on exactly how the converter chip has been configured to present the device to the USB bus. In the best case, there might be an attribute that identifies the type of each device, and there might already be an auto-generated alias at /dev/serial/by-id/*

Worst case, there might be nothing unique (not even a serial number) on the converter chip, and you might have to implement some kind of udev rule that does active probing, by sending some identification request to the device and checking the resulting answer, or dedicate a particular USB port for each type of device and identify them by the sysfs path of the USB port. In this case, check /dev/serial/by-path/*: there might already be an auto-generated device alias that you could use.

Once you find a property or a probe result that can be used to tell the devices apart, you can then set up an udev rule that will assign a type-specific alias to the respective /dev/ttyACM* device, e.g. /dev/POS for the POS device, and /dev/receipt or something appropriate for the printer. Those will be symbolic links pointing to the actual device names, but your applications will be able to use them just like the real devices.

1
  • Thanks a lot! I wrote a udev rule: fantastic!!
    – SteMMo
    Commented May 7, 2021 at 12:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .