当前位置:网站首页>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.
边栏推荐
- 思谋面试准备
- js 替换字符串中所有 “ 引号 —— 数据处理
- Antd 树拖拽一些细节,官网没有,摸坑篇
- QT serial 2: LORA test platform based on QT and STM32H750 (1)
- Through the bit operations to convert the characters are case sensitive
- 表格比手机屏幕宽时不压缩,可左右滚动,格子内容不换行
- QT Weekly Skills (1) ~~~~~~~~~ Running Icon
- 2021-09-19 集成学习TASK2
- 暂时存着阿里云
- 【Qingdao Station】High-level application of SWAT model and modeling of areas without data, uncertainty analysis and climate change, improvement of land use surface pollution impact model and case analy
猜你喜欢
[Jiangsu University Self-Chemistry Association stm32F103c8t6] Notes [Introduction to 32 MCUs and Using TIM Output to Compare and Configure PWM]
Kunlun state screen production (serial 3) - based article (button serial port to send)
查找Proj4js地图投影参数
给Vscode配置ESlint语法检查 — ESLint 插件自动格式化设置(实现Ctrl+S 按照ESLint规则自动格式化代码)
Cannnot download sources不能下载源码百分百超详细解决方案
QT串口动态实时显示大量数据波形曲线(四)========“界面的美化与处理”
二进制到汇编:进制,原码反码补码,位运算,通用寄存器,内存一套打通
VsCode打开终端的方法
虚拟机栈帧结构
Kunlun State Screen Production (serialization 4) --- Basics (graphical setting and display, button lights)
随机推荐
昆仑通态屏幕制作(连载2)---基础篇(设定与显示,串口发送)
租用服务器训练yolov3模型
干货:线上下单应知应会,快来了解下
主机和从机配置,建立ssh连接实现Rviz远程控制
关于map对key自定义排序
Configure MMdetection environment and train
联影医疗二面
动态规划入门 JS
FPGA解析B码----连载2
[Punctuality Atom] Simple application of sys.c, sys.h bit-band operations
FPGA parsing B code----serial 1
Insertion Sort in Classic Sort
Flood Control Assessment Report Compilation Method and Flood Modelling under the New Guidelines (HEC-RAS)
QT Weekly Skills (1) ~~~~~~~~~ Running Icon
Kunlun State Screen Production (serialization 4) --- Basics (graphical setting and display, button lights)
【正点原子】IIC的学习与使用(未完...)
给Vscode配置ESlint语法检查 — ESLint 插件自动格式化设置(实现Ctrl+S 按照ESLint规则自动格式化代码)
干货 | 什么是FOC?一文带你看BLDC电机驱动芯片及解决方案
"R Language + Remote Sensing" Comprehensive Evaluation Method of Water Environment
VsCode打开终端的方法