Qt编写的嵌入式工业控制系统(嵌入式控制系统)
ccwgpt 2024-09-21 13:53 40 浏览 0 评论
一、前言
此系统用于扭力控制,嵌入式平台,采用的开发板为335X,这个还是比较稳定的。
二、开发环境
硬件平台:335X
软件:Qt+嵌入式linux
三、实现功能
1:QSS界面换肤
2:更换主界面背景
3:中文双拼输入法
4:数据图形曲线显示
5:数据统计柱状图显示。
6:串口网络通信
四、效果图
五、核心代码
void Com_RS232_API::ReadData() { if (com->bytesAvailable() <= 0) { return; } myHelper::Sleep(sleep); QByteArray data = com->readAll(); int dataLen = data.length(); if (dataLen <= 0) { return; } //更新最后心跳时间 lastHeartTime = QDateTime::currentDateTime(); QString buffer = myHelper::ByteArrayToAsciiStr(data); int len = buffer.length(); qDebug() << TIMEMS << "接收数据:" << buffer; emit ReceiveData(buffer); // //将数据加入处理队列,用线程处理数据 // mutex.lock(); // App::Buffer.append(data); // mutex.unlock(); // currentFlag=255; // sleep=50; if (buffer.startsWith("667") && currentFlag == 0) { qDebug() << TIMEMS << "命令解析:" << "握手成功" ; isOk = true; //握手成功后将心跳间隔改为500毫秒 timerHeart->setInterval(500); emit ReceiveHelloOk(); //如果未启用自动执行,则将心跳和开机交互完成置为真 if (!isAuto) { isHeart = true; allFinsh = true; } //握手成功后自动执行开机交互命令 if (isAuto) { QTimer::singleShot(10, this, SLOT(ReadPsetIDNameAll())); } } else if (buffer.startsWith("301PST") && currentFlag == 1) { if (buffer.length() < 7) { return; } qDebug() << TIMEMS << "命令解析:" << "所有Pset索引返回" ; QMap<int, QString> psetIDName; QString temp = buffer.mid(6, len - 1); QStringList list = temp.split("'"); int count = list.count() - 1; for (int i = 0; i < count; i++) { QStringList t = list.at(i).split(":"); int id = t.at(0).toInt(); QString name = t.at(1); psetIDName.insert(id, name); } emit ReceivePsetIDNameAll(psetIDName); qDebug() << TIMEMS << "命令解析:" << "psetIDName:" << psetIDName; } else if (buffer.startsWith("001") && currentFlag == 2) { qDebug() << TIMEMS << "命令解析:" << "授权1成功返回" ; emit ReceiveAuthor1Ok(); //握手成功后自动执行开机交互命令 if (isAuto) { QTimer::singleShot(10, this, SLOT(Author2())); } } else if (buffer.startsWith("001") && currentFlag == 3) { qDebug() << TIMEMS << "命令解析:" << "授权2成功返回" ; emit ReceiveAuthor2Ok(); //握手成功后自动执行开机交互命令 if (isAuto) { QTimer::singleShot(10, this, SLOT(ReadPsetIDCurrent())); } } else if (buffer.startsWith("332") && currentFlag == 4) { if (buffer.length() < 6) { return; } qDebug() << TIMEMS << "命令解析:" << "当前Pset索引返回" ; int psetIDCurrent = buffer.mid(3, 3).toInt(); emit ReceivePsetIDCurrent(psetIDCurrent); qDebug() << TIMEMS << "命令解析:" << "psetIDCurrent:" << psetIDCurrent; //如果是重发命令确认的回复,则不需要继续执行开机交互命令 if (isRecheck) { isRecheck = false; return; } //握手成功后自动执行开机交互命令 if (isAuto) { QTimer::singleShot(10, this, SLOT(Cooperate())); } } else if (buffer.startsWith("5691") && currentFlag == 5) { qDebug() << TIMEMS << "命令解析:" << "配合成功返回" ; emit ReceiveCooperateOk(); //握手成功后自动执行开机交互命令 if (isAuto) { QTimer::singleShot(10, this, SLOT(ReadPsetIDAll())); } } else if (buffer.startsWith("5710") && currentFlag == 6) { qDebug() << TIMEMS << "命令解析:" << "所有已经使用的Pset索引返回" ; QList<int> psetIDAll; QStringList list = buffer.split(":"); if (list.count() < 3) { return; } QStringList t = list.at(2).split(";"); int count = t.count(); for (int i = 0; i < count; i++) { psetIDAll.append(t.at(i).toInt()); } emit ReceivePsetIDAll(psetIDAll); qDebug() << TIMEMS << "命令解析:" << "psetIDAll:" << psetIDAll; //启动心跳命令 isHeart = true; allFinsh = true; } else if (buffer.startsWith("001") && currentFlag == 7) { qDebug() << TIMEMS << "命令解析:" << "指定Pset成功返回" ; emit ReceiveSelectPset(); QTimer::singleShot(10, this, SLOT(ReadPsetIDCurrent())); isRecheck = true; //延时启动心跳定时器,防止结果未读成功而停止了心跳 QTimer::singleShot(500, this, SLOT(StartHeart())); } else if (buffer.startsWith("113P") && currentFlag == 8) { if (buffer.length() < 8) { return; } qDebug() << TIMEMS << "命令解析:" << "Pset参数返回" ; QMap<int, QString> config; int psetID = buffer.mid(4, 3).toInt(); QString temp = buffer.mid(7, len - 1); QStringList list = temp.split("'"); int count = list.count() - 1; for (int i = 0; i < count; i++) { QString t = list.at(i); int pID = t.mid(0, 3).toInt(); QString pValue = t.mid(4, t.length()); //如果参数号为406则需要转换为正常的日期格式 //传过来的是从1970年1月1日0时0分0秒到现在经过的秒数 if (pID == 406) { QDateTime d = myHelper::IntToDateTime(pValue.toUInt()); pValue = d.toString("yyyy-MM-dd HH:mm:ss"); } config.insert(pID, pValue); } emit ReceivePsetConfig(psetID, config); qDebug() << TIMEMS << "命令解析:" << "psetID:" << psetID << "config:" << config; qApp->processEvents(); } else if (buffer.startsWith("001") && currentFlag == 9) { qDebug() << TIMEMS << "命令解析:" << "更新Pset准备成功" ; emit ReceiveUpdatePsetPrepareOk(); } else if (buffer.startsWith("001") && currentFlag == 10) { qDebug() << TIMEMS << "命令解析:" << "更新Pset成功" ; emit ReceiveUpdatePsetOk(); } else if (buffer.startsWith("00101") && currentFlag == 11) { qDebug() << TIMEMS << "命令解析:" << "新建Pset成功" ; emit ReceiveNewPsetOk(); } else if (buffer.startsWith("00101") && currentFlag == 12) { qDebug() << TIMEMS << "命令解析:" << "删除Pset成功" ; emit ReceiveDeletePsetOk(); } else if (buffer.startsWith("003")) { qDebug() << TIMEMS << "命令解析:" << "心跳应答成功" ; emit ReceiveHeartOk(); //003\x02=003 003\\ACK为有新的结果通知 if (buffer.startsWith("003\\STX") || buffer.startsWith("003\\ACK")) { qDebug() << TIMEMS << "命令解析:" << "有新的拧紧结果可读取" ; //立马启动执行读取结果值 if (isAuto) { QTimer::singleShot(10, this, SLOT(ReadResultNmDeg())); //延时启动心跳定时器,防止结果未读成功而停止了心跳 QTimer::singleShot(1800, this, SLOT(StartHeart())); } } } else if (buffer.startsWith("113R")) { if (buffer.length() < 8) { return; } qDebug() << TIMEMS << "命令解析:" << "拧紧数值结果返回" ; int psetID = buffer.mid(4, 3).toInt(); double nm = 0; int nmOk = 1; int deg = 0; int degOk = 1; int id = 0; QString strDate = ""; QString num = "0"; QString temp = buffer.mid(7, len - 1); QStringList list = temp.split("'"); int count = list.count() - 1; for (int i = 0; i < count; i++) { QString t = list.at(i); int pID = t.mid(0, 3).toInt(); QString pValue = t.mid(4, t.length()); if (pID == 100) { nm = pValue.toDouble(); } else if(pID == 101) { nmOk = pValue.toInt(); } else if (pID == 102) { deg = pValue.toInt(); } else if(pID == 103) { degOk = pValue.toInt(); } else if (pID == 300) { id = pValue.toInt(); } else if (pID == 301) { strDate += pValue; } else if (pID == 302) { strDate = QString("%1 %2").arg(strDate).arg(pValue); } else if (pID == 305) { num = pValue; } } emit ReceiveResultNmDeg(psetID, id, strDate, num, nm, nmOk, deg, degOk); qDebug() << TIMEMS << "命令解析:" << "psetID:" << psetID << "结果编号:" << id << "时间:" << strDate << "工具系列号:" << num << "扭矩值:" << nm << "扭矩结果:" << nmOk << "角度值:" << deg << "角度结果:" << degOk; //立马读取扭矩对时间曲线结果 if (isAuto) { QTimer::singleShot(10, this, SLOT(ReadResultNmTimePlot())); //延时启动心跳定时器,防止结果未读成功而停止了心跳 QTimer::singleShot(1800, this, SLOT(StartHeart())); } qApp->processEvents(); } else if (buffer.startsWith("123G")) { if (buffer.length() < 5) { return; } qDebug() << TIMEMS << "命令解析:" << "扭矩对时间曲线返回" ; int psetID = 0; int id = 0; QString strDate = ""; QString num = "0"; double interval = 0; int fenzi = 1; int fenmu = 1; double targetNm = 0; double minNm = 0; double maxNm = 0; QList<double> result; QString temp = buffer.mid(4, len - 1); QStringList l = temp.split(";"); if (l.count() < 2) { return; } //取出分号前的数值 QStringList list = l.at(0).split("'"); int count = list.count() - 1; for (int i = 0; i < count; i++) { QString t = list.at(i); int pID = t.mid(0, 3).toInt(); QString pValue = t.mid(4, t.length()); if (pID == 100) { id = pValue.toInt(); } else if (pID == 101) { strDate += pValue; } else if (pID == 102) { strDate = QString("%1 %2").arg(strDate).arg(pValue); } else if (pID == 105) { num = pValue; } else if (pID == 114) { psetID = pValue.toInt(); } else if (pID == 201) { interval = pValue.toDouble(); } else if (pID == 203) { fenzi = pValue.toInt(); } else if (pID == 204) { fenmu = pValue.toInt(); } else if (pID == 206) { targetNm = pValue.toDouble(); } else if (pID == 210) { minNm = pValue.toDouble(); } else if (pID == 211) { maxNm = pValue.toDouble(); } } //分号后的数据代表结果 QString str1 = l.at(1); QByteArray ba = myHelper::AsciiStrToByteArray(str1); QString str2 = myHelper::ByteArrayToHexStr(ba); //保存获取到的扭矩对角度数据 if (isSaveNm) { QString fileName = QString("%1/save/Nm_%2.txt").arg(App::AppPath) .arg(QDateTime::currentDateTime().toString("yyyy-MM-dd-HH-mm-ss")); QFile file(fileName); file.open(QFile::WriteOnly | QFile::Text); file.write(str2.toLatin1()); file.close(); } QStringList tempList = str2.split(" "); int currentCount = tempList.count(); //如果不是2的倍数则长度要减去1 if ( currentCount % 2 != 0) { currentCount = (currentCount - 1); } //逐个取出扭矩值 for (int i = 0; i < currentCount; i = i + 2) { qint16 value = myHelper::StrHexToShort(QString("%1%2").arg(tempList.at(i)).arg(tempList.at(i + 1))); double r = (double)(value * fenzi) / fenmu; result.append(r); } emit ReceiveResultNmTimePlot(psetID, id, strDate, num, interval, targetNm, minNm, maxNm, result); qDebug() << TIMEMS << "命令解析:" << "psetID:" << psetID << "结果编号:" << id << "时间:" << strDate << "工具系列号:" << num << "间隔:" << interval << "目标扭矩:" << targetNm << "扭矩最小:" << minNm << "扭矩最大:" << maxNm << "结果集合:" << result; //立马读取角度对时间曲线结果 if (isAuto) { QTimer::singleShot(10, this, SLOT(ReadResultDegTimePlot())); //延时启动心跳定时器,防止结果未读成功而停止了心跳 QTimer::singleShot(1800, this, SLOT(StartHeart())); } qApp->processEvents(); } else if (buffer.startsWith("125G")) { if (buffer.length() < 5) { return; } qDebug() << TIMEMS << "命令解析:" << "角度对时间曲线返回" ; int psetID = 0; int id = 0; QString strDate = ""; QString num = "0"; double interval = 0; int fenzi = 1; int fenmu = 1; double targetDeg = 0; double minDeg = 0; double maxDeg = 0; QList<double> result; QString temp = buffer.mid(4, len - 1); QStringList l = temp.split(";"); if (l.count() < 2) { return; } //取出分号前的数值 QStringList list = l.at(0).split("'"); int count = list.count() - 1; for (int i = 0; i < count; i++) { QString t = list.at(i); int pID = t.mid(0, 3).toInt(); QString pValue = t.mid(4, t.length()); if (pID == 100) { id = pValue.toInt(); } else if (pID == 101) { strDate += pValue; } else if (pID == 102) { strDate = QString("%1 %2").arg(strDate).arg(pValue); } else if (pID == 105) { num = pValue; } else if (pID == 114) { psetID = pValue.toInt(); } else if (pID == 201) { interval = pValue.toDouble(); } else if (pID == 204) { fenzi = pValue.toInt(); } else if (pID == 205) { fenmu = pValue.toInt(); } else if (pID == 229) { targetDeg = pValue.toDouble(); } else if (pID == 220) { minDeg = pValue.toDouble(); } else if (pID == 221) { maxDeg = pValue.toDouble(); } } //分号后的数据代表结果 QString str1 = l.at(1); QByteArray ba = myHelper::AsciiStrToByteArray(str1); QString str2 = myHelper::ByteArrayToHexStr(ba); //保存获取到的角度对角度数据 if (isSaveDeg) { QString fileName = QString("%1/save/Deg_%2.txt").arg(App::AppPath) .arg(QDateTime::currentDateTime().toString("yyyy-MM-dd-HH-mm-ss")); QFile file(fileName); file.open(QFile::WriteOnly | QFile::Text); file.write(str2.toLatin1()); file.close(); } QStringList tempList = str2.split(" "); int currentCount = tempList.count(); //如果不是2的倍数则长度要减去1 if ( currentCount % 2 != 0) { currentCount = (currentCount - 1); } //逐个取出角度值 for (int i = 0; i < currentCount; i = i + 2) { qint16 value = myHelper::StrHexToShort(QString("%1%2").arg(tempList.at(i)).arg(tempList.at(i + 1))); double r = (double)(value * fenzi) / fenmu; //传过来的值放大了100倍,所以真实显示的值要除以100 double re = r / 100; result.append(re); } emit ReceiveResultDegTimePlot(psetID, id, strDate, num, interval, targetDeg, minDeg, maxDeg, result); qDebug() << TIMEMS << "命令解析:" << "psetID:" << psetID << "结果编号:" << id << "时间:" << strDate << "工具系列号:" << num << "间隔:" << interval << "最终角度结果:" << targetDeg << "最终角度最小:" << minDeg << "最终角度最大:" << maxDeg << "结果集合:" << result; //将心跳重新置为真 isHeart = true; qApp->processEvents(); } //currentFlag = 255; //sleep = 50; }
- 上一篇:Qt的6个简单小案例(qt案例大全)
- 下一篇:Qt项目架构经验总结(qt底层架构)
相关推荐
- 一个基于.Net Core遵循Clean Architecture原则开源架构
-
今天给大家推荐一个遵循CleanArchitecture原则开源架构。项目简介这是基于Asp.netCore6开发的,遵循CleanArchitecture原则,可以高效、快速地构建基于Ra...
- AI写代码翻车无数次,我发现只要提前做好这3步,bug立减80%
-
写十万行全是bug之后终于找到方法了开发"提示词管理助手"新版本那会儿,我差点被bug整崩溃。刚开始两周,全靠AI改代码架构,结果十万行程序漏洞百出。本来以为AI说没问题就稳了,结果...
- OneCode低代码平台的事件驱动设计:架构解析与实践
-
引言:低代码平台的事件驱动范式在现代软件开发中,事件驱动架构(EDA)已成为构建灵活、松耦合系统的核心范式。OneCode低代码平台通过创新性的注解驱动设计,将事件驱动理念深度融入平台架构,实现了业务...
- 国内大厂AI插件评测:根据UI图生成Vue前端代码
-
在IDEA中安装大厂的AI插件,打开ruoyi增强项目:yudao-ui-admin-vue31.CodeBuddy插件登录腾讯的CodeBuddy后,大模型选择deepseek-v3,输入提示语:...
- AI+低代码技术揭秘(二):核心架构
-
本文档介绍了为VTJ低代码平台提供支持的基本架构组件,包括Engine编排层、Provider服务系统、数据模型和代码生成管道。有关UI组件库和widget系统的信息,请参阅UI...
- GitDiagram用AI把代码库变成可视化架构图
-
这是一个名为gitdiagram的开源工具,可将GitHub仓库实时转换为交互式架构图,帮助开发者快速理解代码结构。核心功能一键可视化:替换GitHubURL中的"hub...
- 30天自制操作系统:第六天:代码架构整理与中断处理
-
1.拆开bootpack.c文件。根据设计模式将对应的功能封装成独立的文件。2.初始化pic:pic(可编程中断控制器):在设计上,cpu单独只能处理一个中断。而pic是将8个中断信号集合成一个中断...
- AI写代码越帮越忙?2025年研究揭露惊人真相
-
近年来,AI工具如雨后春笋般涌现,许多人开始幻想程序员的未来就是“对着AI说几句话”,就能轻松写出完美的代码。然而,2025年的一项最新研究却颠覆了这一期待,揭示了一个令人意外的结果。研究邀请了16位...
- 一键理解开源项目:两个自动生成GitHub代码架构图与说明书工具
-
一、GitDiagram可以一键生成github代码仓库的架构图如果想要可视化github开源项目:https://github.com/luler/reflex_ai_fast,也可以直接把域名替换...
- 5分钟掌握 c# 网络通讯架构及代码示例
-
以下是C#网络通讯架构的核心要点及代码示例,按协议类型分类整理:一、TCP协议(可靠连接)1.同步通信//服务器端usingSystem.Net.Sockets;usingTcpListene...
- 从复杂到优雅:用建造者和责任链重塑代码架构
-
引用设计模式是软件开发中的重要工具,它为解决常见问题提供了标准化的解决方案,提高了代码的可维护性和可扩展性,提升了开发效率,促进了团队协作,提高了软件质量,并帮助开发者更好地适应需求变化。通过学习和应...
- 低代码开发当道,我还需要学习LangChain这些框架吗?| IT杂谈
-
专注LLM深度应用,关注我不迷路前两天有位兄弟问了个问题:当然我很能理解这位朋友的担忧:期望效率最大化,时间用在刀刃上,“不要重新发明轮子”嘛。铺天盖地的AI信息轰炸与概念炒作,很容易让人浮躁与迷茫。...
- 框架设计并不是简单粗暴地写代码,而是要先弄清逻辑
-
3.框架设计3.框架设计本节我们要开发一个UI框架,底层以白鹭引擎为例。框架设计的第一步并不是直接撸代码,而是先想清楚设计思想,抽象。一个一个的UI窗口是独立的吗?不是的,...
- 大佬用 Avalonia 框架开发的 C# 代码 IDE
-
AvalonStudioAvalonStudio是一个开源的跨平台的开发编辑器(IDE),AvalonStudio的目标是成为一个功能齐全,并且可以让开发者快速使用的IDE,提高开发的生产力。A...
- 轻量级框架Lagent 仅需20行代码即可构建自己的智能代理
-
站长之家(ChinaZ.com)8月30日消息:Lagent是一个专注于基于LLM模型的代理开发的轻量级框架。它的设计旨在简化和提高这种模型下代理的开发效率。LLM模型是一种强大的工具,可以...
你 发表评论:
欢迎- 一周热门
- 最近发表
- 标签列表
-
- 框架图 (58)
- flask框架 (53)
- quartz框架 (51)
- abp框架 (47)
- springmvc框架 (49)
- 分布式事务框架 (65)
- scrapy框架 (56)
- shiro框架 (61)
- 定时任务框架 (56)
- java日志框架 (61)
- mfc框架 (52)
- abb框架断路器 (48)
- beego框架 (52)
- java框架spring (58)
- grpc框架 (65)
- tornado框架 (48)
- 前端框架bootstrap (54)
- orm框架有哪些 (51)
- 知识框架图 (52)
- ppt框架 (55)
- 框架图模板 (59)
- 内联框架 (52)
- cad怎么画框架 (58)
- ssm框架实现登录注册 (49)
- oracle字符串长度 (48)