Pārlūkot izejas kodu

增加通信统计,及串级PID 中间数据收集

guoqiang 2 gadi atpakaļ
vecāks
revīzija
75aa0584b9
12 mainītis faili ar 227 papildinājumiem un 74 dzēšanām
  1. 64 0
      ComStatistics.cpp
  2. 23 0
      ComStatistics.h
  3. 16 0
      PressureSensor.cpp
  4. 3 0
      PressureSensor.h
  5. 65 71
      TestService.cpp
  6. 3 1
      TestService.h
  7. 2 0
      ValveTest.pro
  8. 1 2
      ValveTest.pro.user
  9. 24 0
      ballvalve.cpp
  10. 4 0
      ballvalve.h
  11. 19 0
      valve.cpp
  12. 3 0
      valve.h

+ 64 - 0
ComStatistics.cpp

@@ -0,0 +1,64 @@
+#include "ComStatistics.h"
+#include <QMutex>
+#include <QDateTime>
+#include <QFile>
+#include <QDir>
+#include <QTextStream>
+
+ComStatistics::ComStatistics(QString sensor_name):
+tag_name(sensor_name)
+{
+    request_count = 0;
+    crcerror_count = 0;
+    timeout_count = 0;
+}
+
+void ComStatistics::ReQuestCount_increase()
+{
+    request_count++;
+}
+
+
+void ComStatistics::CrcErrorCount_increase()
+{
+    crcerror_count++;
+}
+
+void ComStatistics::TimeoutCount_increase()
+{
+    timeout_count++;
+}
+
+void ComStatistics::Save2File(QString filepath)
+{
+    static QMutex mutex;
+    mutex.lock();
+    QString time=QDateTime::currentDateTime().toString(QString("[ yyyy-MM-dd HH:mm:ss:zzz ]"));
+    QString mmsg;
+    mmsg = time + "["+ tag_name +"]:";
+    mmsg += "\r\n";
+
+    QString requestString;
+    requestString = "\t ReQuestCount:" + QString::number(request_count) + "\r\n";
+
+    QString crcString;
+    crcString = "\t CrcErrorCount:" + QString::number(crcerror_count) + "\r\n";
+
+    QString timeoutString;
+    timeoutString = "\t TimeoutCount:" + QString::number(timeout_count) + "\r\n";
+
+    QFile file(filepath);
+    file.open(QIODevice::ReadWrite | QIODevice::Append);
+
+    QTextStream stream(&file);
+
+    stream << mmsg;
+    stream << requestString;
+    stream << crcString;
+    stream << timeoutString;
+    stream << "\r\n";
+
+    file.flush();
+    file.close();
+    mutex.unlock();
+}

+ 23 - 0
ComStatistics.h

@@ -0,0 +1,23 @@
+#ifndef COMSTATISTICS_H
+#define COMSTATISTICS_H
+
+#include <QString>
+
+class ComStatistics
+{
+public:
+    ComStatistics(QString sensor_name);
+    void ReQuestCount_increase();
+    void CrcErrorCount_increase();
+    void TimeoutCount_increase();
+    void Save2File(QString filepath);
+
+private:
+    int request_count;
+    int crcerror_count;
+    int timeout_count;
+
+    QString tag_name;
+};
+
+#endif // COMSTATISTICS_H

+ 16 - 0
PressureSensor.cpp

@@ -1,5 +1,8 @@
 #include "PressureSensor.h"
 #include "Modbus.h"
+#include "ComStatistics.h"
+
+static ComStatistics g_PS_Statistics("PressureSensor");
 
 PressureSensor::PressureSensor(SerialUi* pSerial)
 {
@@ -25,6 +28,8 @@ bool PressureSensor::Read(float& pressure)
     tx_buf.append((crc>>8)&0xff);
     tx_buf.append(crc&0xff);
 
+    g_PS_Statistics.ReQuestCount_increase();
+
     QByteArray rx_buf;
     rx_buf = m_pSerial->serialWriteReponse(tx_buf);
     if(rx_buf.size() > 0){
@@ -43,12 +48,14 @@ bool PressureSensor::Read(float& pressure)
         }else{
 
             qDebug("PressureSensor::Read <<< check crc failed");
+            g_PS_Statistics.CrcErrorCount_increase();
             return false;
         }
 
     }else{
 
         qDebug("PressureSensor::Read <<< no data received");
+        g_PS_Statistics.TimeoutCount_increase();
         return false;
     }
 }
