ui->setupUi(this);
QVector<double> data_x(101), data_y(101);
timer.start();
init_port();
init_line_plot();
x_position = 0;
}
graphwidget::~graphwidget()
{
delete ui;
}
void graphwidget::init_port()
{
connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(receive()));
process->start("./test2");
process->waitForStarted();
qDebug()<<"process error code:" <<process->error();
}
void graphwidget::init_line_plot()
{
ui->customPlot->addGraph();
// ui->customPlot->setMinimumSize(500,500);
ui->customPlot->xAxis->setLabel("t");
ui->customPlot->yAxis->setLabel("V");
ui->customPlot->axisRect()->setAutoMargins(QCP::msNone);
ui->customPlot->axisRect()->setMargins(QMargins(0,0,0,0));
}
void graphwidget::receive()
{
// recieves data as ASCII string
int datalength = 1000;
char data [1000];
int bytesRead =process->readLine(data, datalength);
data[bytesRead]='\0';
ui
->textEdit
->append
(QString(data
));
out << data << endl;
addDataPoint(atof(data));
}
void graphwidget::addDataPoint(double datapoint)
{
if (x_position>60)data_x.pop_front();
double ms = timer.elapsed();
data_x.push_back((double)ms/1000);
x_position++;
if (x_position>60) data_y.pop_front();
data_y.push_back(datapoint);
ui->customPlot->graph(0)->setData(data_x,data_y);
ui->customPlot->xAxis->grid()->setSubGridVisible(false);
ui->customPlot->yAxis->grid()->setSubGridVisible(false);
ui->customPlot->xAxis->grid()->setVisible(false);
ui->customPlot->yAxis->grid()->setVisible(false);
ui
->customPlot
->graph
(0)->setPen
(QPen(QColor(0,
200,
0)));
ui->customPlot->setBackground(Qt::black);
ui->customPlot->graph(0)->rescaleAxes();
ui->customPlot->replot();
}
ui->setupUi(this);
QVector<double> data_x(101), data_y(101);
timer.start();
init_port();
init_line_plot();
x_position = 0;
}
graphwidget::~graphwidget()
{
delete ui;
}
void graphwidget::init_port()
{
process = new QProcess(this);
connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(receive()));
process->start("./test2");
process->waitForStarted();
qDebug()<<"process error code:" <<process->error();
}
void graphwidget::init_line_plot()
{
ui->customPlot->addGraph();
// ui->customPlot->setMinimumSize(500,500);
ui->customPlot->xAxis->setLabel("t");
ui->customPlot->yAxis->setLabel("V");
ui->customPlot->axisRect()->setAutoMargins(QCP::msNone);
ui->customPlot->axisRect()->setMargins(QMargins(0,0,0,0));
}
void graphwidget::receive()
{
// recieves data as ASCII string
int datalength = 1000;
char data [1000];
int bytesRead =process->readLine(data, datalength);
data[bytesRead]='\0';
ui->textEdit->append(QString(data));
QTextStream out(stdout);
out << data << endl;
addDataPoint(atof(data));
}
void graphwidget::addDataPoint(double datapoint)
{
if (x_position>60)data_x.pop_front();
double ms = timer.elapsed();
data_x.push_back((double)ms/1000);
x_position++;
if (x_position>60) data_y.pop_front();
data_y.push_back(datapoint);
ui->customPlot->graph(0)->setData(data_x,data_y);
ui->customPlot->xAxis->grid()->setSubGridVisible(false);
ui->customPlot->yAxis->grid()->setSubGridVisible(false);
ui->customPlot->xAxis->grid()->setVisible(false);
ui->customPlot->yAxis->grid()->setVisible(false);
ui->customPlot->graph(0)->setPen(QPen(QColor(0,200,0)));
ui->customPlot->setBackground(Qt::black);
ui->customPlot->graph(0)->rescaleAxes();
ui->customPlot->replot();
}
To copy to clipboard, switch view to plain text mode
Bookmarks