Connection error above com10

problem phenomenon

The first is the QT program, QSerialPort for the serial port, this error is reported when connecting to com17, but when connecting to serial port numbers such as com4 and com5, no error is reported:
insert image description here

It is very strange, as long as it is com1...com9, it is fine, but if it is changed to com10, com11 in the device manager, an error will be reported.
There is still this kind of problem.
After checking the information, I found this kind of problem:
when the port number of the COM port is higher than 9, that is to say, from COM10 onwards, the assignment of serialPortName cannot be the same as COM1~~COM9, and COM in C++ is greater than 9. , you need to add \.\COM in front of COM.
For example,
serialPortName = "COM1"; //This is no problem, until COM9 is no problem.
serialPortName = "COM10"; //But it is wrong to write the ports after COM10 like this. The following is the correct spelling.
serialPortName = "\\.\COM10"; //From COM10 onwards, you need to add some modifiers \.\COM before COM. In the string \need escape character \ means a \

QString portName = "";
portName.append("\\\\.\\").append("COM18");
pSerialCOM = new Win_QextSerialPort(portName, ...);

problem analysis

Simply put:
com1...com9 can be used directly. If you add \.\, the serial port connection will prompt a connection error
com10, com11..., add \., if you do not add it, the serial port connection will report an error

Guess you like

Origin blog.csdn.net/maokexu123/article/details/130089216