I'm making a program that reads a stream of data coming from a serial RN42 bluetooth connection at 250 samples per second (115200 baud). When running the code, I've noticed that some of the data were being dropped not and read, thus getting out of sync.
SerialMonitor::SerialMonitor(QObject *parent) :
QObject(parent)
{
// Initialization here
DAQ = new QSerialPort(this);
DAQ->setPortName("/dev/tty.BIOEXG-SPP");
DAQ->setBaudRate(QSerialPort::Baud115200);
DAQ->setDataBits(QSerialPort::Data8);
DAQ->setParity(QSerialPort::NoParity);
DAQ->setStopBits(QSerialPort::OneStop);
DAQ->setFlowControl(QSerialPort::NoFlowControl);
if (DAQ->open(QIODevice::ReadOnly)) printf("Success!\n");
else printf("FAILED...\n");
connect(DAQ, SIGNAL(readyRead()), this, SLOT(WriteToText()));
}
void SerialMonitor::WriteToText()
{
while (DAQ->canReadLine()) {
QString IncomingData = DAQ->readLine();
// More processing here
}
}
}
Is there a problem with my code? If not, is there a way around this problem? This is an EEG device thus every single data point is crucial.
Thanks in advance!
You have disabled all error check and sync mechanism:
If you have control of microcontroller on devices a good choice is implementing a chk mechanism for recover de lost data. If your devices is a black box you must use the HW mechanism for improve stability. When a wireless communication is used the possibility of lost some data exist and was considered on the project.
Note: You should set-up the serial parameter after the opening not before.