Opening a serial terminal based on COM port selection from QComboBox
Hi,
OS - Windows 10
Qt version - Qt5
In my Qt GUI, I have a QComboBox for the COM port selection and "connect" push button. When I click on connect button, able to configure serial port properly and open() call is successful.
I am trying to build an serial port application between PC and a device.
But I am able to see a serial console terminal on clicking connect button. Can somebody help me out here!
Thanks in Advance,
Anita
Re: Opening a serial terminal based on COM port selection from QComboBox
Re: Opening a serial terminal based on COM port selection from QComboBox
Small correction, I am not able to open a new terminal on clicking connect push button for the COM port selected through combo box.
Re: Opening a serial terminal based on COM port selection from QComboBox
Why do you think that opening a serial port should create a complete terminal application?
I suggest you study Qt's Terminal example. If you use Qt Creator, it is one of the examples on the Examples part of the Welcome page.
Re: Opening a serial terminal based on COM port selection from QComboBox
Thanks, It was my understanding that just by configuring serial port and clicking a button would open a serial port.
Yes, I have already executed Terminal example while exploring documents. For now, I think not necessary to open a new terminal.
My serial interface frame format is, SOF | command | Len | Data | Checksum | EOF. I would like to extract my read data based on command types with variable Len. Which is the better way to store frame data, buffer or structure?
connect(serial, &QSerialPort::readyRead, this, &MainWindow::serialReadyRead);
void MainWindow::serialReadyRead()
{
QByteArray data = serial->readAll();
QString str = QString(data);
qDebug()<<"Received data : "<<data;
/* SOF | command | Len | Data | Checksum | EOF */
/* parsing serial frame data takes place here */
}
Where serialReadyRead() function, parses serial frame received data from another PC. Is there any correction required in the above implementation?
Best Regards,
Anita
Re: Opening a serial terminal based on COM port selection from QComboBox
Yes, the readyRead signal is generated after a few (one, several, different) bytes, not after a packet. Serial port knows nothing about your data structure. You have to build the package in the buffer yourself and start its analysis after receiving the EOF.
Re: Opening a serial terminal based on COM port selection from QComboBox
Thanks...
Just want to know, to build a package I am using QByteArray. But my Len and Checksum are of 2 bytes in size. How can I append 2 bytes to QByteArray?
Best Regards,
Anita
Re: Opening a serial terminal based on COM port selection from QComboBox
Quote:
How can I append 2 bytes to QByteArray?
QByteArray::append() sounds like it could be useful for appending to a QByteArray.