Browse Source

ModbusNG: Only output new measurements if at least 1 value in the scanlist has changed

Neal Wilson 8 years ago
parent
commit
dbff3296e6
1 changed files with 19 additions and 4 deletions
  1. 19
    4
      src/modbus.w

+ 19
- 4
src/modbus.w View File

@@ -393,6 +393,7 @@ class ModbusNG : public QObject
393 393
         QList<QString> channelLabels;
394 394
         QList<bool> hiddenStates;
395 395
         QList<QString> channelTypeList;
396
+        QVector<double> lastMeasurement;
396 397
 };
397 398
 
398 399
 @ One of the things that the old Modbus code got right was in allowing the
@@ -499,6 +500,7 @@ ModbusNG::ModbusNG(DeviceTreeModel *model, const QModelIndex &index) :
499 500
 	        channelTypeList.append("C");
500 501
         }
501 502
         scanList.append(scanItem);
503
+        lastMeasurement.append(0.0);
502 504
         channels.append(new Channel);
503 505
         channelNames.append(channelAttributes.value("column").toString());
504 506
         hiddenStates.append(
@@ -601,15 +603,28 @@ void ModbusNG::dataAvailable()
601 603
     if(scanPosition == 0)
602 604
     {
603 605
         QTime time = QTime::currentTime();
606
+        bool doOutput = false;
604 607
         for(int i = 0; i < scanList.size(); i++)
605 608
         {
606
-	        if(scanList.at(scanPosition).unit == Units::Unitless)
609
+	        if(scanList.at(i).lastValue != lastMeasurement.at(i))
607 610
 	        {
608
-		        channels.at(i)->input(Measurement(scanList.at(i).lastValue, time, Units::Unitless));
611
+		        doOutput = true;
612
+		        break;
609 613
 	        }
610
-	        else
614
+        }
615
+        if(doOutput)
616
+        {
617
+	        for(int i = 0; i < scanList.size(); i++)
611 618
 	        {
612
-	            channels.at(i)->input(Measurement(scanList.at(i).lastValue, time, Units::Fahrenheit));
619
+		        lastMeasurement[i] = scanList.at(i).lastValue;
620
+		        if(scanList.at(scanPosition).unit == Units::Unitless)
621
+		        {
622
+			        channels.at(i)->input(Measurement(scanList.at(i).lastValue, time, Units::Unitless));
623
+		        }
624
+		        else
625
+		        {
626
+		            channels.at(i)->input(Measurement(scanList.at(i).lastValue, time, Units::Fahrenheit));
627
+	            }
613 628
             }
614 629
         }
615 630
     }

Loading…
Cancel
Save