一、前言

设备调试核心就是将整个系统中的所有打印数据统一显示到一个模块上,一般都会将硬件通信的收发数据和对应的解析信号发出来或者qdebug出来,这个在调试阶段非常有用,可以具体追踪问题出在哪,哪个数据解析不对直接定位过去,这个模块直接留出界面进行打印查看等,可以在各种现场捕捉异常情况,让现场工程师将调试的数据保存好发给开发人员即可,帮助分析问题,因为很多时候是家里公司测试的好好的,到了现场各种千奇百怪的情况都会出现的,开发人员不可能一天到晚在各种现场跑来跑去,太浪费精力了,不如直接做好对应的设备调试模块,捕捉错误数据将日志文件发过来分析。

作为一个做了十年的这种软硬件通信项目开发的人员来说,这种设备调试的模块肯定考虑的比较多,比如可以直接在界面上过滤某个通信端口、某个设备进行捕捉,可以只监听发送数据、接收数据、解析数据等,最关键的一点,可以自由设定关键字进行捕捉,关键字的数据特殊颜色显示,可以设定多个关键字,这样效率大大提高,毕竟设备数据的收发是很快的,刷刷刷的,一秒钟一个屏幕就过去了,设定关键字进行捕捉自动打印不同颜色,防止眼睛疲劳,一眼老远就看到了,多么美好,在这个模块中还可以勾选输出到日志文件,设定最大行数用来自动清空数据,毕竟文本框不能一直加载数据下去,到了最大行数自动清空。

日志工具开源:https://gitee.com/feiyangqingyun/QWidgetDemo https://github.com/feiyangqingyun/QWidgetDemo

文件名称:savelog

体验地址:https://gitee.com/feiyangqingyun/QWidgetExe https://github.com/feiyangqingyun/QWidgetExe

文件名称:bin_sams.zip

二、功能特点

  1. 采集数据端口,支持串口端口+网络端口,串口支持自由设置串口号+波特率,网络支持自由设置IP地址+通讯端口,每个端口支持采集周期,默认1秒钟一个地址,支持设置通讯超时次数,默认3次,支持最大重连时间,用于重新读取离线的设备。
  2. 控制器信息,能够添加控制器名称,选择控制器地址+控制器型号,设置该控制器下面的探测器数量。
  3. 探测器信息,能够添加位号,可自由选择探测器型号,气体种类,气体符号,高报值,低报值,缓冲值,清零值,是否启用,报警声音,背景地图,存储周期,数值换算小数点位数,报警延时时间,报警的类型(HH,LL,HL)等。
  4. 控制器型号+探测器型号+气体种类+气体符号,均可自由配置。
  5. 地图支持导入和删除,所有的探测器对应地图位置可自由拖动保存。
  6. 端口信息+控制器信息+探测器信息,支持导入导出+导出到excel+打印。
  7. 运行记录+报警记录+用户记录,支持多条件组合查询,比如时间段+控制器+探测器等,所有记录支持导出到excel+打印。
  8. 导出到excel的记录支持所有excel+wps等表格文件版本,不依赖excel等软件。
  9. 可删除指定时间范围内的数据,支持自动清理早期数据,设置最大保存记录数。
  10. 支持报警短信转发,支持多个接收手机号码,可设定发送间隔,比如即时发送或者6个小时发送一次所有的报警信息,短信内容过长,自动拆分多条短信。
  11. 支持报警邮件转发,支持多个接收邮箱,可设定发送间隔,比如即时发送或者6个小时发送一次所有的报警信息,支持附件发送。
  12. 高报颜色+低报颜色+正常颜色+0值颜色+曲线背景+曲线颜色等,都可以自由选择。
  13. 软件的中文标题+英文标题+logo路径+版权所有都可以自由设置。
  14. 提供开关设置开机运行+报警声音+自动登录+记住密码等。
  15. 报警声音可设置播放次数,界面提供17种皮肤文件选择。
  16. 支持云端数据同步,可设置云端数据库的信息,比如数据库名称,用户名+密码等。
  17. 支持网络转发和网络接收,网络接收开启后,软件从udp接收数据进行解析。网络转发支持多个目标IP,这样就实现了本地采集的软件,自由将数据转到客户端,随时查看探测器数据。
  18. 自动记住用户最后停留的界面+其他信息,重启后自动应用。
  19. 报警自动切换到对应的地图,探测器按钮闪烁。
  20. 双击探测器图标,可以进行回控。
  21. 支持用户权限管理,管理员+操作员两大类,用户登录+用户退出,可以记住密码和自动登录,超过三次报错提示并关闭程序。
  22. 支持四种监控模式,设备面板监控+地图监控+表格数据监控+曲线数据监控,可自由切换,四种同步应用。
  23. 支持报警继电器联动,一个位号可以跨串口联动多个模块和继电器号,支持多对多。
  24. 本地数据存储支持sqlite+mysql,支持远程数据同步到云端数据库。自动重连。
  25. 本地设备采集到的数据实时上传到云端,以便手机APP或者web等其他方式提取。
  26. 支持两种数据源,一种是串口和网络通过协议采集设备数据,一种是数据库采集。数据库采集模式可以作为通用的系统使用。
  27. 自带设备模拟工具,支持16个设备数据模拟,同时还带数据库数据模拟,以便在没有设备的时候测试数据。
  28. 默认通信协议采用modbus协议,后期增加mqtt等物联网协议的支持,做成通用系统。
  29. 支持所有windows操作系统+linux操作系统和其他操作系统。

