当前位置:网站首页>QT serial port dynamically displays a large number of data waveform curves in real time (5) ======== "Final perfect solution version"
QT serial port dynamically displays a large number of data waveform curves in real time (5) ======== "Final perfect solution version"
2022-07-30 07:24:00 【transparent light】
前言
busy studyinglinux的嵌入式开发,QTdevelopment has come to an end,So the perfect solution has not been written,Take time nowQTThe serial port dynamically displays a large amount of data in real time. The waveform program has been processed again.,Hope it helps to work on MCU and not familiar with itQT的小伙伴.
先总结下QTfinal feeling:
(1)Use templates if you can use templates written by others,can save a lot of time;
(2)Use variables if you can use global variables,方便.The most important thing is that most of the people who can read this article are engaged in single-chip microcomputers.,Not make an embedded display,Therefore, the logic of thinking cannot be changed for a while.,In accordance with the previous way of thinking in relative comfort;
(3)want something fast,Don't know what the specific code means,知道怎么用就行.QT和while(1)the program is different,It's all piece by piece,know a function,change it, change it,Just output what you want.
第一章:Introduction to program ideas
串口接收程序
This part is divided into two parts,(1)数据接收,(2)数据处理.
Let's talk about data reception first:20ms接收一次,no matter how many,只要在20mswithin the maximum data that can be received at a specific baud rate,That is, all data can be received.直接上程序:
void MainWindow::receive_20ms()
{
int nRxAllLength;
QByteArray recvData;
recvData.resize(256);
uint8_t gnReceiveData[256];
nRxAllLength = m_serial->bytesAvailable();
recvData = m_serial->readAll();
for(int i=0; i<nRxAllLength; i++)
{
gnReceiveData[i] = recvData[i];
}
for(int i=0; i<nRxAllLength; i++)
{
nUartRxBuffer[nUartRxBufHead] = gnReceiveData[i];
nUartRxBufHead++;
if(nUartRxBufHead>=UART_RX_BUF_SIZE) nUartRxBufHead=0;
if(nUartRxBufHead==nUartRxBufTail)
{
nUartRxBufTail++;
if(nUartRxBufTail>=UART_RX_BUF_SIZE) nUartRxBufTail=0;
}
}
}
代码功能:接收数据,并且放到一个fifo里面,接收多少,把fifo开大点,Just receive one and don't overwrite the original data.,Anyway, running on the computer,随便开.If you need to reduce memory,那没办法,You need to figure out how big it is.
Let's talk about the handler:1ms处理一次.为啥1ms,2ms也是可以的,只要比20ms小就行,Best to deal with it as soon as possible,But can't handle it.
存在问题:1msIsn't it timed correctly in embedded??差不多就行,1ms左右就行,As long as it can be executed in a short time.no precise time,Just measure this yourself.Anyway, the processing time of the thread is the approximate time.,don't worry about this.unless you want very precise time output or input,那没办法.Or directly on the program:
void MainWindow::dealdata_1ms()
{
nUartRxLengthTemp = nUartRxBufHead - nUartRxBufTail;
if( nUartRxLengthTemp < 0 )
{
nUartRxLengthTemp = nUartRxLengthTemp+ UART_RX_BUF_SIZE;
}
switch( nUartRxCtrlMode )
{
case MODE_UARTRXCMD_WAIT:
if(nUartRxLengthTemp >= 2)//header is twobyte,Check header first
{
nUartRxHeadCheck = UartRdCharRxBuff();
if(nUartRxHeadCheck == 0x5A) //Guaranteed to parse the first two bytes when5AA5
{
nUartRxHeadCheck = UartRdCharRxBuff();
if(nUartRxHeadCheck == 0xA5)
{
nUartRxCtrlMode = MODE_UARTRXCMD_FRAME;
}
}
}
break;
case MODE_UARTRXCMD_FRAME:
if(nUartRxLengthTemp >= 14)//数据帧14个字节,Change according to your needs
{
for (int i=0;i<14;i++)
{
gnUartRxDataBuffer[i] = UartRdCharRxBuff();
}
data handler code;
gnLatchCnt++;
if(gnLatchCnt == 8)//8Points to store,Displays how many times to store according to how many points are needed
{
gnUartRxRecDoneFlag = 1;
}
nUartRxCtrlMode = MODE_UARTRXCMD_WAIT;
}
break;
default:
nUartRxCtrlMode = MODE_UARTRXCMD_WAIT;
break;
}
}
代码功能:(1)Look for headers from received data5AA5,This is based on your own data,只要能找到就行,Throw it away if you can't find it,know to find the beginning5AA5.(2)find post-processing remaining14数据,14is my own residual data,That is to say, each frame of data has a total of16个字节,The first two are headers,The following data is the data that you need to display.
注意:Here's a habit,It is best to use the data every timebuffer缓存下,The first function prevents from being overwritten,The second is that other programs can be added at any time,The transformation step is best put into a new array.
缓存8帧数据(8个点)之后,出来一个flag,Used to display the data.This depends on how many points you want to display at a time,Because it is the data sent by the serial port assistant,所以8almost a point,If the data of the microcontroller is used,Change this.
Waveform processing program
Waveform processing program is relatively simple,直接上代码:
void ampshow::dealdata_5ms()
{
if(gnUartRxRecDoneFlag == 1)
{
ui->PLOTVAMP->graph(0)->setData(gvUTCms,gvVsuAmp);
ui->PLOTVAMP->graph(1)->setData(gvUTCms,gvVsvAmp);
ui->PLOTVAMP->graph(2)->setData(gvUTCms,gvVswAmp);
ui->PLOTIAMP->graph(0)->setData(gvUTCms,gvIsuAmp);
ui->PLOTIAMP->graph(1)->setData(gvUTCms,gvIsvAmp);
ui->PLOTIAMP->graph(2)->setData(gvUTCms,gvIswAmp);
ui->PLOTVAMP->replot();
ui->PLOTIAMP->replot();
gnUartRxRecDoneFlag = 0;
}
}
receive inside1ms处理一次,这个5ms更新一次,当flag变化后,Start drawing here,就可以正确显示了.
第二章:效果
Post the message first:随便发,5AA5is the header,0001到0008change is time,一共8次.followed by display data.Change according to your needs.
5AA50001000100020003000400050006
5AA50002000100020003000400050006
5AA50003000100020003000400050006
5AA50004000100020003000400050006
5AA50005000100020003000400050006
5AA50006000100020003000400050006
5AA50007000100020003000400050006
5AA50008000100020003000400050006
效果图:
第三章:测试
Use the serial port assistant to test the received data,Tried every time100个数据,每10ms发一次,serial ports can be received correctly.and can display correctly.
第四章:写在最后
Those who need the code can add a public account,Complete code will be placed on baidu in the cloud,可自行下载,If you have any questions, please send a private message,Will answer them one by one.
边栏推荐
- 一文盘点五款 BLDC 风机参考方案,建议先马
- 思谋面试准备
- FPGA解析B码----连载2
- Atmospheric particulate matter PMF source analysis
- QT weekly skills (3)~~~~~~~~~ serial port addition
- 与所有 ARM 工具、软件兼容?韦斯佰瑞这款MCU内核值得关注!
- 【江科大自化协stm32F103c8t6】笔记之【入门32单片机及TIM定时中断初始化参数配置】
- 重磅揭晓!第十四届深创赛福田预选赛区暨华秋第八届硬创大赛华南分赛区晋
- 【江科大自化协stm32F103c8t6】笔记之【入门32单片机及EXTI外部中断初始化参数配置】
- 探究make_shared效率
猜你喜欢
迪文串口屏幕制作(连载一)=====准备工作
Acwing刷题第一节
干货 | 什么是FOC?一文带你看BLDC电机驱动芯片及解决方案
DeepLearing4j's deep learning Yolo Tiny realizes target detection
【markdown常用用法】
使用Dva项目作Antd的Demo
2021-09-16 集成学习上--task1机器学习数学基础
xxx is not in the sudoers file.This incident will be reported错误
TCP为什么要三次握手,握手过程中丢包会怎么样?
CPU的三种工作模式:实模式、保护模式、长模式
随机推荐
User password encryption using Bcrypt instead of MD5, SHA1 and SHA256
查找Proj4js地图投影参数
关于 PCB 多层板制程能力不得不说的那些事儿
租用服务器训练yolov3模型
【江科大自化协stm32F103c8t6】笔记之【入门32单片机及GPIO初始化参数配置】
Flood Control Assessment Report Compilation Method and Flood Modelling under the New Guidelines (HEC-RAS)
Massive remote sensing data processing and application of GEE cloud computing technology [basic, advanced]
openssl 1.1.1编译语句
QT每周技巧(1)~~~~~~~~~运行图标
CLUE Model Construction Method, Model Validation and Land Use Change Scenario Prediction
FPGA parsing B code----serial 2
Kunlun State Screen Production (serialization 4) --- Basics (graphical setting and display, button lights)
高集成度 MCU 市场增大,如何加速 BLDC 领域落地应用
边境的悍匪—机器学习实战:第三章 分类
jvm之方法区
Self-augmented Unpaired Image Dehazing via Density and Depth Decomposition program running record
删除当前路径下含某个关键字的所有文件
边境的悍匪—机器学习实战:第二章 端到端的机器学习项目
DeepLearing4j's deep learning Yolo Tiny realizes target detection
Anaconda 安装低版本tensorflow