专业做网站的团队/竞价恶意点击器

一个简单的串口示例,并将数据予以图表化显示,让数据体现得更直观。

串口部分代码
- 查找可用串口列表
foreach(const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) {...
}
- 设置串口名
m_serialPort.setPortName(ui->PortBox->currentText());
- 设置波特率
m_serialPort.setBaudRate(ui->BaudBox->currentText().toInt());
- 设置数据位数
m_serialPort.setDataBits(QSerialPort::Data8);
- 设置奇偶校验
m_serialPort.setParity(QSerialPort::NoParity);
- 设置停止位
switch(ui->StopBox->currentIndex()) {case 1: m_serialPort.setStopBits(QSerialPort::OneStop); break;case 2: m_serialPort.setStopBits(QSerialPort::TwoStop); break;default: break;
}
- 设置流控制
m_serialPort.setFlowControl(QSerialPort::NoFlowControl);
- 打开串口
m_serialPort.open(QIODevice::ReadWrite);
图表代码部分
折线图基于qcustomplot库绘制。

- 向绘图区域添加一条曲线
ui->qCustomPlot->addGraph();
- 设置坐标轴标签名称
ui->qCustomPlot->xAxis->setLabel("次数");
ui->qCustomPlot->yAxis->setLabel("温度");
- 设置坐标轴显示范围
ui->qCustomPlot->xAxis->setRange(0, 10);
ui->qCustomPlot->yAxis->setRange(0, 100);
- 图表数据更新函数
void onUpdateChart()
{
...m_xs.append(m_xLength);m_ys.append(m_serialUpdateData);m_serialUpdateData = 0;ui->qCustomPlot->replot();ui->qCustomPlot->graph(0)->setData(m_xs, m_ys);m_xLength++;
}
关于更多
- 源码地址:https://github.com/aeagean/SerialPort
- 公众号回复"串口"即可获取串口相关的文章。