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
         QList<QString> channelLabels;
393
         QList<QString> channelLabels;
394
         QList<bool> hiddenStates;
394
         QList<bool> hiddenStates;
395
         QList<QString> channelTypeList;
395
         QList<QString> channelTypeList;
396
+        QVector<double> lastMeasurement;
396
 };
397
 };
397
 
398
 
398
 @ One of the things that the old Modbus code got right was in allowing the
399
 @ One of the things that the old Modbus code got right was in allowing the
499
 	        channelTypeList.append("C");
500
 	        channelTypeList.append("C");
500
         }
501
         }
501
         scanList.append(scanItem);
502
         scanList.append(scanItem);
503
+        lastMeasurement.append(0.0);
502
         channels.append(new Channel);
504
         channels.append(new Channel);
503
         channelNames.append(channelAttributes.value("column").toString());
505
         channelNames.append(channelAttributes.value("column").toString());
504
         hiddenStates.append(
506
         hiddenStates.append(
601
     if(scanPosition == 0)
603
     if(scanPosition == 0)
602
     {
604
     {
603
         QTime time = QTime::currentTime();
605
         QTime time = QTime::currentTime();
606
+        bool doOutput = false;
604
         for(int i = 0; i < scanList.size(); i++)
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