Good Morning,
i'm new in RS232 Programming.
I need to read data from a serial RS232 hardware.
The hardware can send 2 types of messages with a variable size
the first is 20 bytes (binary notation)
the other is 15 bytes. (binary notation)
Every message has LF in the last byte.
What is the best way to read theese data and reconstruct the messages ?
Is there any example showing how to read from a serial a variable number of bytes ?
i see :
QByteArray inByteArray = serial->readAll();
but in these way i dont' know how many bytes are read...and how to find the LF character to build the message to decode.
I think the readAll can also contains pieces of two messages...
Thanks in advance
to init the serial i use :
void MainWindow::initSerialPort()
{
serial->setPort("COM1");
if (serial->open(QIODevice::ReadWrite))
{
serial->setRate(SerialPort::Rate19200);
serial->setDataBits(SerialPort:ata8);
serial->setParity(SerialPort::NoParity);
serial->setStopBits(SerialPort::OneStop);
serial->setFlowControl(SerialPort::NoFlowControl);
}
else {
serial->close();
QMessageBox::critical(this, tr("Error"),
tr("Can't configure the serial port: %1,\n"
"error code: %2")
.arg("COM1").arg(serial->error()));
ui->statusBar->showMessage(tr("Open error"));
}
}
Bookmarks