添加记录功能

master
zcy 2023-10-03 23:48:41 +08:00
parent 5d4a457a63
commit ba1e158819
5 changed files with 65 additions and 45 deletions

View File

@ -13,7 +13,8 @@ extern "C"{
typedef struct { typedef struct {
int addr; int addr;
float val1; uint16_t *val1;
uint16_t len;
QString time; QString time;
bool succ; bool succ;
}CapData; }CapData;
@ -84,11 +85,9 @@ public:
QThread::msleep(300); QThread::msleep(300);
for(auto s = 0;s < itr->req.length();s++){ for(auto s = 0;s < itr->req.length();s++){
QThread::msleep(1000); QThread::msleep(1000);
int ret = modbus_read_registers(mMod,itr->req[s].addr,itr->req[s].len,dat); int ret = modbus_read_registers(mMod,itr->req[s].addr,itr->req[s].len,dat);
mMux.lock(); mMux.lock();
bool succ = true; bool succ = true;
@ -96,24 +95,29 @@ public:
if(ret < 0){ if(ret < 0){
succ = false; succ = false;
} }
uint16_t *val = new uint16_t[itr->req[s].len];
memcpy(val,dat,itr->req[s].len*2);
mListData[itr->addr]->push_front(new CapData{ mListData[itr->addr]->push_front(new CapData{
itr->req[s].addr, itr->req[s].addr,
float(float(dat[0])), val,
itr->req[s].len,
QDateTime::currentDateTime().toString("yyyy-mm-dd hh:MM:ss"), QDateTime::currentDateTime().toString("yyyy-mm-dd hh:MM:ss"),
true true
}); });
}else{ }else{
uint16_t *val = new uint16_t[itr->req[s].len];
mListData[itr->addr] = new QList<CapData *>; mListData[itr->addr] = new QList<CapData *>;
mListData[itr->addr]->push_front(new CapData{ mListData[itr->addr]->push_front(new CapData{
itr->req[s].addr, itr->req[s].addr,
float(float(dat[0])), val,
itr->req[s].len,
QDateTime::currentDateTime().toString("yyyy-mm-dd hh:MM:ss"), QDateTime::currentDateTime().toString("yyyy-mm-dd hh:MM:ss"),
succ succ
}); });
} }
mMux.unlock(); mMux.unlock();
} }
modbus_close(mMod); modbus_close(mMod);
} }

View File

