@@ -29,7 +29,7 @@ const __FlashStringHelper * P052_data_struct::Plugin_052_valuename(uint8_t value
29
29
F (" ABC period" ), F (" abc_per" ),
30
30
F (" Error Status" ), F (" err" )
31
31
};
32
- const size_t index = ( 2 * value_nr) + (displayString ? 0 : 1 );
32
+ const size_t index = 2 * value_nr + (displayString ? 0 : 1 );
33
33
constexpr size_t nrStrings = sizeof (strings) / sizeof (strings[0 ]);
34
34
35
35
if (index < nrStrings) {
@@ -38,5 +38,58 @@ const __FlashStringHelper * P052_data_struct::Plugin_052_valuename(uint8_t value
38
38
return F (" " );
39
39
}
40
40
41
+ void P052_data_struct::setABCperiod (int hours)
42
+ {
43
+ // Enable: write 1 ... 65534 to HR14 and bit1 set to 0 at HR19
44
+ // Disable: write 0 or 65535 to HR14 and bit1 set to 1 at HR19
41
45
42
- #endif // ifdef USES_P052
46
+
47
+ // Read HR19
48
+ uint8_t errorcode = 0 ;
49
+ int value = modbus.readHoldingRegister (P052_HR19_METER_CONTROL, errorcode);
50
+
51
+ // Clear bit 1 in register and write back HR19
52
+ if (bitRead (value, 1 )) {
53
+ bitClear (value, 1 );
54
+ modbus.writeSingleRegister (P052_HR19_METER_CONTROL, value, errorcode);
55
+ }
56
+
57
+ // Read HR14 and verify desired ABC period
58
+ value = modbus.readHoldingRegister (P052_HR14_ABC_PERIOD, errorcode);
59
+
60
+ // If HR14 (ABC period) is not the desired period,
61
+ // write desired ABC period to HR14
62
+ if (value != hours) {
63
+ modbus.writeSingleRegister (P052_HR14_ABC_PERIOD, hours, errorcode);
64
+ }
65
+ }
66
+
67
+ uint32_t P052_data_struct::getSensorID ()
68
+ {
69
+ uint8_t errorcode = 0 ;
70
+ const uint32_t sensorId = (modbus.readInputRegister (P052_IR30_SENSOR_ID_HIGH, errorcode) << 16 ) |
71
+ modbus.readInputRegister (P052_IR31_SENSOR_ID_LOW, errorcode);
72
+
73
+ if (errorcode == 0 ) {
74
+ return sensorId;
75
+ }
76
+ return 0 ;
77
+ }
78
+
79
+ bool P052_data_struct::readInputRegister (short addr, int & value)
80
+ {
81
+ uint8_t errorcode = 0 ;
82
+
83
+ value = modbus.readInputRegister (addr, errorcode);
84
+ return errorcode == 0 ;
85
+ }
86
+
87
+ bool P052_data_struct::readHoldingRegister (short addr, int & value)
88
+ {
89
+ uint8_t errorcode = 0 ;
90
+
91
+ value = modbus.readHoldingRegister (addr, errorcode);
92
+ return errorcode == 0 ;
93
+ }
94
+
95
+ #endif // ifdef USES_P052
0 commit comments