三、效果图

四、核心代码

#include "frmconfigdebug.h"
#include "ui_frmconfigdebug.h"
#include "quiwidget.h"
#include "deviceserver.h"
#include "dblocalthread.h"
#include "dbtcpclientthread.h"
#include "dbreceive.h" frmConfigDebug::frmConfigDebug(QWidget *parent) : QWidget(parent), ui(new Ui::frmConfigDebug)
{
ui->setupUi(this);
this->initForm();
this->initConfig();
} frmConfigDebug::~frmConfigDebug()
{
delete ui;
} void frmConfigDebug::initForm()
{
QFont font;
font.setPixelSize(QUIConfig::FontSize + 5);
ui->txtMain->setFont(font);
ui->frameRight->setFixedWidth(App::RightWidth); ui->cboxPortName->addItem("所有端口");
ui->cboxPortName->addItems(DBData::PortInfo_PortName); QUIHelper::setLabStyle(ui->labPortName, 1);
QUIHelper::setLabStyle(ui->labDeviceName, 1);
QUIHelper::setLabStyle(ui->labKeyValue1, 3);
QUIHelper::setLabStyle(ui->labKeyValue2, 3);
QUIHelper::setPushButtonQss(ui->btnClearData);
QUIHelper::setPushButtonQss(ui->btnReadValueAll); #if (QT_VERSION >= QT_VERSION_CHECK(5,2,0))
ui->txtKeyValue1->setPlaceholderText("支持多个关键字,用 | 隔开");
ui->txtKeyValue2->setPlaceholderText("支持多个关键字,用 | 隔开");
#endif //颜色下拉框
QStringList colorList = QColor::colorNames();
foreach (QString strColor, colorList) {
QPixmap pix(ui->cboxKeyColor1->iconSize());
pix.fill(strColor);
ui->cboxKeyColor1->addItem(QIcon(pix), strColor);
ui->cboxKeyColor2->addItem(QIcon(pix), strColor);
} //绑定设备采集服务信号槽
connect(DeviceServer::Instance(), SIGNAL(sendData(QString, quint8, QByteArray)),
this, SLOT(sendData(QString, quint8, QByteArray)));
connect(DeviceServer::Instance(), SIGNAL(receiveData(QString, quint8, QByteArray)),
this, SLOT(receiveData(QString, quint8, QByteArray)));
connect(DeviceServer::Instance(), SIGNAL(receiveInfo(QString, quint8, QString)),
this, SLOT(receiveInfo(QString, quint8, QString)));
connect(DeviceServer::Instance(), SIGNAL(receiveError(QString, quint8, QString)),
this, SLOT(receiveError(QString, quint8, QString)));
} void frmConfigDebug::initConfig()
{
ui->cboxPortName->setCurrentIndex(App::PortNameIndex);
connect(ui->cboxPortName, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig())); ui->cboxDeviceName->setCurrentIndex(App::DeviceNameIndex);
connect(ui->cboxDeviceName, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig())); keys1 = App::KeyValue1.split("|");
ui->txtKeyValue1->setText(App::KeyValue1);
connect(ui->txtKeyValue1, SIGNAL(textChanged()), this, SLOT(saveConfig())); ui->cboxKeyColor1->setCurrentIndex(ui->cboxKeyColor1->findText(App::KeyColor1));
connect(ui->cboxKeyColor1, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig())); keys2 = App::KeyValue2.split("|");
ui->txtKeyValue2->setText(App::KeyValue2);
connect(ui->txtKeyValue2, SIGNAL(textChanged()), this, SLOT(saveConfig())); ui->cboxKeyColor2->setCurrentIndex(ui->cboxKeyColor2->findText(App::KeyColor2));
connect(ui->cboxKeyColor2, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
} void frmConfigDebug::saveConfig()
{
App::PortNameIndex = ui->cboxPortName->currentIndex();
App::DeviceNameIndex = ui->cboxDeviceName->currentIndex();
App::KeyValue1 = ui->txtKeyValue1->toPlainText().trimmed();
App::KeyColor1 = ui->cboxKeyColor1->currentText();
App::KeyValue2 = ui->txtKeyValue2->toPlainText().trimmed();
App::KeyColor2 = ui->cboxKeyColor2->currentText(); if (App::KeyValue1.isEmpty()) {
App::KeyValue1 = "|";
} if (App::KeyValue2.isEmpty()) {
App::KeyValue2 = "|";
} App::writeConfig(); keys1 = App::KeyValue1.split("|");
keys2 = App::KeyValue2.split("|");
} void frmConfigDebug::append(int type, const QString &portName, quint8 addr, const QString &data, bool clear)
{
static int currentCount = 0;
static int maxCount = 500; //执行清空数据命令
if (clear) {
ui->txtMain->clear();
currentCount = 0;
return;
} //执行条数到了清空数据
if (currentCount >= maxCount) {
ui->txtMain->clear();
currentCount = 0;
} //暂停显示
if (ui->ckPause->isChecked()) {
return;
} //过滤端口
QString currentPortName = ui->cboxPortName->currentText();
if (currentPortName != "所有端口") {
if (currentPortName != portName) {
return;
}
} //过滤地址
quint8 deviceAddr = ui->cboxDeviceName->itemData(App::DeviceNameIndex).toInt();
if (deviceAddr != 255) {
if (deviceAddr != addr) {
return;
}
} //过滤回车换行符
QString strData = data;
strData = strData.replace("\r", "");
strData = strData.replace("\n", ""); //不同类型不同颜色显示
QString strType;
if (type == 0) {
strType = "发送";
ui->txtMain->setTextColor(QColor("#009679"));
} else if (type == 1) {
strType = "接收";
ui->txtMain->setTextColor(QColor("#D64D54"));
} else if (type == 2) {
strType = "解析";
ui->txtMain->setTextColor(QColor("#B59481"));
} else if (type == 3) {
strType = "错误";
ui->txtMain->setTextColor(QColor("#A279C5"));
} else if (type == 4) {
strType = "解析";
ui->txtMain->setTextColor(QColor("#047058"));
} else if (type == 5) {
strType = "解析";
ui->txtMain->setTextColor(QColor("#9157C8"));
} else if (type == 6) {
strType = "解析";
ui->txtMain->setTextColor(QColor("#BA5656"));
} //过滤关键字1,设置不同颜色
foreach (QString key, keys1) {
if (!key.isEmpty() && data.contains(key)) {
ui->txtMain->setTextColor(QColor(App::KeyColor1));
break;
}
} //过滤关键字2,设置不同颜色
foreach (QString key, keys2) {
if (!key.isEmpty() && data.contains(key)) {
ui->txtMain->setTextColor(QColor(App::KeyColor2));
break;
}
} QString strAddr = QString("%1").arg(addr, 3, 10, QChar('0'));
strData = QString("%1 %2[%3] %4: %5").arg(TIMEMS).arg(portName).arg(strAddr).arg(strType).arg(strData);
ui->txtMain->append(strData);
currentCount++; //输出数据
if (ui->ckDebug->isChecked()) {
qDebug() << strData;
}
} void frmConfigDebug::sendData(const QString &portName, quint8 addr, const QByteArray &data)
{
if (!ui->ckSendData->isChecked()) {
return;
} append(0, portName, addr, QUIHelper::byteArrayToHexStr(data));
} void frmConfigDebug::receiveData(const QString &portName, quint8 addr, const QByteArray &data)
{
if (!ui->ckReceiveData->isChecked()) {
return;
} append(1, portName, addr, QUIHelper::byteArrayToHexStr(data));
} void frmConfigDebug::receiveInfo(const QString &portName, quint8 addr, const QString &data)
{
if (!ui->ckReceiveInfo->isChecked()) {
return;
} append(2, portName, addr, data);
} void frmConfigDebug::receiveError(const QString &portName, quint8 addr, const QString &data)
{
append(3, portName, addr, data);
} void frmConfigDebug::debugDbLocalThread(const QString &msg)
{
append(4, "本地数据库", 255, msg);
} void frmConfigDebug::debugDbTcpClientThread(const QString &msg)
{
append(5, "云端数据库", 255, msg);
} void frmConfigDebug::debugDbReceive(const QString &msg)
{
append(6, "下载数据库", 255, msg);
} void frmConfigDebug::on_btnClearData_clicked()
{
append(0, "", 255, "", true);
} void frmConfigDebug::on_btnReadValueAll_clicked()
{
DeviceServer::Instance()->readValueAll();
} void frmConfigDebug::on_cboxPortName_currentIndexChanged(const QString &arg1)
{
//重新载入该端口对应的所有设备
ui->cboxDeviceName->clear();
ui->cboxDeviceName->addItem("所有设备", 255); for (int i = 0; i < DBData::DeviceInfo_Count; i++) {
if (DBData::DeviceInfo_PortName.at(i) == arg1) {
QString deviceName = DBData::DeviceInfo_DeviceName.at(i);
quint8 deviceAddr = DBData::DeviceInfo_DeviceAddr.at(i);
ui->cboxDeviceName->addItem(deviceName, deviceAddr);
}
}
} void frmConfigDebug::on_ckOther_stateChanged(int arg1)
{
on_btnClearData_clicked();
if (arg1 != 0) {
//先解除设备采集服务信号槽
disconnect(DeviceServer::Instance(), SIGNAL(sendData(QString, quint8, QByteArray)),
this, SLOT(sendData(QString, quint8, QByteArray)));
disconnect(DeviceServer::Instance(), SIGNAL(receiveData(QString, quint8, QByteArray)),
this, SLOT(receiveData(QString, quint8, QByteArray)));
disconnect(DeviceServer::Instance(), SIGNAL(receiveInfo(QString, quint8, QString)),
this, SLOT(receiveInfo(QString, quint8, QString)));
disconnect(DeviceServer::Instance(), SIGNAL(receiveError(QString, quint8, QString)),
this, SLOT(receiveError(QString, quint8, QString))); //绑定其他信号槽
connect(DbLocalThread::Instance(), SIGNAL(debug(QString)), this, SLOT(debugDbLocalThread(QString)));
connect(DbTcpClientThread::Instance(), SIGNAL(debug(QString)), this, SLOT(debugDbTcpClientThread(QString)));
connect(DbReceive::Instance(), SIGNAL(debug(QString)), this, SLOT(debugDbReceive(QString)));
} else {
//先绑定设备采集服务信号槽
connect(DeviceServer::Instance(), SIGNAL(sendData(QString, quint8, QByteArray)),
this, SLOT(sendData(QString, quint8, QByteArray)));
connect(DeviceServer::Instance(), SIGNAL(receiveData(QString, quint8, QByteArray)),
this, SLOT(receiveData(QString, quint8, QByteArray)));
connect(DeviceServer::Instance(), SIGNAL(receiveInfo(QString, quint8, QString)),
this, SLOT(receiveInfo(QString, quint8, QString)));
connect(DeviceServer::Instance(), SIGNAL(receiveError(QString, quint8, QString)),
this, SLOT(receiveError(QString, quint8, QString))); //解除其他信号槽
disconnect(DbLocalThread::Instance(), SIGNAL(debug(QString)), this, SLOT(debugDbLocalThread(QString)));
disconnect(DbTcpClientThread::Instance(), SIGNAL(debug(QString)), this, SLOT(debugDbTcpClientThread(QString)));
disconnect(DbReceive::Instance(), SIGNAL(debug(QString)), this, SLOT(debugDbReceive(QString)));
}
}