@ -1,23 +1,27 @@
#### 又一个modbus调试工具 #### 又一个modbus调试工具
最近混迹物联网企业,发现目前缺少一个简易可用的modbus调试工具,本软件旨在为开发者提供一个简单modbus测试工具。</br>
主打一个代码简单易修改。</br>
特点: 特点:
- 基于QT5 - 基于QT5
- 基于libmodbus - 基于libmodbus
- 完全开源,代码量少 - 完全开源,代码量少
- 三方库完全跨平台,linux/windows。 - 三方库完全跨平台,linux/windows。
#### 功能: #### 已实现功能:
本软件旨在提供一个简单modbus测试工具。 当前仅实现寄存器监控功能。</br>
后期根据心情和捐款情况可能会逐步增加todo项功能。</br>
##### 寄存器监控功能 ##### 寄存器监控功能
1. 返回值导出。
1. 2. 单个寄存器绘图。
2. 返回值导出 3. 消息报文记录。
3. 绘图
[![image.png](https://www.testingcloud.club/sapi/api/image_download/203b900b-61fa-11ee-8ba6-525400797f57.png)](界面) [![image.png](https://www.testingcloud.club/sapi/api/image_download/203b900b-61fa-11ee-8ba6-525400797f57.png)](界面)
#### todo #### todo
1. 主界面配置化,退出后可以保留 1. 配置保存为json文件,不用每次都手动指定监控项。
2. 2. 协议上目前仅支持RTU,增加对modbus-tcp和modbus-ascii的支持。

27
sub.ui
View File

@ -97,7 +97,32 @@
<widget class="QTableView" name="tableView"/> <widget class="QTableView" name="tableView"/>
</item> </item>
<item> <item>
<widget class="QtCharts::QChartView" name="graphicsView"/> <layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>绘图:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>记录</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QtCharts::QChartView" name="graphicsView"/>
</item>
<item>
<widget class="QTextEdit" name="textEdit"/>
</item>
</layout>
</item> </item>
</layout> </layout>
</item> </item>

View File

@ -42,7 +42,15 @@ SubForm::SubForm(QString addr,int baurate,int device_addr)
int ret = gAsyncData->TakeLast(device_addr,&z); int ret = gAsyncData->TakeLast(device_addr,&z);
if(ret == 0){ if(ret == 0){
bool succ = z->succ; bool succ = z->succ;
mSeries1->append(sd,z->val1); if(this->mLines.find(z->addr) != mLines.end()){
mLines[z->addr]->append(mLines.count() + 1,z->val1[0]);
}else{
mLines[z->addr] = new QLineSeries;
mChart->addSeries(mLines[z->addr]); //
mLines[z->addr]->attachAxis(mAxisX); //
mLines[z->addr]->attachAxis(mAxisY);
}
// mSeries1->append(sd,z->val1);
pTime.append(QDateTime::currentDateTime().toString("yyyyMMdd-hh:mm:ss")); pTime.append(QDateTime::currentDateTime().toString("yyyyMMdd-hh:mm:ss"));
QStandardItem *found = nullptr; QStandardItem *found = nullptr;
@ -65,7 +73,7 @@ SubForm::SubForm(QString addr,int baurate,int device_addr)
if(found == 0){ if(found == 0){
QStandardItem *item; QStandardItem *item;
if(succ) if(succ)
item = new QStandardItem(QString("%1").arg(z->val1)); item = new QStandardItem(QString("%1").arg(z->val1[0]));
else else
item = new QStandardItem(QString("³¬Ê±")); item = new QStandardItem(QString("³¬Ê±"));
@ -73,11 +81,14 @@ SubForm::SubForm(QString addr,int baurate,int device_addr)
QStandardItem *item1 = new QStandardItem(QString("%1").arg(z->addr)); QStandardItem *item1 = new QStandardItem(QString("%1").arg(z->addr));
mModel->setItem(i, 0, item1); mModel->setItem(i, 0, item1);
mModel->setItem(i, 2, new QStandardItem(QString("%1").arg(z->time))); mModel->setItem(i, 2, new QStandardItem(QString("%1").arg(z->time)));
QPushButton *button = new QPushButton(this);
ui->tableView->setIndexWidget(mModel->index(i,3),button);
button->setText("»æͼ");
}else{ }else{
mModel->item(found->row(),0)->setData(QString("%1").arg(z->addr),Qt::DisplayRole); mModel->item(found->row(),0)->setData(QString("%1").arg(z->addr),Qt::DisplayRole);
if(succ) if(succ)
mModel->item(found->row(),1)->setData(QString("%1").arg(z->val1),Qt::DisplayRole); mModel->item(found->row(),1)->setData(QString("%1").arg(z->val1[0]),Qt::DisplayRole);
else else
mModel->item(found->row(),1)->setData(QString("³¬Ê±"),Qt::DisplayRole); mModel->item(found->row(),1)->setData(QString("³¬Ê±"),Qt::DisplayRole);
mModel->item(found->row(),2)->setData(QString("%1").arg(z->time),Qt::DisplayRole); mModel->item(found->row(),2)->setData(QString("%1").arg(z->time),Qt::DisplayRole);
@ -97,7 +108,7 @@ SubForm::SubForm(QString addr,int baurate,int device_addr)
qDebug()<<QDateTime::currentDateTime().toString(); qDebug()<<QDateTime::currentDateTime().toString();
ui->lineEdit_2->setText(addr); ui->lineEdit_2->setText(addr);
gAsyncData->AddConfig(this->mConfig); gAsyncData->AddConfig(this->mConfig);
ui->tableView->setColumnWidth(2,230);
} }
void SubForm::on_pushButton_clicked() { void SubForm::on_pushButton_clicked() {
@ -179,24 +190,6 @@ void SubForm::init_charts()
Qt::SolidPattern)); Qt::SolidPattern));
mAxisY->setTitleText("temperature (°C)"); mAxisY->setTitleText("temperature (°C)");
mAxisY2->setMin(0); //YΧ
mAxisY2->setMax(100);
mAxisY2->setTickCount(11);
mAxisY2->setLabelFormat("%d");
mAxisY2->setLinePenColor(QColor(Qt::yellow)); //
mAxisY2->setGridLineColor(QColor(Qt::yellow));
mAxisY2->setGridLinePen(QPen(Qt::white,0.1,Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin));
mAxisY2->setGridLineVisible(true);
mAxisY2->setLinePen(QPen(Qt::yellow,1,Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin));
mAxisY2->setLabelsFont(QFont("",8,18,false));
mAxisY2->setLabelsBrush(QBrush(QColor(Qt::white),
Qt::SolidPattern));
mAxisY2->setLabelsColor(QColor(Qt::white));
mAxisY2->setTitleFont(QFont("",13,20,false));
mAxisY2->setTitleBrush(QBrush(QColor(Qt::white),
Qt::SolidPattern));
mAxisY2->setTitleText("wet %");
mChart->addAxis(mAxisX,Qt::AlignBottom); //λmChartеλ mChart->addAxis(mAxisX,Qt::AlignBottom); //λmChartеλ
mChart->addAxis(mAxisY,Qt::AlignLeft); mChart->addAxis(mAxisY,Qt::AlignLeft);
mChart->addAxis(mAxisY2,Qt::AlignRight); mChart->addAxis(mAxisY2,Qt::AlignRight);

View File

@ -22,7 +22,6 @@ QT_END_NAMESPACE
using namespace QtCharts; using namespace QtCharts;
class SubForm :QWidget class SubForm :QWidget
{ {
Q_OBJECT Q_OBJECT
@ -46,12 +45,7 @@ private:
int baurate; int baurate;
QLineSeries *mSeries1; QLineSeries *mSeries1;
QLineSeries *mSeries2; QMap<uint16_t,QLineSeries*> mLines;
QLineSeries *mSeries3;
QLineSeries *mSeries4;
QLineSeries *mSeries5;
QLineSeries *mSeries6;
QVector<QString> pTime; QVector<QString> pTime;