当前位置:网站首页>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.

边栏推荐
- Kunlun state screen production (serial 3) - based article (button serial port to send)
- QT serial 2: LORA test platform based on QT and STM32H750 (1)
- ipconfig Command Guide
- Real-time waveform display of CAN communication data based on QT (serial eight) ==== "Sub function or new class calls ui control"
- 边境的悍匪—Kaggle—泰坦尼克号生还预测详细教程
- 自定义类加载器
- QT Weekly Skills (1) ~~~~~~~~~ Running Icon
- R language application in the field of ecological environment
- QT连载1:readyRead()函数,数据分包不完整解决办法
- 无法完成包的安装npm ERR! Refusing to install package with name “moment“ under a package also called “moment“
猜你喜欢

电子工程师怎么才能规范设计标准、提高设计效率?

QT每周技巧(1)~~~~~~~~~运行图标

查看 word版本号

【江科大自化协stm32F103c8t6】笔记之【入门32单片机及EXTI外部中断初始化参数配置】

2021 soft exam intermediate pass

动态规划入门 JS

昆仑通态屏幕制作(连载5)---基础篇(串口接收,文本与灯显示)

给Vscode配置ESlint语法检查 — ESLint 插件自动格式化设置(实现Ctrl+S 按照ESLint规则自动格式化代码)

FPGA解析B码----连载2

Atmospheric particulate matter PMF source analysis
随机推荐
QT Weekly Skills (1) ~~~~~~~~~ Running Icon
Kunlun State Screen Production (Serialization 5) --- Basics (serial port reception, text and light display)
闭包(你不知道的JS)
Three working modes of CPU: real mode, protected mode, long mode
查找Proj4js地图投影参数
电子工程师怎么才能规范设计标准、提高设计效率?
服务器基础知识:包含基本概念,作用,服务器选择,服务器管理等(学习来自米拓建站)
Basic application of XMLBean
2021 soft exam intermediate pass
Atmospheric particulate matter PMF source analysis
联影医疗一面
高集成度 MCU 市场增大,如何加速 BLDC 领域落地应用
PCB 一分钟科普之你真的懂多层板吗?
pdf和word等文档添加水印
探究make_shared效率
创建快捷方式时如何不带“快捷方式“后缀字样?
三种内核结构---宏内核、微内核、混合内核
多层板的层数,为啥选项都是偶数?就不能选奇数?
【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
干货:线上下单应知应会,快来了解下