@@ -72,6 +79,8 @@ bool PressureSensor::Set_Zero()
     tx_buf.append((crc>>8)&0xff);
     tx_buf.append(crc&0xff);
 
+    g_PS_Statistics.ReQuestCount_increase();
+
     QByteArray rx_buf;
     rx_buf = m_pSerial->serialWriteReponse(tx_buf);
     if(rx_buf.size() > 0){
@@ -80,10 +89,12 @@ bool PressureSensor::Set_Zero()
             return true;
         }else{
             qDebug("PressureSensor::Set_Zero <<< check crc failed");
+            g_PS_Statistics.CrcErrorCount_increase();
             return false;
         }
     }else{
         qDebug("PressureSensor::Set_Zero <<< no data received");
+        g_PS_Statistics.TimeoutCount_increase();
         return false;
     }
 }
@@ -105,3 +116,8 @@ bool PressureSensor::check_crc(QByteArray data)
          return false;
      }
 }
+
+void PressureSensor::Dump_Statistics(QString file_path)
+{
+   g_PS_Statistics.Save2File(file_path);
+}

+ 3 - 0
PressureSensor.h

@@ -2,6 +2,7 @@
 #define PRESSURESENSOR_H
 
 #include "serialui.h"
+#include <QString>
 
 class PressureSensor
 {
@@ -9,6 +10,8 @@ public:
     PressureSensor(SerialUi* pSerial);
     bool Read(float& pressure);
     bool Set_Zero(); // 零点标定
+
+    void Dump_Statistics(QString file_path);
 private:
     SerialUi* m_pSerial;
     bool check_crc(QByteArray data);

+ 65 - 71
TestService.cpp

@@ -224,7 +224,7 @@ bool TestService::tselfstart(int compartmentid, int direction)
     {
     case QMessageBox::Ok:
         qDebug()<<"Ok";
-        m_pTimer_1->start(1*1000);  // 1s
+        m_pTimer_1->start(1*500);  // 1s
         m_bRunning = true;
         start();
         break;
@@ -404,9 +404,6 @@ QString TestService::read_PressureValue()
     PressureSensor ps(&m_SerialUi4);
     if(ps.Read(pressure)){
 
-        int _ipressure = pressure*100;
-        pressure = _ipressure/100.0;
-
         push_pressurelist(pressure);
         timeout_count=0;
 
@@ -423,6 +420,9 @@ QString TestService::read_PressureValue()
 
     }
 
+    int _ipressure = pressure*100;
+    pressure = _ipressure/100.0;
+
     QString pressure_str = QString("%1").arg(pressure, 4,'f',2,QLatin1Char('0'));
     return pressure_str;
 
@@ -486,60 +486,19 @@ QJsonObject TestService::ballvalve_status()
     return rootObj;
 }
 
-#if 0
-bool TestService::OpenSerial3()
+void TestService::dump_comstatistic()
 {
-    m_SerialPort3 = new QSerialPort();
-    m_SerialPort3->setPortName("COM3");
-    m_SerialPort3->setBaudRate(9600, QSerialPort::AllDirections);
-    m_SerialPort3->setDataBits(QSerialPort::Data8);
-    m_SerialPort3->setParity(QSerialPort::NoParity);
-    m_SerialPort3->setStopBits(QSerialPort::OneStop);
-    //m_SerialPort3->setFlowControl(QSerialPort::NoFlowControl);//Set to no flow control
-
-    if (m_SerialPort3->open(QIODevice::ReadWrite) == false){
-        qDebug("open COM3 failed");
-        //QMessageBox::warning(this, "警告", "打开串口COM3失败");
-
-        QString str = "打开串口COM3失败";
-        emit onNotice(str);
-        return false;
-    }
-    else
-    {
-        //controlserial->close();
-        //connect(m_SerialPort3,SIGNAL(readyRead()),this,SLOT(ReadSerialport3()));
-        return true;
-    }
-}
+    QString filepath = "D:/VaporRecoverySystemTest/comstatistic.txt";
+    Valve in_v(&m_SerialUi3, VALVE_INTAKE);
+    in_v.Dump_Statistics(filepath);
 
-bool TestService::OpenSerial4()
-{
-    m_SerialPort4 = new QSerialPort();
-    m_SerialPort4->setPortName("COM4");
-    m_SerialPort4->setBaudRate(9600, QSerialPort::AllDirections);
-    m_SerialPort4->setDataBits(QSerialPort::Data8);
-    m_SerialPort4->setParity(QSerialPort::EvenParity);
-    m_SerialPort4->setStopBits(QSerialPort::OneStop);
-    m_SerialPort4->setFlowControl(QSerialPort::NoFlowControl);//Set to no flow control
-
-    if (m_SerialPort4->open(QIODevice::ReadWrite) == false){
-        qDebug("open COM4 failed");
-        //QMessageBox::warning(this, "警告", "打开串口COM4失败");
-
-        QString str = "打开串口COM4失败,无法读取压力";
-        emit onNotice(str);
-        return false;
-    }
-    else
-    {
-        //readserial->close();
-        //connect(m_SerialPort4,SIGNAL(readyRead()),this,SLOT(ReadSerialport4()));
-        return true;
-    }
-}
+    PressureSensor ps(&m_SerialUi4);
+    ps.Dump_Statistics(filepath);
 
-#endif
+    BallValve bv(&m_SerialUi4);
+    bv.Dump_Statistics(filepath);
+
+}
 
 void TestService::OnTimer1()
 {
@@ -569,13 +528,13 @@ void TestService::OnTimer1()
     }
 
     int _ipressure = 0;
