简体   繁体   English

QSerialPortInfo::serialNumber() 总是返回一个空字符串

[英]QSerialPortInfo::serialNumber() always returns an empty string

QSerialPortInfo::serialNumber() always returns an empty string, which happens when it's unavailable. QSerialPortInfo::serialNumber()总是返回一个空字符串,当它不可用时会发生这种情况。
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.我尝试连接不同的端口,一切似乎都很好,但是无论我做什么,它都没有显示端口的序列号,端口名称,制造商,产品ID。 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:我猜这个错误是在代码之外的某个地方,但这是我用来访问serialNumber()的插槽:

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();
}

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.如果您查看相关的源代码parseDeviceSerialNumber() ,您会看到一些奇特的逻辑,其中 Qt 试图将序列号与某些设备标识字符串隔离开来。 That's the string you are likely also seeing in the Windows device manager way down in the details.这就是您可能在 Windows 设备管理器中详细看到的字符串。

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.您似乎有一个串行端口没有以 Qt 可以理解的格式提供其标识符。 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.您可以尝试为 Qt 提供补丁以使其识别您的串行端口,或者您可以 go 并购买 Qt 可以识别的串行端口。 One chipset that is explicitly mentioned in the source code is FTDI .源代码中明确提到的一种芯片组是FTDI

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM