Home > Mobile >  QSerialPort problem in Qt
QSerialPort problem in Qt

Time:12-26

use QSerialPort and QTimer reading meter data, the
Use QTimer (10 ms) regularly sends commands to the serial port, serial port receiving instructions,
Send instructions, use the connect link timerout () and channel function,
Receiving instructions, use the connect link readyread () and channel function,
Using the connect, connect errorOccurred (QSerialPort: : SerialPortError) and channel function, receive abort, and abort code,

After opening a serial port, sending and receiving data is normal,

Question:
When I connect to the Internet, refresh the web page, a serial port error, error code 9 (QSerialPort: : ResourceError); After a serial port has been disconnected at this time, unable to send data,

Rule out possible mistakes:
1, eliminate the problem of instrument when refresh the web page, a serial port connection error, don't send the data directly, and use the serial program of VB to read the same data, connect to the Internet, refresh the page, not problems,
2, when a serial port open, don't time (10 ms) to send data, refresh the page, there will be no error code 9, a serial port without disconnected, after a serial port to send and receive data is normal,
3, put a serial port to send and receive data in the thread, won't appear the problem,

Now, I want to know what caused this problem, do not use the multithreading can solve? QSerialPort still need to pay attention to what problem?

CodePudding user response:

I again tested, the basic orientation to the timer time the question, if once every 1 ms, speaking, reading and writing data, refresh the page every time a serial port will disconnect, if the timer time to 50 ms, a lower risk of abnormal disconnect at this time,
  •  Tags:  
  • Qt
  • Related