1

I have a device that acts as a serial port connected over USB. I have a class that interfaces with the device through a QSerialPort. Soon I will have multiple such devices and the program will need to reliably distinguish them to assign configured values to instances of the class.

Qt identifies serial devices by the portName field of the QSerialPortInfo helper object. This name is derived from the /dev/ path (e.g. /dev/tty.foo42 is port name "foo42") and this path does not remain associated with a particular device over reboots or deployment to a different machine. However, through libusb I can get a serial number, which is stable across reboots and different machines.

What I am still missing is a way to match the serial number, which can be identified in advance and recorded in a configuration file, to a port name, which can be used to open a QSerialPort. Currently deploying to MacOS, but in the future we may wish to deploy to Linux.

Searching existing questions mostly turns up ways to configure a Linux system to always assign a particular dev path to a particular device. A solution that involves configuring the operating system is acceptable, but something the application can do without that is preferable. A Mac specific solution is acceptable, but something that also works on Linux is preferable.

01d55
  • 1,872
  • 13
  • 22

1 Answers1

1

The documentation for QSerialPortInfo::serialNumber() (new in Qt 5.3) sounds like what you're after:

QString QSerialPortInfo::serialNumber() const

Returns the serial number string of the serial port, if available; otherwise returns an empty string.

Note: The serial number may include letters.

MrEricSir
  • 8,044
  • 4
  • 30
  • 35