-    if(pressure >= 4.5){
-        _ipressure = pressure*10;
-        pressure = _ipressure/10.0;
-    }else{
+    //if(pressure >= 4.5){
+    //   _ipressure = pressure*10;
+    //    pressure = _ipressure/10.0;
+    //}else{
         _ipressure = pressure*100;
         pressure = _ipressure/100.0;
-    }
+    //}
 
     //int _ipressure = pressure*100;
     //pressure = _ipressure/100.0;
@@ -615,7 +574,7 @@ void TestService::OnTimer2()
     //qDebug("OnTimer2 >>>leave ");
 }
 
-Ret_Value  TestService::PositivePressure_Add(const TestExpect& expect)
+Ret_Value  TestService::PositivePressure_Add(const TestExpect& expect, bool bSavedata)
 {
     Ret_Value ret_v = Ret_OK;
     int count = 0;
@@ -641,12 +600,13 @@ Ret_Value  TestService::PositivePressure_Add(const TestExpect& expect)
 
    PID* pPIDouter = NULL;
    PID* pPIDinner = NULL;
+   double speed_target = 0.0;
 
    //pPIDouter = new PID(1, 0.2, 0, 0.2, 0, 0);
 
-   if(expect.volume <= 1000){
-       pPIDouter = new PID(1, 0.2, 0, 0.2, 0, 0);
-        pPIDinner = new PID(1, 200, 0, 1000, 50, 20, 40, 2);
+   if(expect.volume <= 500){
+       pPIDouter = new PID(0.5, 0.2, 0, 0.2, 0, 0);
+        pPIDinner = new PID(0.5, 200, 0, 1000, 50, 20, 50, 2);
         holding_time = 30;
    }else if(expect.volume <= 5000){
        pPIDouter = new PID(1, 0.2, 0, 0.2, 0, 0);
@@ -668,6 +628,17 @@ Ret_Value  TestService::PositivePressure_Add(const TestExpect& expect)
    bool bOpen_intake = false;
    //bOpen_intake = in_v.Open();
 
+   //
+   QDateTime datetime = QDateTime::currentDateTime();
+   QString timestr = datetime.toString("ddHHmmzzz");
+   QString filepath = "D:/VaporRecoverySystemTest/";
+   QFile datafile(filepath+timestr+"_PIDdata.csv");
+   bool datafile_opened = false;
+   if(true == bSavedata){
+        datafile_opened = datafile.open(QFile::WriteOnly | QFile::Truncate);
+   }
+
+
    //等待压力达到目标值附近
    while(m_bRunning){
 
@@ -702,7 +673,7 @@ Ret_Value  TestService::PositivePressure_Add(const TestExpect& expect)
 
             qDebug(" PositivePressure_Add, current_pressure : %f target: %f", current_pressure, expect.target);
 
-            if(current_pressure >  expect.target+0.05){
+            if(current_pressure >=  expect.target+0.01){
 
                 count++;
                 if(bOpen_intake){
@@ -716,7 +687,6 @@ Ret_Value  TestService::PositivePressure_Add(const TestExpect& expect)
                         //bOpen_intake = false;
                 }
 
-
                 if(exceed_times <= 1){
                     stable_counts = 15;
                 }else if(2 == exceed_times){
@@ -744,7 +714,7 @@ Ret_Value  TestService::PositivePressure_Add(const TestExpect& expect)
 
             }else{
 
-                if(current_pressure >= expect.target && current_pressure <= expect.target + 0.05 ){
+                if(current_pressure >= expect.target && current_pressure < expect.target + 0.01){
                     count++;
                 }else{
                     count=0;
@@ -763,10 +733,10 @@ Ret_Value  TestService::PositivePressure_Add(const TestExpect& expect)
 
                 if(NULL != pPIDouter && NULL != pPIDinner && 0 == stable_counts){
 
-                    double speed_target = pPIDouter->calculate(expect.target+0.02, current_pressure);
+                    speed_target = pPIDouter->calculate(expect.target+0.01, current_pressure);
 
                     qDebug(" PositivePressure_Add, pPIDinner speed_target:%f, current_speed:%f", speed_target, current_speed);
-                    double inc = pPIDinner->calculate(speed_target+0.009, current_speed);
+                    double inc = pPIDinner->calculate(speed_target, current_speed);
 
                     unsigned short  position = bvoffset +inc;
 
@@ -795,7 +765,26 @@ Ret_Value  TestService::PositivePressure_Add(const TestExpect& expect)
             break;
         }
 
-        QThread::msleep(1000);
+        if(true == bSavedata && true == datafile_opened){
+
+            QTextStream out(&datafile);    // 输入流
+
+            QString str1 = QString("%1").arg(expect.target, 8,'f',6,QLatin1Char('0'));
+            QString str2 = QString("%1").arg(current_pressure, 8,'f',6,QLatin1Char('0'));
+
+            //out << QString::number(expect.target) << "," << QString::number(current_pressure) << ",";
+            out << str1 << "," << str2 << ",";
+
+            str1 = QString("%1").arg(speed_target, 8,'f',6,QLatin1Char('0'));
+            str2 = QString("%1").arg(current_speed, 8,'f',6,QLatin1Char('0'));
+
+            //out << QString::number(speed_target) << "," << QString::number(current_speed) << ",";
+            out << str1 << "," << str2 << ",";
+            out << QString::number(bvposition) << "\n";
+
+        }
+
+        QThread::msleep(500);
 
         int remainingtime = expect.timeout*1000 - timer.elapsed();
         if(remainingtime <= 0){
@@ -823,6 +812,9 @@ Ret_Value  TestService::PositivePressure_Add(const TestExpect& expect)
    in_v.Close();
    bv.SetPosition(0);
 
+   if(true == bSavedata && true == datafile_opened){
+       datafile.close();
+   }
 
    return ret_v;
 
@@ -1548,7 +1540,7 @@ void TestService::run()
                              texpect.volume = 0;
                              texpect.target = 4.50;
                              texpect.timeout = 3*60; //5分钟
-                             ret_v = PositivePressure_Add(texpect);
+                             ret_v = PositivePressure_Add(texpect, true);
 
                              if(Ret_Exit == ret_v){
                                 bQuit = true;
@@ -1699,6 +1691,8 @@ void TestService::run()
     Valve all_v(&m_SerialUi3, ALL_VALVE);
     all_v.Close();
 
+    dump_comstatistic();
+
 
     qDebug("doTest >>>leave ");
 

+ 3 - 1
TestService.h

@@ -133,10 +133,12 @@ private:
     bool self_checking();
     bool test_init();
 
+    void dump_comstatistic();
+
     // 0   ok
     // -1  timeout
     // -2  error
-    Ret_Value  PositivePressure_Add(const TestExpect& expect);
+    Ret_Value  PositivePressure_Add(const TestExpect& expect, bool bSavedata = false);
 
     // 0   ok
     // -1  timeout

+ 2 - 0
ValveTest.pro

@@ -11,6 +11,7 @@ QT += virtualkeyboard axcontainer
 #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
 
 SOURCES += \
+        ComStatistics.cpp \
         DLog.cpp \
         Modbus.cpp \
         Msgbox.cpp \
@@ -43,6 +44,7 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin
 !isEmpty(target.path): INSTALLS += target
 
 HEADERS += \
+    ComStatistics.h \
     DLog.h \
     Modbus.h \
     Msgbox.h \

+ 1 - 2
ValveTest.pro.user

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE QtCreatorProject>
-<!-- Written by QtCreator 8.0.0, 2023-05-07T21:43:36. -->
+<!-- Written by QtCreator 8.0.0, 2023-05-09T09:16:00. -->
 <qtcreator>
  <data>
   <variable>EnvironmentId</variable>
@@ -246,7 +246,6 @@
     <value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
     <value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
     <value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
-    <value type="QString" key="RunConfiguration.WorkingDirectory.default">D:/Code/QTapps/build-ValveTest-Desktop_Qt_5_15_2_MinGW_32_bit-Release</value>
    </valuemap>
    <value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
   </valuemap>

+ 24 - 0
ballvalve.cpp

@@ -3,6 +3,10 @@
 #include <QTimer>
 #include <QElapsedTimer>
 
+#include "ComStatistics.h"
+
+static ComStatistics g_BallValve_Statistics("BallValve");
+
 BallValve::BallValve(SerialUi* pSerial)
 {
     m_pSerial = pSerial;
@@ -55,6 +59,7 @@ bool BallValve::SetPosition(unsigned short value)
     tx_buf.append((crc>>8)&0xff);
     tx_buf.append(crc&0xff);
 
+    g_BallValve_Statistics.ReQuestCount_increase();
     QByteArray rx_buf;
     rx_buf = m_pSerial->serialWriteReponse(tx_buf);
     if(rx_buf.size() > 0){
@@ -62,10 +67,12 @@ bool BallValve::SetPosition(unsigned short value)
             return true;
         }else{
             qDebug("SetPosition <<< check crc failed");
+            g_BallValve_Statistics.CrcErrorCount_increase();
             return false;
         }
     }else{
         qDebug("SetPosition <<< no data received use time: %lld ms", timer.elapsed());
+        g_BallValve_Statistics.TimeoutCount_increase();
         return false;
     }
 
@@ -93,6 +100,8 @@ bool BallValve::GetWorkStatus(unsigned char& status)
     tx_buf.append((crc>>8)&0xff);
     tx_buf.append(crc&0xff);
 
+    g_BallValve_Statistics.ReQuestCount_increase();
+
     QByteArray rx_buf;
     rx_buf = m_pSerial->serialWriteReponse(tx_buf);
     if(rx_buf.size() > 0){
@@ -103,10 +112,12 @@ bool BallValve::GetWorkStatus(unsigned char& status)
             return true;
         }else{
             qDebug("GetWorkStatus <<< check crc failed");
+            g_BallValve_Statistics.CrcErrorCount_increase();
             return false;
         }
     }else{
         qDebug("GetWorkStatus <<< no data received ");
+        g_BallValve_Statistics.TimeoutCount_increase();
         return false;
     }
 }
@@ -133,6 +144,8 @@ bool BallValve::GetPosition(unsigned short& value)
     tx_buf.append((crc>>8)&0xff);
     tx_buf.append(crc&0xff);
 
+    g_BallValve_Statistics.ReQuestCount_increase();
+
     QByteArray rx_buf;
     rx_buf = m_pSerial->serialWriteReponse(tx_buf);
     if(rx_buf.size() > 0){
@@ -145,10 +158,12 @@ bool BallValve::GetPosition(unsigned short& value)
             return true;
         }else{
             qDebug("GetPosition <<< check crc failed");
+            g_BallValve_Statistics.CrcErrorCount_increase();
             return false;
         }
     }else{
         qDebug("GetPosition <<< no data received ");
+        g_BallValve_Statistics.TimeoutCount_increase();
         return false;
     }
 }
@@ -176,6 +191,8 @@ bool BallValve::GetSP(unsigned char& status, unsigned short& value)
     tx_buf.append((crc>>8)&0xff);
     tx_buf.append(crc&0xff);
 
+    g_BallValve_Statistics.ReQuestCount_increase();
+
     QByteArray rx_buf;
     rx_buf = m_pSerial->serialWriteReponse(tx_buf);
     if(rx_buf.size() > 0){
@@ -189,10 +206,17 @@ bool BallValve::GetSP(unsigned char& status, unsigned short& value)
             return true;
         }else{
             qDebug("GetSP <<< check crc failed");
+            g_BallValve_Statistics.CrcErrorCount_increase();
             return false;
         }
     }else{
         qDebug("GetSP <<< no data received ");
+        g_BallValve_Statistics.TimeoutCount_increase();
         return false;
     }
 }
+
+void BallValve::Dump_Statistics(QString file_path)
+{
+    g_BallValve_Statistics.Save2File(file_path);
+}

+ 4 - 0
ballvalve.h

@@ -2,6 +2,7 @@
 #define BALLVALVE_H
 
 #include "serialui.h"
+#include <QString>
 
 
 #define BALLVALVE_STATUS_OPENING (0xAA)
@@ -27,9 +28,12 @@ public:
     //bool Break();
     bool GetSP(unsigned char& status, unsigned short& value);
 
+    void Dump_Statistics(QString file_path);
+
 private:
     SerialUi* m_pSerial;
     bool check_crc(QByteArray data);
+
 };
 
 #endif // BALLVALVE_H

+ 19 - 0
valve.cpp

@@ -1,6 +1,10 @@
 #include "valve.h"
 #include "Modbus.h"
 
+#include "ComStatistics.h"
+
+static ComStatistics g_RelayControl_Statistics("RelayControl");
+
 Valve::Valve(SerialUi* pSerial, int id)
 {
     m_pSerial = pSerial;
@@ -56,6 +60,7 @@ bool Valve::Open()
     tx_buf.append((crc>>8)&0xff);
     tx_buf.append(crc&0xff);
 
+    g_RelayControl_Statistics.ReQuestCount_increase();
     QByteArray rx_buf;
     rx_buf = m_pSerial->serialWriteReponse(tx_buf);
     if(rx_buf.size() > 0){
@@ -64,10 +69,12 @@ bool Valve::Open()
             return true;
         }else{
             qDebug("Valve Open crc failed  valve_id[%d]", m_id);
+            g_RelayControl_Statistics.CrcErrorCount_increase();
             return false;
         }
     }else{
         qDebug("Valve Open no data received  valve_id[%d]", m_id);
+        g_RelayControl_Statistics.TimeoutCount_increase();
         return false;
     }
 }
@@ -102,6 +109,7 @@ bool Valve::Close()
     tx_buf.append((crc>>8)&0xff);
     tx_buf.append(crc&0xff);
 
+    g_RelayControl_Statistics.ReQuestCount_increase();
     QByteArray rx_buf;
     rx_buf = m_pSerial->serialWriteReponse(tx_buf);
     if(rx_buf.size() > 0){
@@ -110,10 +118,12 @@ bool Valve::Close()
             return true;
         }else{
             qDebug("Valve close crc failed  valve_id[%d]", m_id);
+            g_RelayControl_Statistics.CrcErrorCount_increase();
             return false;
         }
     }else{
         qDebug("Valve close no data received  valve_id[%d]", m_id);
+        g_RelayControl_Statistics.TimeoutCount_increase();
         return false;
     }
 }
@@ -137,6 +147,8 @@ bool Valve::ReadStatus()
     tx_buf.append((crc>>8)&0xff);
     tx_buf.append(crc&0xff);
 
+    g_RelayControl_Statistics.ReQuestCount_increase();
+
     QByteArray rx_buf;
     rx_buf = m_pSerial->serialWriteReponse(tx_buf);
     if(rx_buf.size() > 0){
@@ -148,10 +160,17 @@ bool Valve::ReadStatus()
             return true;
         }else{
             qDebug("Valve ReadStatus crc failed  valve_id[%d]", m_id);
+            g_RelayControl_Statistics.CrcErrorCount_increase();
             return false;
         }
     }else{
         qDebug("Valve ReadStatus no data received  valve_id[%d]", m_id);
+        g_RelayControl_Statistics.TimeoutCount_increase();
         return false;
     }
 }
+
+void Valve::Dump_Statistics(QString file_path)
+{
+    g_RelayControl_Statistics.Save2File(file_path);
+}

+ 3 - 0
valve.h

@@ -2,6 +2,7 @@
 #define VALVE_H
 
 #include "serialui.h"
+#include <QString>
 
 #define  VALVE_INTAKE  (0)
 #define  VALVE_VACUUM  (1)
@@ -18,6 +19,8 @@ public:
     bool Close();
     bool ReadStatus();
 
+    void Dump_Statistics(QString file_path);
+
 private:
     SerialUi* m_pSerial;
     int  m_id;