Home > other >  Consult! Questions about QT serial port to accept data
Consult! Questions about QT serial port to accept data

Time:09-26

Added a pair of virtual serial port on the computer COM8 and COM9, send data on the serial assistants open COM8, COM9 can accept data and displayed,

Yourself to write a serial port in QSerialport on QT assistant, open the COM9 wants to read a serial port assistant COM8 send data, but can't read it out,

Is my understanding of a serial port is there a problem? Or am I code has a problem?
O great god answer!!

Code inside a serial port Settings are all right, after the open set and set have tried before the open, still no,
And a trigger readyRead functions cannot turn into the trough, times of trigger readyRead functions to read data is empty,

 
MainWindow: : MainWindow (QWidget * parent)
: QMainWindow (parent)
, the UI (new UI: : MainWindow)
{
The UI - & gt; SetupUi (this);

The connect (& amp; Mycom, & amp; QSerialPort: : readyRead, this, & amp; MainWindow: : readCOM);
}

 void MainWindow: : readCOM () 
{
QByteArray buff.=mycom readAll ();
QString receive_data=https://bbs.csdn.net/topics/QString (buff);
The UI - & gt; TextBrowser_1 - & gt; InsertPlainText (receive_data);
}




CodePudding user response:

The building Lord, serial port baud rate, parity bit and stop bit is how to set?

CodePudding user response:

reference 1st floor yishumei response:
the building Lord, serial port baud rate, parity bit and stop bit is how to set?


These Settings are all right, just tried, without readyread signal trigger slot function can be read, but this can only be read once:
 MainWindow: : MainWindow (QWidget * parent) 
: QMainWindow (parent)
, the UI (new UI: : MainWindow)
{
The UI - & gt; SetupUi (this);

The connect (UI - & gt; PushButton_1, SIGNAL (clicked ()), and this, SLOT (readCOM ()));
//connect (& amp; Mycom, & amp; QSerialPort: : readyRead, this, & amp; MainWindow: : readCOM);
}


To readyread read will not be able to trigger:
 
MainWindow: : MainWindow (QWidget * parent)
: QMainWindow (parent)
, the UI (new UI: : MainWindow)
{
The UI - & gt; SetupUi (this);

//connect (UI - & gt; PushButton_1, SIGNAL (clicked ()), and this, SLOT (readCOM ()));
The connect (& amp; Mycom, & amp; QSerialPort: : readyRead, this, & amp; MainWindow: : readCOM);
}


Void MainWindow: : readCOM ()
{
While (mycom. WaitForReadyRead (10)) {
QDebug () & lt; <" Enter into func "& lt; QString receive_data=https://bbs.csdn.net/topics/QString (mycom readAll ());
The UI - & gt; TextBrowser_1 - & gt; InsertPlainText (receive_data);
QDebug () & lt; }
}

  • Related