@enyo-energy/sunspec-sdk 0.0.10 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/sunspec-modbus-client.cjs +47 -38
- package/dist/cjs/sunspec-modbus-client.d.cts +1 -1
- package/dist/cjs/version.cjs +1 -1
- package/dist/cjs/version.d.cts +1 -1
- package/dist/sunspec-modbus-client.d.ts +1 -1
- package/dist/sunspec-modbus-client.js +47 -38
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -22,18 +22,20 @@ exports.SunspecModbusClient = void 0;
|
|
|
22
22
|
const sunspec_interfaces_js_1 = require("./sunspec-interfaces.cjs");
|
|
23
23
|
const EnergyAppModbusConnectionHealth_js_1 = require("@enyo-energy/energy-app-sdk/dist/implementations/modbus/EnergyAppModbusConnectionHealth.js");
|
|
24
24
|
const EnergyAppModbusFaultTolerantReader_js_1 = require("@enyo-energy/energy-app-sdk/dist/implementations/modbus/EnergyAppModbusFaultTolerantReader.js");
|
|
25
|
+
const EnergyAppModbusDataTypeConverter_js_1 = require("@enyo-energy/energy-app-sdk/dist/implementations/modbus/EnergyAppModbusDataTypeConverter.js");
|
|
25
26
|
class SunspecModbusClient {
|
|
26
27
|
energyApp;
|
|
27
28
|
modbusClient = null;
|
|
28
29
|
discoveredModels = new Map();
|
|
29
|
-
scaleFactors = {};
|
|
30
30
|
connected = false;
|
|
31
31
|
baseAddress = 40001;
|
|
32
32
|
connectionHealth;
|
|
33
33
|
faultTolerantReader = null;
|
|
34
|
+
modbusDataTypeConverter;
|
|
34
35
|
constructor(energyApp) {
|
|
35
36
|
this.energyApp = energyApp;
|
|
36
37
|
this.connectionHealth = new EnergyAppModbusConnectionHealth_js_1.EnergyAppModbusConnectionHealth();
|
|
38
|
+
this.modbusDataTypeConverter = new EnergyAppModbusDataTypeConverter_js_1.EnergyAppModbusDataTypeConverter();
|
|
37
39
|
}
|
|
38
40
|
/**
|
|
39
41
|
* Connect to Modbus device
|
|
@@ -66,7 +68,6 @@ class SunspecModbusClient {
|
|
|
66
68
|
this.faultTolerantReader = null;
|
|
67
69
|
this.connected = false;
|
|
68
70
|
this.discoveredModels.clear();
|
|
69
|
-
this.scaleFactors = {};
|
|
70
71
|
}
|
|
71
72
|
}
|
|
72
73
|
/**
|
|
@@ -241,7 +242,7 @@ class SunspecModbusClient {
|
|
|
241
242
|
/**
|
|
242
243
|
* Helper to read register value(s) using the fault-tolerant reader with data type conversion
|
|
243
244
|
*/
|
|
244
|
-
async readRegisterValue(address, quantity = 1, dataType
|
|
245
|
+
async readRegisterValue(address, quantity = 1, dataType) {
|
|
245
246
|
if (!this.faultTolerantReader) {
|
|
246
247
|
throw new Error('Fault-tolerant reader not initialized');
|
|
247
248
|
}
|
|
@@ -253,30 +254,38 @@ class SunspecModbusClient {
|
|
|
253
254
|
}
|
|
254
255
|
const buffer = result.value;
|
|
255
256
|
this.connectionHealth.recordSuccess();
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
let str = '';
|
|
260
|
-
for (let i = 0; i < buffer.length; i += 2) {
|
|
261
|
-
const char1 = buffer[i];
|
|
262
|
-
const char2 = buffer[i + 1];
|
|
263
|
-
if (char1 !== 0)
|
|
264
|
-
str += String.fromCharCode(char1);
|
|
265
|
-
if (char2 !== 0)
|
|
266
|
-
str += String.fromCharCode(char2);
|
|
267
|
-
}
|
|
268
|
-
return this.cleanString(str);
|
|
269
|
-
case 'int16':
|
|
270
|
-
return buffer.readInt16BE(0);
|
|
271
|
-
case 'uint32':
|
|
272
|
-
case 'acc32':
|
|
273
|
-
return buffer.readUint32BE(0);
|
|
274
|
-
case 'int32':
|
|
275
|
-
return buffer.readInt32BE(0);
|
|
276
|
-
case 'uint16':
|
|
277
|
-
default:
|
|
278
|
-
return buffer.readUInt16BE(0);
|
|
257
|
+
const value = this.modbusDataTypeConverter.convertFromBuffer(buffer, dataType);
|
|
258
|
+
if (dataType === 'string') {
|
|
259
|
+
return this.cleanString(value);
|
|
279
260
|
}
|
|
261
|
+
return value;
|
|
262
|
+
//
|
|
263
|
+
// switch (dataType) {
|
|
264
|
+
// case 'string':
|
|
265
|
+
// // Convert buffer to string and clean null characters
|
|
266
|
+
// let str = '';
|
|
267
|
+
// for (let i = 0; i < buffer.length; i += 2) {
|
|
268
|
+
// const char1 = buffer[i];
|
|
269
|
+
// const char2 = buffer[i + 1];
|
|
270
|
+
// if (char1 !== 0) str += String.fromCharCode(char1);
|
|
271
|
+
// if (char2 !== 0) str += String.fromCharCode(char2);
|
|
272
|
+
// }
|
|
273
|
+
// return this.cleanString(str);
|
|
274
|
+
//
|
|
275
|
+
// case 'int16':
|
|
276
|
+
// return buffer.readInt16BE(0);
|
|
277
|
+
//
|
|
278
|
+
// case 'uint32':
|
|
279
|
+
// case 'acc32':
|
|
280
|
+
// return buffer.readUint32BE(0);
|
|
281
|
+
//
|
|
282
|
+
// case 'int32':
|
|
283
|
+
// return buffer.readInt32BE(0);
|
|
284
|
+
//
|
|
285
|
+
// case 'uint16':
|
|
286
|
+
// default:
|
|
287
|
+
// return buffer.readUInt16BE(0);
|
|
288
|
+
// }
|
|
280
289
|
}
|
|
281
290
|
catch (error) {
|
|
282
291
|
this.connectionHealth.recordFailure(error);
|
|
@@ -299,7 +308,7 @@ class SunspecModbusClient {
|
|
|
299
308
|
return this.readSinglePhaseInverterData(singlePhaseModel);
|
|
300
309
|
}
|
|
301
310
|
console.log(`Found 3-phase inverter model 103 at address ${model.address} with length ${model.length}`);
|
|
302
|
-
const baseAddr = model.address +
|
|
311
|
+
const baseAddr = model.address + 1; // Skip ID and Length
|
|
303
312
|
try {
|
|
304
313
|
// Read all scale factors first using fault-tolerant reader
|
|
305
314
|
console.log(`Reading Inverter Data from Model ${model.id} at base address: ${baseAddr}`);
|
|
@@ -385,7 +394,7 @@ class SunspecModbusClient {
|
|
|
385
394
|
};
|
|
386
395
|
// Read AC Energy (32-bit accumulator) - Offset 24-25
|
|
387
396
|
const acEnergyAddr = baseAddr + 24;
|
|
388
|
-
const acEnergy = await this.readRegisterValue(acEnergyAddr, 2, '
|
|
397
|
+
const acEnergy = await this.readRegisterValue(acEnergyAddr, 2, 'uint32');
|
|
389
398
|
console.log(`AC Energy: address=${acEnergyAddr}, raw=0x${acEnergy.toString(16).toUpperCase()} (${acEnergy}), SF=${scaleFactors.WH_SF}`);
|
|
390
399
|
data.acEnergy = !this.isUnimplementedValue(acEnergy, 'acc32')
|
|
391
400
|
? acEnergy * Math.pow(10, scaleFactors.WH_SF) // Regular number with scale factor
|
|
@@ -411,7 +420,7 @@ class SunspecModbusClient {
|
|
|
411
420
|
async readSinglePhaseInverterData(model) {
|
|
412
421
|
// Similar to 3-phase but with fewer phase-specific values
|
|
413
422
|
// Implementation would be similar but simplified
|
|
414
|
-
const baseAddr = model.address +
|
|
423
|
+
const baseAddr = model.address + 1;
|
|
415
424
|
try {
|
|
416
425
|
console.log(`Reading Single-Phase Inverter Data from Model 101 at base address: ${baseAddr}`);
|
|
417
426
|
// Read scale factors for single phase model
|
|
@@ -512,7 +521,7 @@ class SunspecModbusClient {
|
|
|
512
521
|
console.log('MPPT model 160 not found');
|
|
513
522
|
return null;
|
|
514
523
|
}
|
|
515
|
-
const baseAddr = model.address +
|
|
524
|
+
const baseAddr = model.address + 1; // Skip ID and Length
|
|
516
525
|
try {
|
|
517
526
|
// MPPT modules are repeating blocks, calculate offset for specific module
|
|
518
527
|
const moduleSize = 26; // Size of each MPPT module based on CSV (offsets 0-25)
|
|
@@ -531,7 +540,7 @@ class SunspecModbusClient {
|
|
|
531
540
|
const dcCurrentRaw = await this.readRegisterValue(moduleAddr + 9, 1, 'uint16');
|
|
532
541
|
const dcVoltageRaw = await this.readRegisterValue(moduleAddr + 11, 1, 'uint16');
|
|
533
542
|
const dcPowerRaw = await this.readRegisterValue(moduleAddr + 13, 1, 'uint16');
|
|
534
|
-
const dcEnergyRaw = await this.readRegisterValue(moduleAddr + 15, 2, '
|
|
543
|
+
const dcEnergyRaw = await this.readRegisterValue(moduleAddr + 15, 2, 'uint32');
|
|
535
544
|
const temperatureRaw = await this.readRegisterValue(moduleAddr + 20, 1, 'int16');
|
|
536
545
|
console.log(`MPPT Module ${moduleId} Raw Values:`, {
|
|
537
546
|
dcCurrentRaw: `0x${dcCurrentRaw.toString(16).toUpperCase()} (${dcCurrentRaw})`,
|
|
@@ -628,7 +637,7 @@ class SunspecModbusClient {
|
|
|
628
637
|
console.log('No meter model found');
|
|
629
638
|
return null;
|
|
630
639
|
}
|
|
631
|
-
const baseAddr = model.address +
|
|
640
|
+
const baseAddr = model.address + 1;
|
|
632
641
|
console.log(`Reading Meter Data from Model ${model.id} at base address: ${baseAddr}`);
|
|
633
642
|
try {
|
|
634
643
|
// Different meter models have different register offsets
|
|
@@ -695,10 +704,10 @@ class SunspecModbusClient {
|
|
|
695
704
|
const freqRaw = await this.readRegisterValue(freqAddr, 1, 'uint16');
|
|
696
705
|
console.log(`Meter Frequency: address=${freqAddr}, raw=0x${freqRaw.toString(16).toUpperCase()} (${freqRaw}), SF=${freqSF}`);
|
|
697
706
|
const exportAddr = baseAddr + exportOffset;
|
|
698
|
-
const exportRaw = await this.readRegisterValue(exportAddr, 2, '
|
|
707
|
+
const exportRaw = await this.readRegisterValue(exportAddr, 2, 'uint32');
|
|
699
708
|
console.log(`Meter Export Energy: address=${exportAddr}, raw=0x${exportRaw.toString(16).toUpperCase()} (${exportRaw}), SF=${energySF}`);
|
|
700
709
|
const importAddr = baseAddr + importOffset;
|
|
701
|
-
const importRaw = await this.readRegisterValue(importAddr, 2, '
|
|
710
|
+
const importRaw = await this.readRegisterValue(importAddr, 2, 'uint32');
|
|
702
711
|
console.log(`Meter Import Energy: address=${importAddr}, raw=0x${importRaw.toString(16).toUpperCase()} (${importRaw}), SF=${energySF}`);
|
|
703
712
|
// Calculate final values with scale factors
|
|
704
713
|
const totalPower = this.applyScaleFactor(powerRaw, powerSF, 'int16', 'Meter Total Power');
|
|
@@ -812,7 +821,7 @@ class SunspecModbusClient {
|
|
|
812
821
|
console.log('Settings model 121 not found');
|
|
813
822
|
return null;
|
|
814
823
|
}
|
|
815
|
-
const baseAddr = model.address +
|
|
824
|
+
const baseAddr = model.address + 1; // Skip ID and Length
|
|
816
825
|
try {
|
|
817
826
|
// Read scale factors first (offsets 22-31)
|
|
818
827
|
const scaleFactors = {
|
|
@@ -885,7 +894,7 @@ class SunspecModbusClient {
|
|
|
885
894
|
console.log('Controls model 123 not found');
|
|
886
895
|
return null;
|
|
887
896
|
}
|
|
888
|
-
const baseAddr = model.address +
|
|
897
|
+
const baseAddr = model.address + 1; // Skip ID and Length
|
|
889
898
|
try {
|
|
890
899
|
// Read scale factors first (offsets 21-23)
|
|
891
900
|
const scaleFactors = {
|
|
@@ -942,7 +951,7 @@ class SunspecModbusClient {
|
|
|
942
951
|
console.error('Settings model 121 not found');
|
|
943
952
|
return false;
|
|
944
953
|
}
|
|
945
|
-
const baseAddr = model.address +
|
|
954
|
+
const baseAddr = model.address + 1;
|
|
946
955
|
try {
|
|
947
956
|
// For each setting, write the value if provided
|
|
948
957
|
// Note: This is a simplified implementation. In production, you'd batch writes
|
|
@@ -979,7 +988,7 @@ class SunspecModbusClient {
|
|
|
979
988
|
console.error('Controls model 123 not found');
|
|
980
989
|
return false;
|
|
981
990
|
}
|
|
982
|
-
const baseAddr = model.address +
|
|
991
|
+
const baseAddr = model.address + 1;
|
|
983
992
|
try {
|
|
984
993
|
// Connection control
|
|
985
994
|
if (controls.Conn !== undefined && this.modbusClient) {
|
|
@@ -23,11 +23,11 @@ export declare class SunspecModbusClient {
|
|
|
23
23
|
private energyApp;
|
|
24
24
|
private modbusClient;
|
|
25
25
|
private discoveredModels;
|
|
26
|
-
private scaleFactors;
|
|
27
26
|
private connected;
|
|
28
27
|
private baseAddress;
|
|
29
28
|
private connectionHealth;
|
|
30
29
|
private faultTolerantReader;
|
|
30
|
+
private modbusDataTypeConverter;
|
|
31
31
|
constructor(energyApp: EnergyApp);
|
|
32
32
|
/**
|
|
33
33
|
* Connect to Modbus device
|
package/dist/cjs/version.cjs
CHANGED
|
@@ -9,7 +9,7 @@ exports.getSdkVersion = getSdkVersion;
|
|
|
9
9
|
/**
|
|
10
10
|
* Current version of the enyo Energy App SDK.
|
|
11
11
|
*/
|
|
12
|
-
exports.SDK_VERSION = '0.0.
|
|
12
|
+
exports.SDK_VERSION = '0.0.12';
|
|
13
13
|
/**
|
|
14
14
|
* Gets the current SDK version.
|
|
15
15
|
* @returns The semantic version string of the SDK
|
package/dist/cjs/version.d.cts
CHANGED
|
@@ -23,11 +23,11 @@ export declare class SunspecModbusClient {
|
|
|
23
23
|
private energyApp;
|
|
24
24
|
private modbusClient;
|
|
25
25
|
private discoveredModels;
|
|
26
|
-
private scaleFactors;
|
|
27
26
|
private connected;
|
|
28
27
|
private baseAddress;
|
|
29
28
|
private connectionHealth;
|
|
30
29
|
private faultTolerantReader;
|
|
30
|
+
private modbusDataTypeConverter;
|
|
31
31
|
constructor(energyApp: EnergyApp);
|
|
32
32
|
/**
|
|
33
33
|
* Connect to Modbus device
|
|
@@ -19,18 +19,20 @@
|
|
|
19
19
|
import { SunspecModelId } from "./sunspec-interfaces.js";
|
|
20
20
|
import { EnergyAppModbusConnectionHealth } from "@enyo-energy/energy-app-sdk/dist/implementations/modbus/EnergyAppModbusConnectionHealth.js";
|
|
21
21
|
import { EnergyAppModbusFaultTolerantReader } from "@enyo-energy/energy-app-sdk/dist/implementations/modbus/EnergyAppModbusFaultTolerantReader.js";
|
|
22
|
+
import { EnergyAppModbusDataTypeConverter } from "@enyo-energy/energy-app-sdk/dist/implementations/modbus/EnergyAppModbusDataTypeConverter.js";
|
|
22
23
|
export class SunspecModbusClient {
|
|
23
24
|
energyApp;
|
|
24
25
|
modbusClient = null;
|
|
25
26
|
discoveredModels = new Map();
|
|
26
|
-
scaleFactors = {};
|
|
27
27
|
connected = false;
|
|
28
28
|
baseAddress = 40001;
|
|
29
29
|
connectionHealth;
|
|
30
30
|
faultTolerantReader = null;
|
|
31
|
+
modbusDataTypeConverter;
|
|
31
32
|
constructor(energyApp) {
|
|
32
33
|
this.energyApp = energyApp;
|
|
33
34
|
this.connectionHealth = new EnergyAppModbusConnectionHealth();
|
|
35
|
+
this.modbusDataTypeConverter = new EnergyAppModbusDataTypeConverter();
|
|
34
36
|
}
|
|
35
37
|
/**
|
|
36
38
|
* Connect to Modbus device
|
|
@@ -63,7 +65,6 @@ export class SunspecModbusClient {
|
|
|
63
65
|
this.faultTolerantReader = null;
|
|
64
66
|
this.connected = false;
|
|
65
67
|
this.discoveredModels.clear();
|
|
66
|
-
this.scaleFactors = {};
|
|
67
68
|
}
|
|
68
69
|
}
|
|
69
70
|
/**
|
|
@@ -238,7 +239,7 @@ export class SunspecModbusClient {
|
|
|
238
239
|
/**
|
|
239
240
|
* Helper to read register value(s) using the fault-tolerant reader with data type conversion
|
|
240
241
|
*/
|
|
241
|
-
async readRegisterValue(address, quantity = 1, dataType
|
|
242
|
+
async readRegisterValue(address, quantity = 1, dataType) {
|
|
242
243
|
if (!this.faultTolerantReader) {
|
|
243
244
|
throw new Error('Fault-tolerant reader not initialized');
|
|
244
245
|
}
|
|
@@ -250,30 +251,38 @@ export class SunspecModbusClient {
|
|
|
250
251
|
}
|
|
251
252
|
const buffer = result.value;
|
|
252
253
|
this.connectionHealth.recordSuccess();
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
let str = '';
|
|
257
|
-
for (let i = 0; i < buffer.length; i += 2) {
|
|
258
|
-
const char1 = buffer[i];
|
|
259
|
-
const char2 = buffer[i + 1];
|
|
260
|
-
if (char1 !== 0)
|
|
261
|
-
str += String.fromCharCode(char1);
|
|
262
|
-
if (char2 !== 0)
|
|
263
|
-
str += String.fromCharCode(char2);
|
|
264
|
-
}
|
|
265
|
-
return this.cleanString(str);
|
|
266
|
-
case 'int16':
|
|
267
|
-
return buffer.readInt16BE(0);
|
|
268
|
-
case 'uint32':
|
|
269
|
-
case 'acc32':
|
|
270
|
-
return buffer.readUint32BE(0);
|
|
271
|
-
case 'int32':
|
|
272
|
-
return buffer.readInt32BE(0);
|
|
273
|
-
case 'uint16':
|
|
274
|
-
default:
|
|
275
|
-
return buffer.readUInt16BE(0);
|
|
254
|
+
const value = this.modbusDataTypeConverter.convertFromBuffer(buffer, dataType);
|
|
255
|
+
if (dataType === 'string') {
|
|
256
|
+
return this.cleanString(value);
|
|
276
257
|
}
|
|
258
|
+
return value;
|
|
259
|
+
//
|
|
260
|
+
// switch (dataType) {
|
|
261
|
+
// case 'string':
|
|
262
|
+
// // Convert buffer to string and clean null characters
|
|
263
|
+
// let str = '';
|
|
264
|
+
// for (let i = 0; i < buffer.length; i += 2) {
|
|
265
|
+
// const char1 = buffer[i];
|
|
266
|
+
// const char2 = buffer[i + 1];
|
|
267
|
+
// if (char1 !== 0) str += String.fromCharCode(char1);
|
|
268
|
+
// if (char2 !== 0) str += String.fromCharCode(char2);
|
|
269
|
+
// }
|
|
270
|
+
// return this.cleanString(str);
|
|
271
|
+
//
|
|
272
|
+
// case 'int16':
|
|
273
|
+
// return buffer.readInt16BE(0);
|
|
274
|
+
//
|
|
275
|
+
// case 'uint32':
|
|
276
|
+
// case 'acc32':
|
|
277
|
+
// return buffer.readUint32BE(0);
|
|
278
|
+
//
|
|
279
|
+
// case 'int32':
|
|
280
|
+
// return buffer.readInt32BE(0);
|
|
281
|
+
//
|
|
282
|
+
// case 'uint16':
|
|
283
|
+
// default:
|
|
284
|
+
// return buffer.readUInt16BE(0);
|
|
285
|
+
// }
|
|
277
286
|
}
|
|
278
287
|
catch (error) {
|
|
279
288
|
this.connectionHealth.recordFailure(error);
|
|
@@ -296,7 +305,7 @@ export class SunspecModbusClient {
|
|
|
296
305
|
return this.readSinglePhaseInverterData(singlePhaseModel);
|
|
297
306
|
}
|
|
298
307
|
console.log(`Found 3-phase inverter model 103 at address ${model.address} with length ${model.length}`);
|
|
299
|
-
const baseAddr = model.address +
|
|
308
|
+
const baseAddr = model.address + 1; // Skip ID and Length
|
|
300
309
|
try {
|
|
301
310
|
// Read all scale factors first using fault-tolerant reader
|
|
302
311
|
console.log(`Reading Inverter Data from Model ${model.id} at base address: ${baseAddr}`);
|
|
@@ -382,7 +391,7 @@ export class SunspecModbusClient {
|
|
|
382
391
|
};
|
|
383
392
|
// Read AC Energy (32-bit accumulator) - Offset 24-25
|
|
384
393
|
const acEnergyAddr = baseAddr + 24;
|
|
385
|
-
const acEnergy = await this.readRegisterValue(acEnergyAddr, 2, '
|
|
394
|
+
const acEnergy = await this.readRegisterValue(acEnergyAddr, 2, 'uint32');
|
|
386
395
|
console.log(`AC Energy: address=${acEnergyAddr}, raw=0x${acEnergy.toString(16).toUpperCase()} (${acEnergy}), SF=${scaleFactors.WH_SF}`);
|
|
387
396
|
data.acEnergy = !this.isUnimplementedValue(acEnergy, 'acc32')
|
|
388
397
|
? acEnergy * Math.pow(10, scaleFactors.WH_SF) // Regular number with scale factor
|
|
@@ -408,7 +417,7 @@ export class SunspecModbusClient {
|
|
|
408
417
|
async readSinglePhaseInverterData(model) {
|
|
409
418
|
// Similar to 3-phase but with fewer phase-specific values
|
|
410
419
|
// Implementation would be similar but simplified
|
|
411
|
-
const baseAddr = model.address +
|
|
420
|
+
const baseAddr = model.address + 1;
|
|
412
421
|
try {
|
|
413
422
|
console.log(`Reading Single-Phase Inverter Data from Model 101 at base address: ${baseAddr}`);
|
|
414
423
|
// Read scale factors for single phase model
|
|
@@ -509,7 +518,7 @@ export class SunspecModbusClient {
|
|
|
509
518
|
console.log('MPPT model 160 not found');
|
|
510
519
|
return null;
|
|
511
520
|
}
|
|
512
|
-
const baseAddr = model.address +
|
|
521
|
+
const baseAddr = model.address + 1; // Skip ID and Length
|
|
513
522
|
try {
|
|
514
523
|
// MPPT modules are repeating blocks, calculate offset for specific module
|
|
515
524
|
const moduleSize = 26; // Size of each MPPT module based on CSV (offsets 0-25)
|
|
@@ -528,7 +537,7 @@ export class SunspecModbusClient {
|
|
|
528
537
|
const dcCurrentRaw = await this.readRegisterValue(moduleAddr + 9, 1, 'uint16');
|
|
529
538
|
const dcVoltageRaw = await this.readRegisterValue(moduleAddr + 11, 1, 'uint16');
|
|
530
539
|
const dcPowerRaw = await this.readRegisterValue(moduleAddr + 13, 1, 'uint16');
|
|
531
|
-
const dcEnergyRaw = await this.readRegisterValue(moduleAddr + 15, 2, '
|
|
540
|
+
const dcEnergyRaw = await this.readRegisterValue(moduleAddr + 15, 2, 'uint32');
|
|
532
541
|
const temperatureRaw = await this.readRegisterValue(moduleAddr + 20, 1, 'int16');
|
|
533
542
|
console.log(`MPPT Module ${moduleId} Raw Values:`, {
|
|
534
543
|
dcCurrentRaw: `0x${dcCurrentRaw.toString(16).toUpperCase()} (${dcCurrentRaw})`,
|
|
@@ -625,7 +634,7 @@ export class SunspecModbusClient {
|
|
|
625
634
|
console.log('No meter model found');
|
|
626
635
|
return null;
|
|
627
636
|
}
|
|
628
|
-
const baseAddr = model.address +
|
|
637
|
+
const baseAddr = model.address + 1;
|
|
629
638
|
console.log(`Reading Meter Data from Model ${model.id} at base address: ${baseAddr}`);
|
|
630
639
|
try {
|
|
631
640
|
// Different meter models have different register offsets
|
|
@@ -692,10 +701,10 @@ export class SunspecModbusClient {
|
|
|
692
701
|
const freqRaw = await this.readRegisterValue(freqAddr, 1, 'uint16');
|
|
693
702
|
console.log(`Meter Frequency: address=${freqAddr}, raw=0x${freqRaw.toString(16).toUpperCase()} (${freqRaw}), SF=${freqSF}`);
|
|
694
703
|
const exportAddr = baseAddr + exportOffset;
|
|
695
|
-
const exportRaw = await this.readRegisterValue(exportAddr, 2, '
|
|
704
|
+
const exportRaw = await this.readRegisterValue(exportAddr, 2, 'uint32');
|
|
696
705
|
console.log(`Meter Export Energy: address=${exportAddr}, raw=0x${exportRaw.toString(16).toUpperCase()} (${exportRaw}), SF=${energySF}`);
|
|
697
706
|
const importAddr = baseAddr + importOffset;
|
|
698
|
-
const importRaw = await this.readRegisterValue(importAddr, 2, '
|
|
707
|
+
const importRaw = await this.readRegisterValue(importAddr, 2, 'uint32');
|
|
699
708
|
console.log(`Meter Import Energy: address=${importAddr}, raw=0x${importRaw.toString(16).toUpperCase()} (${importRaw}), SF=${energySF}`);
|
|
700
709
|
// Calculate final values with scale factors
|
|
701
710
|
const totalPower = this.applyScaleFactor(powerRaw, powerSF, 'int16', 'Meter Total Power');
|
|
@@ -809,7 +818,7 @@ export class SunspecModbusClient {
|
|
|
809
818
|
console.log('Settings model 121 not found');
|
|
810
819
|
return null;
|
|
811
820
|
}
|
|
812
|
-
const baseAddr = model.address +
|
|
821
|
+
const baseAddr = model.address + 1; // Skip ID and Length
|
|
813
822
|
try {
|
|
814
823
|
// Read scale factors first (offsets 22-31)
|
|
815
824
|
const scaleFactors = {
|
|
@@ -882,7 +891,7 @@ export class SunspecModbusClient {
|
|
|
882
891
|
console.log('Controls model 123 not found');
|
|
883
892
|
return null;
|
|
884
893
|
}
|
|
885
|
-
const baseAddr = model.address +
|
|
894
|
+
const baseAddr = model.address + 1; // Skip ID and Length
|
|
886
895
|
try {
|
|
887
896
|
// Read scale factors first (offsets 21-23)
|
|
888
897
|
const scaleFactors = {
|
|
@@ -939,7 +948,7 @@ export class SunspecModbusClient {
|
|
|
939
948
|
console.error('Settings model 121 not found');
|
|
940
949
|
return false;
|
|
941
950
|
}
|
|
942
|
-
const baseAddr = model.address +
|
|
951
|
+
const baseAddr = model.address + 1;
|
|
943
952
|
try {
|
|
944
953
|
// For each setting, write the value if provided
|
|
945
954
|
// Note: This is a simplified implementation. In production, you'd batch writes
|
|
@@ -976,7 +985,7 @@ export class SunspecModbusClient {
|
|
|
976
985
|
console.error('Controls model 123 not found');
|
|
977
986
|
return false;
|
|
978
987
|
}
|
|
979
|
-
const baseAddr = model.address +
|
|
988
|
+
const baseAddr = model.address + 1;
|
|
980
989
|
try {
|
|
981
990
|
// Connection control
|
|
982
991
|
if (controls.Conn !== undefined && this.modbusClient) {
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED