当前位置: 首页> 教育> 幼教 > QT串口通讯上位机框架,带qcustomplot绘图(DLL集成)有需要的可以自用

QT串口通讯上位机框架,带qcustomplot绘图(DLL集成)有需要的可以自用

时间:2025/7/13 13:20:42来源:https://blog.csdn.net/watch361/article/details/141899488 浏览次数:0次

一个比较简单的qt串口上位机框架,提供给大家做二次开发

编译器为Qt_6_5_3_MinGW_64

优点1:带一个绘制好的仪表盘,可进行数据显示
优点2:自带qcutomplot,能够进行绘图,并且对应qcutomplot已经进行dll集成,能够极大地提升编译时间
优点3:基础的串口通讯配置都有,有对应的发送接收显示
优点4:带一个简单的信号发生器,能够测试qcutomplot绘图

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
下载地址
https://github.com/watch361/QT/

部分代码
串口初始化

void MainWindow::SerialPortInit()
{QStringList portNameList;serial = new QSerialPort; //申请内存,并设置父对象// 参数配置ui->BaudBox->addItem("9600");ui->BaudBox->addItem("57600");ui->BaudBox->addItem("115200");ui->BaudBox->addItem("230400");ui->BaudBox->addItem("460800");// 获取用户选择的波特率字符串QString selectedBaudRate = ui->BaudBox->currentText();// 检查用户选择的波特率,并根据不同的波特率设置串口的波特率// 检查用户选择的波特率,并根据不同的波特率设置串口的波特率if (selectedBaudRate == "9600"){serial->setBaudRate(QSerialPort::Baud9600);}if (selectedBaudRate == "57600"){serial->setBaudRate(QSerialPort::Baud57600);}if (selectedBaudRate == "115200"){serial->setBaudRate(QSerialPort::Baud115200);}// if (selectedBaudRate == "230400")// {//     serial->setBaudRate(QSerialPort::Baud230400);// }// if (selectedBaudRate == "460800")// {//     serial->setBaudRate(QSerialPort::Baud460800);// }// 校验,校验默认选择无ui->ParityBox->addItem("无");serial->setParity(QSerialPort::NoParity);// 数据位,数据位默认选择8位ui->BitBox->addItem("8");serial->setDataBits(QSerialPort::Data8);// 停止位,停止位默认选择1位ui->StopBox->addItem("1");serial->setStopBits(QSerialPort::OneStop);// 刷新串口//  RefreshSerialPort(0);ui->PortBox->clear();                                        //关闭串口号ui->PortBox->addItem("刷新");                                //添加刷新foreach(const QSerialPortInfo &info,QSerialPortInfo::availablePorts()) //添加新串口{portNameList.append(info.portName());}ui->PortBox->addItems(portNameList);ui->PortBox->setCurrentIndex(1);                             // 当前串口号为COM1serial->setPortName(ui->PortBox->currentText());             //设置串口号connect(serial,&QSerialPort::readyRead,this,&MainWindow::UartReceiveMessage);}

仪表盘初始化

void MainWindow::Dashboard_Init()
{//仪表盘显示// connect(this->ui->horizontalSlider,&QSlider::valueChanged,this,&MainWindow::horizontalSlider_3);this->ui->mydial->settitle("速度");this->ui->mydial->setunits("r/min");this->ui->mydial->setmaxValue(4000);this->ui->mydial->setminValue(-4000);//this->ui->dialPlate->setValue(value);this->ui->mydial->update();//手动调用控件的OnPaint方法// connect(this->ui->horizontalSlider_2,&QSlider::valueChanged,this,&MainWindow::horizontalSlider_4);this->ui->mydial1->settitle("角度");this->ui->mydial1->setunits("°");this->ui->mydial1->setmaxValue(360);this->ui->mydial1->setminValue(0);//this->ui->dialPlate->setValue(value);this->ui->mydial1->update();//手动调用控件的OnPaint方法}

绘图初始化

void MainWindow::QCustomPlot_Init()
{//添加一条曲线//向绘图区域QCustomPlot(从widget提升来的)添加一条曲线ui->myCustomPlot->addGraph();//设置画笔ui->myCustomPlot->graph(0)->setPen(QPen(Qt::blue));//设置画刷,曲线和X轴围成面积的颜色ui->myCustomPlot->graph(0)->setBrush(QBrush(QColor(255,255,0)));//设置右上角图形标注名称ui->myCustomPlot->graph(0)->setName("曲线");//设置坐标轴标签名称ui->myCustomPlot->xAxis->setLabel("x");ui->myCustomPlot->yAxis->setLabel("y");//设置坐标轴显示范围,否则我们只能看到默认的范围ui->myCustomPlot->xAxis->setRange(0,60);ui->myCustomPlot->yAxis->setRange(0,1000);}
关键字:QT串口通讯上位机框架,带qcustomplot绘图(DLL集成)有需要的可以自用

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: