How to detect individual USB-RS232 device tty number?
Posted: Sun Apr 26, 2020 9:46 pm
I am planning a conversion from Windows to Raspbian of a software control program.
It uses two serial ports to handle external equipment and I was planning to use a pair of USB-RS232 converters.
The two channels have completely different use and are connected to different boxes.
Now when looking at converting the Windows code from using ports like COM1, COM2 etc into using /dev/ttyS1, /dev/ttyS2 etc I noticed two problems:
1) The base name of serial ports is not consistent.
It looks like various Linux versions uses different names:
- On Raspbian Buster it looks like /dev/ttyN where N is a number.
- On Ubuntu 18.04 it looks like /dev/ttySN where N is a number
If I attach USB to Serial converter cables I get on both Raspbian and Ubuntu:
/dev/ttyUSB0, /dev/ttyUSB1 etc
2) The number for the USB device varies.
What happens is that the first detected converter cable gets /dev/USB0, the second /dev/USB1 etc
So depending on how they are detected by the operating system they get different port numbers.
QUESTION:
How is this normally handled in Linux software configuration-wise?
With the USB connections it is very important to know which is which, preferably by use the actual USB port it is connected to.
Is there some way to know which of ttyUSB0 and ttyUSB1 is connected to a specific USB port?
lsusb does not display any such information...
On Raspbian I get this:
And on Ubuntu 18 this:
So it is exactly the same and no info available to differentiate between the two.
If I unplug both and then plug the one that is ttyUSB1 it becomes ttyUSB0
My software is configured via ini file formatted configuration files on Windows and there the port numbers seem to stick.
Is there some serial number or the like that can be used to identify each USB cable uniquely?
It uses two serial ports to handle external equipment and I was planning to use a pair of USB-RS232 converters.
The two channels have completely different use and are connected to different boxes.
Now when looking at converting the Windows code from using ports like COM1, COM2 etc into using /dev/ttyS1, /dev/ttyS2 etc I noticed two problems:
1) The base name of serial ports is not consistent.
It looks like various Linux versions uses different names:
- On Raspbian Buster it looks like /dev/ttyN where N is a number.
- On Ubuntu 18.04 it looks like /dev/ttySN where N is a number
If I attach USB to Serial converter cables I get on both Raspbian and Ubuntu:
/dev/ttyUSB0, /dev/ttyUSB1 etc
2) The number for the USB device varies.
What happens is that the first detected converter cable gets /dev/USB0, the second /dev/USB1 etc
So depending on how they are detected by the operating system they get different port numbers.
QUESTION:
How is this normally handled in Linux software configuration-wise?
With the USB connections it is very important to know which is which, preferably by use the actual USB port it is connected to.
Is there some way to know which of ttyUSB0 and ttyUSB1 is connected to a specific USB port?
lsusb does not display any such information...
On Raspbian I get this:
Code: Select all
$ lsusb
Bus 001 Device 007: ID 0403:6001 Future Technology Devices International, Ltd FT232 Serial (UART) IC
Bus 001 Device 008: ID 0403:6001 Future Technology Devices International, Ltd FT232 Serial (UART) IC
Code: Select all
lsusb
Bus 002 Device 005: ID 0403:6001 Future Technology Devices International, Ltd FT232 USB-Serial (UART) IC
Bus 002 Device 004: ID 0403:6001 Future Technology Devices International, Ltd FT232 USB-Serial (UART) ICIf I unplug both and then plug the one that is ttyUSB1 it becomes ttyUSB0
My software is configured via ini file formatted configuration files on Windows and there the port numbers seem to stick.
Is there some serial number or the like that can be used to identify each USB cable uniquely?