QSerialPortInfo::serialNumber() always returns an empty string, which happens when it's unavailable.
I tried connecting different ports, everything seems allright, but it doesn't show a Serial Number of a port no matter what I do!
Port name, manufacturer, product ID, however, can be correctly outputted.
I didn't connect any devices to the ports, however.
Why can serial number be unavailable? Can this be fixed somehow?
I guess the mistake is somewhere outside code, but here is a slot that I use to access serialNumber() in :
void PortBrowser::onPortChange()
{
int i;
if(comsCombo->currentIndex()>-1)
i =comsCombo->currentIndex();
else
i = 0;
QSerialPort currPort(comsList[i]);
bool opened = currPort.open(QIODevice::ReadOnly);
const QString seriNum = comsList[i].serialNumber();
serNum->setText(seriNum);
manufact->setText(comsList[i].manufacturer());
QTextStream out(stdout);
out<<comsList[i].serialNumber();
currPort.close();
}
CodePudding user response:
If you take a look at the relevant source code parseDeviceSerialNumber() you will see quite some fancy logic where Qt tries to isolate a serial number from some device-identification string. That's the string you are likely also seeing in the Windows device manager way down in the details.
Why can serial number be unavailable? Can this be fixed somehow?
You seem to have a serial port that does not provide its identifier in a format Qt would understand. You could try to come up with a patch for Qt to make it recognize your serial port or you might go and buy a serial port that Qt does recognize. One chipset that is explicitly mentioned in the source code is FTDI.