最新文章

  1. F#之旅1 - Why use F#?为什么要用F#?
  2. java学习第14天(集合的框架和基本遍历)
  3. python: extend (扩展) 与 append (追加) 的差别
  4. 针对跑MySQL的Linux优化【转】
  5. android 程序开机自启动
  6. HDU 1875 畅通工程再续 (最小生成树)
  7. Swift学习笔记(一)搭配环境以及代码执行成功
  8. 黑马程序员_&lt;&lt;GUI(图形用户管理)-----2&gt;&gt;
  9. MFC--自定义消息
  10. 基于MongoDB打造.Net的分布式Session子系统
  11. 使用MxNet新接口Gluon提供的预训练模型进行微调
  12. 简介CentOS与 Ubuntu的不同
  13. RabbitMQ安装及使用
  14. 项目三(2)——person与学生
  15. git 创建标签和删除标签
  16. bzoj千题计划266:bzoj4872: [六省联考2017]分手是祝愿
  17. (A - 整数划分 HYSBZ - 1263)(数组模拟大数乘法)
  18. C#中二进制和流之间的各种相互转换
  19. 使用REGINI修改注册表权限
  20. Docker查看关联容器的卷宗在本机的存储位置

热门文章

  1. 使用kubeadm搭建高可用k8s v1.16.3集群
  2. centos安装zookeeper,并集群配置
  3. 矩阵指数 Matrix Exponentials
  4. Relief 过滤式特征选择
  5. 更改DHCP服务器默认日志存储位置
  6. 【Selenium-WebDriver实战篇】基于java的selenium之验证码识别内容
  7. 常用Maven插件介绍(转载)
  8. 【NOIP 2017】宝藏 D2 T2
  9. Build Post Office II
  10. 经肝药酶CYP3A4代谢的药物对比记录