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

相关推荐

  • 辽河油田:党建引领自主管理 创新构建本质安全(党建引领内部管理)

      辽河油田曙光采油厂集输大队下设3座联合站,管理各类机泵438台,各类储罐82座,加热炉42台。承担着采油厂原油脱水、污水处理、污水回注等生产任务。面对工艺老、人员老、设备老、负…

    科研百科 2023年9月19日
    227
  • 路由器能当NAS吗?实测过后才知是异想天开(路由器可以当nas吗)

    在网盘服务极为普遍的今天,仍然有不少人把目光投向更加私密的NAS。对数据绝对控制权带来的安全感,是普通网盘所给不了的。但NAS的缺点也是显然而易见的,更高的经济成本和学习门槛,阻碍…

    科研百科 2022年7月26日
    387
  • 吴志雄:精准发力 深入推进“两新”党建工作

    会议现场。 红网永州站4月7日讯(记者 甘红春)4月7日上午,中共永州市委非公有制经济组织和社会组织工作委员会第一次全体会议在冷水滩召开。市委常委、组织部长吴志雄出席会议并讲话。 …

    科研百科 2023年10月14日
    177
  • 评价导师的网站

    评价导师的网站 随着教育的不断发展,越来越多的学生开始寻求导师的帮助。导师在学生学术发展和成长中扮演着重要的角色,因此,评价导师的网站也变得越来越受欢迎。 然而,评价导师的网站需要…

    科研百科 2024年10月2日
    24
  • 例会专题会议管理制度

    例会专题会议管理制度 例会专题会议管理制度是组织管理中至关重要的一种制度,能够加强团队协作,提高工作效率,保证工作的顺利进行。本文将从例会专题会议管理制度的定义、目的、意义、实施步…

    科研百科 2024年8月23日
    37
  • 系统运行维护和项目管理

    系统运行维护和项目管理是当今软件开发和运营中至关重要的两个方面。在软件开发中,系统运行维护是确保软件质量和稳定性的重要环节,而项目管理则是实现项目目标和时间表的关键。本文将探讨系统…

    科研百科 2025年1月8日
    0
  • 施工项目进度管理

    施工项目进度管理 施工项目进度管理是指在施工项目中,通过对项目进度的控制和规划,确保项目按时完成,达到预期的目标。施工项目进度管理对于保证施工质量和工程进度至关重要,是施工项目成功…

    科研百科 2024年8月30日
    44
  • 上海市科技计划项目管理办法(上海市科学技术委员会科研计划项目)

    《上海市科技计划项目管理办法》 (草案) 公开征求意见中! 为规范和加强上海市科技计划项目管理,根据国家和本市有关规定,市科委对《上海市科技计划项目管理办法(试行)》进行修订。前期…

    科研百科 2022年12月15日
    593
  • 敏捷项目管理工具对比

    敏捷项目管理工具对比 敏捷方法是一种基于用户故事和迭代的项目管理方法,它能够帮助团队更好地理解和满足客户需求,同时提高项目交付质量和效率。随着敏捷方法的普及,敏捷项目管理工具也逐渐…

    科研百科 2024年5月28日
    111
  • 仓库管理流程图(仓库管理流程图片)

    我始终坚信: 管理就是走流程 没有规范流程,管理一切为零 ★按流程来做 流程为各项工作提供程序化的流程 保证办事有指导 ★用制度来管 制度为企业运行制定规范化的制度 保证事事有规范…

    科研百科 2022年5月23日
    1.7K