Qt编写的嵌入式工业控制系统

一、前言

此系统用于扭力控制,嵌入式平台,采用的开发板为335X,这个还是比较稳定的。

二、开发环境

硬件平台:335X

软件:Qt 嵌入式linux

三、实现功能

1:QSS界面换肤

2:更换主界面背景

3:中文双拼输入法

4:数据图形曲线显示

5:数据统计柱状图显示。

6:串口网络通信

四、效果图

Qt编写的嵌入式工业控制系统Qt编写的嵌入式工业控制系统Qt编写的嵌入式工业控制系统

五、核心代码

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×02=003 003ACK为有新的结果通知 if (buffer.startsWith(\”003STX\”) || buffer.startsWith(\”003ACK\”)) { 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;}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

(0)
上一篇 2023年4月25日 上午8:00
下一篇 2023年4月25日 上午8:10

相关推荐

  • 进销存办公软件有哪些

    进销存办公软件是用于管理商品进销存的计算机软件,可以帮助企业更好地管理库存、销售和客户信息,提高企业的运营效率和管理水平。目前市面上常见的进销存办公软件包括: 1. SAP进销存管…

    科研百科 2024年9月2日
    30
  • 一文看懂前端和后端开发(前端和后端开发的区别)

    作为一名开发者,你可能会想:2019 年最好的软件开发技术和编程语言会是什么?它们又是如何被应用在软件开发当中的?如果你在思考这个问题,那就来对地方了。这篇文章将对前端和后端开发技…

    科研百科 2023年5月8日
    236
  • 医院各科室间业务协同数字化解决方案

    早期医疗信息化的过程中,有不少将信息化做成一块儿一块儿的了。在进行数字化转型时,这反倒成了鸡肋了。 医院各科室间的业务协同,从这个场景来综合考虑,完全根据实际业务的情况、基于数字化…

    2022年6月23日
    350
  • eae项目(eas工程项目管理系统)

    eas工程项目管理系统eas工程项目管理系统的开发工作促进了“CN 101038484” 工程开工1月13日,“您可以在App的基础上使用 ” “您可以在App的基础上使用 ”“您…

    科研百科 2024年9月26日
    25
  • 茂名工程项目管理系统

    茂名工程项目管理系统 茂名工程项目管理系统是一种用于管理工程项目的软件系统,它可以帮助项目经理和工程师更高效地规划和执行项目任务,提高项目质量和效率。该系统提供了各种功能和工具,包…

    科研百科 2025年1月21日
    0
  • 北龙湖有哪些科研项目

    北龙湖是一个位于中国山东省青岛市的市区,拥有着丰富的自然资源和人文历史。随着城市化进程的不断加速,北龙湖成为了一个备受关注的商业中心。在北龙湖,有许多科研项目正在进行中,这些项目不…

    科研百科 2025年4月1日
    1
  • 党建+基层综合治理,激活社会治理红色引擎(党建引领社会综合治理)

    基础不牢、地动山摇。基层治理水平直接关系人民群众生产生活,决定着党执政的社会基础和执政能力、国家治理的根基和水平。坚持党建引领,搭建党员服务平台,充分发挥基层党组织在调解矛盾、服务…

    科研百科 2023年1月30日
    245
  • 科研项目出差理由

    科研项目出差的理由 随着科技的不断发展,科研项目的不断推进,出差也成为了研究人员必不可少的一部分。出差的原因有很多,其中最常见的就是进行实验或研究项目。 出差对于研究人员来说,是一…

    科研百科 2025年2月4日
    5
  • 【案例】民营企业如何通过定向增发进行股权融资(定向增发股票能够增加企业所有者权益吗)

    民营经济是推进中国式现代化的生力军,是高质量发展的重要基础,是推动我国全面建成社会主义现代化强国、实现第二个百年奋斗目标的重要力量。 2023年7月20日,《中共中央国务院关于促进…

    科研百科 2024年5月16日
    148
  • 科研项目可靠吗知乎

    科研项目可靠吗? 在科技发展日新月异的今天,科研项目已经成为了科学研究的重要组成部分。科研项目的成功与否,直接关系到人类的科技发展和社会进步。因此,对于任何科研项目,我们都需要对其…

    科研百科 2025年5月9日
    1