Thank you! I have one last error, when I try to call the function that reads serial data, from mainwindow.cpp, and it says : C2664: ' QByteArray:: (QByteArrayDataPtr)': cannot convert argument 1 from 'QByteRef' to 'const char*'. No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called.
The method from serialportreader.cpp is:
{
int sz = data.size();
for(int i=0;i<sz;i++)
if((int)data[i] != 13 && (int)data[i] != 10)
return (data[i]);
}
QByteArray SerialPortReader::_read_callback()
{
QByteArray data = _serial->readAll();
int sz = data.size();
for(int i=0;i<sz;i++)
if((int)data[i] != 13 && (int)data[i] != 10)
return (data[i]);
}
To copy to clipboard, switch view to plain text mode
And in mainwindow.cpp I have the following function that calls the above :
void MainWindow::realtimeDataSlot()
{
double key
= QDateTime::currentDateTime().
toMSecsSinceEpoch()/1000.0;
static double lastPointKey = 0;
if (key-lastPointKey > 0.01)
{
SerialPortReader value;
ui->customPlot->graph(0)->addData(key, value0);
ui->customPlot->graph(1)->clearData();
ui->customPlot->graph(1)->addData(key, value0);
ui->customPlot->graph(0)->rescaleValueAxis();
lastPointKey = key;
}
ui->customPlot->xAxis->setRange(key+0.25, 8, Qt::AlignRight);
ui->customPlot->replot();
}
void MainWindow::realtimeDataSlot()
{
double key = QDateTime::currentDateTime().toMSecsSinceEpoch()/1000.0;
static double lastPointKey = 0;
if (key-lastPointKey > 0.01)
{
SerialPortReader value;
QByteArray value0=value._read_callback();
ui->customPlot->graph(0)->addData(key, value0);
ui->customPlot->graph(1)->clearData();
ui->customPlot->graph(1)->addData(key, value0);
ui->customPlot->graph(0)->rescaleValueAxis();
lastPointKey = key;
}
ui->customPlot->xAxis->setRange(key+0.25, 8, Qt::AlignRight);
ui->customPlot->replot();
}
To copy to clipboard, switch view to plain text mode
Bookmarks