0

I have a device that I want to be able to communicate with serially. On Linux, I can see that when I plug in the device to my computer, I see that /dev/ttyUSB0 pops up, which I know to be the device; however, what I am not sure about is how would I go about finding out what port my device is connected to in the general sense? Say if I were to go to another machine and plug it in, or if I had multiple serial devices already plugged in to this computer; I wouldn't be able to rely on it always being /dev/ttyUSB0.

I plan on using PySerial to be communicate with the device (I couldn't find any other officially supported method with python to communicate with a serial device), and when you open a serial connection, you of course must specify the path to the device. On Windows it would be COM something, and Linux /dev/tty something. I want to be able to automatically find this out through the program. What is the best method to go about this?

Kalcifer
  • 1,211
  • 12
  • 18
  • You can list [available serial ports](https://stackoverflow.com/a/14224477/2280890) and then try to open each port and see if your device is connected. – import random Apr 12 '21 at 00:47
  • It depends on the characteristics of the device. The serial port is a communication function, not a device. The existence of a serial port does not mean that the device is connected. If a device always uses a USB serial conversion interface with a dedicated VID/PID and you can see it from your computer, you will be able to determine if it is connected or not. Except in those special cases, it is not possible to know if a device is connected to a serial port or what the device is until the actual communication. Or even if communication is possible, it may not be possible to identify it. – kunif Apr 12 '21 at 12:59

0 Answers0