Hello guys.
First time here, should not be the last, since I should work with Qt for a few times
I developed an app to obtain data from a serial port.
The current baudrate is 115200, and I wanted to improve it even more.
The thing is, that even at this rate it is really slow.
The buffer keeps storing data and increasing all the time, by using the function QSerialPort::readAll
I don't know if I am handling the data correctly, but here's a hint of my code:
This is the slot for the readyRead() signal from QSerialPort
this is the constructor of the main dialogvoid ADCStream::readData()
{
ADCData += ADCPort->readAll();
int dataBegin;
int dataEnd;
dataBegin = ADCData.indexOf('A',0);
dataEnd = ADCData.indexOf('Z',dataBegin);
if((dataBegin != -1) && (dataEnd != -1))
{
QByteArray tempData = ADCData.mid(dataBegin+1,2);
quint16 number=0;
number = (tempData.at(0) & 0x00FF)<<8;
number |= tempData.at(1) & 0x00FF;
emit dataReady(number);
ADCData.remove(0,dataEnd+1);//get next data
}
}
The slot showData simply displays the data in a QTextBrowser with this:ui->setupUi(this);
myStream = new ADCStream();//customized class, with a QSerialPort instance
streamThread = new QThread(this);
myStream->moveToThread(streamThread);
streamThread->setPriority();
streamThread->start();
myStream->open();
log = new QFile("Log",this);
if(!log->open(QIODevice::Append))
{
QMessageBox::warning(this,"Log File","Couldn't open file");
}
connect(myStream,SIGNAL(dataReady(quint16)),this,S LOT(showData(quint16)),Qt::QueuedConnection);
connect(myStream->ADCPort,SIGNAL(readyRead()),myStream,SLOT(readDat a()));
ui->textLogger->insertPlainText(QString(" %1\n").arg(whatever));
Can you tell me how can I improve this data handling from the serialPort?
I'm reading from a sensor, and when I change the sensor, it takes a REALLY long time to update in the GUI
Thanks in advance
Bookmarks