@enyo-energy/sunspec-sdk 0.0.8 → 0.0.9

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.
@@ -286,7 +286,7 @@ class SunspecModbusClient {
286
286
  const baseAddr = model.address + 2; // Skip ID and Length
287
287
  try {
288
288
  // Read all scale factors first using fault-tolerant reader
289
- console.log(`Reading Inverter Data from Model 103 at base address: ${baseAddr}`);
289
+ console.log(`Reading Inverter Data from Model ${model.id} at base address: ${baseAddr}`);
290
290
  const scaleFactors = await this.readInverterScaleFactors(baseAddr);
291
291
  // Read values using fault-tolerant reader with proper data types
292
292
  // Read raw voltage values to check for unimplemented phases
@@ -611,17 +611,57 @@ class SunspecModbusClient {
611
611
  const baseAddr = model.address + 2;
612
612
  console.log(`Reading Meter Data from Model ${model.id} at base address: ${baseAddr}`);
613
613
  try {
614
- // Model 201 (single phase meter) - Correct register offsets from Sunspec
615
- // All offsets are from data start (after ID and Length)
616
- console.log(`Meter is Model 201 (Single Phase Meter)`);
617
- // Model 201 register offsets according to Sunspec specification:
618
- const powerOffset = 18; // W - Total Real Power (int16) at offset 18
619
- const powerSFOffset = 21; // W_SF - Power scale factor at offset 21
620
- const freqOffset = 32; // Hz - Frequency (uint16) at offset 32
621
- const freqSFOffset = 35; // Hz_SF - Frequency scale factor at offset 35
622
- const exportOffset = 38; // TotWhExp - Total Wh Exported (acc32) at offset 38-39
623
- const importOffset = 46; // TotWhImp - Total Wh Imported (acc32) at offset 46-47
624
- const energySFOffset = 4; // TotWh_SF - Total Energy scale factor at offset 4
614
+ // Different meter models have different register offsets
615
+ console.log(`Meter is Model ${model.id}`);
616
+ let powerOffset;
617
+ let powerSFOffset;
618
+ let freqOffset;
619
+ let freqSFOffset;
620
+ let exportOffset;
621
+ let importOffset;
622
+ let energySFOffset;
623
+ switch (model.id) {
624
+ case 201: // Single-phase meter
625
+ console.log('Using Model 201 (Single-Phase Meter) offsets');
626
+ powerOffset = 18; // W - Total Real Power (int16)
627
+ powerSFOffset = 21; // W_SF - Power scale factor
628
+ freqOffset = 32; // Hz - Frequency (uint16)
629
+ freqSFOffset = 35; // Hz_SF - Frequency scale factor
630
+ exportOffset = 38; // TotWhExp - Total Wh Exported (acc32)
631
+ importOffset = 46; // TotWhImp - Total Wh Imported (acc32)
632
+ energySFOffset = 4; // TotWh_SF - Total Energy scale factor
633
+ break;
634
+ case 203: // 3-phase meter (Delta)
635
+ console.log('Using Model 203 (3-Phase Meter Delta) offsets');
636
+ powerOffset = 14; // W - Total Real Power (int16)
637
+ powerSFOffset = 17; // W_SF - Power scale factor
638
+ freqOffset = 24; // Hz - Frequency (uint16)
639
+ freqSFOffset = 27; // Hz_SF - Frequency scale factor
640
+ exportOffset = 38; // TotWhExp - Total Wh Exported (acc32)
641
+ importOffset = 46; // TotWhImp - Total Wh Imported (acc32)
642
+ energySFOffset = 4; // TotWh_SF - Total Energy scale factor
643
+ break;
644
+ case 204: // 3-phase meter (Wye)
645
+ console.log('Using Model 204 (3-Phase Meter Wye) offsets');
646
+ powerOffset = 14; // W - Total Real Power (int16)
647
+ powerSFOffset = 17; // W_SF - Power scale factor
648
+ freqOffset = 28; // Hz - Frequency (uint16)
649
+ freqSFOffset = 31; // Hz_SF - Frequency scale factor
650
+ exportOffset = 42; // TotWhExp - Total Wh Exported (acc32)
651
+ importOffset = 50; // TotWhImp - Total Wh Imported (acc32)
652
+ energySFOffset = 4; // TotWh_SF - Total Energy scale factor
653
+ break;
654
+ default:
655
+ console.error(`Unknown meter model ${model.id}, using Model 201 defaults`);
656
+ powerOffset = 18;
657
+ powerSFOffset = 21;
658
+ freqOffset = 32;
659
+ freqSFOffset = 35;
660
+ exportOffset = 38;
661
+ importOffset = 46;
662
+ energySFOffset = 4;
663
+ break;
664
+ }
625
665
  // Read scale factors
626
666
  const powerSF = await this.readRegisterValue(baseAddr + powerSFOffset, 1, 'int16');
627
667
  const freqSF = await this.readRegisterValue(baseAddr + freqSFOffset, 1, 'int16');
@@ -838,7 +878,7 @@ class SunspecModbusClient {
838
878
  blockAddress: model.address,
839
879
  blockLength: model.length,
840
880
  // Connection control - Offsets 0-2
841
- Conn_WinTms: await this.readRegisterValue(baseAddr + 0, 1, 'uint16'),
881
+ Conn_WinTms: await this.readRegisterValue(baseAddr, 1, 'uint16'),
842
882
  Conn_RvrtTms: await this.readRegisterValue(baseAddr + 1, 1, 'uint16'),
843
883
  Conn: await this.readRegisterValue(baseAddr + 2, 1, 'uint16'),
844
884
  // Power limit control - Offsets 3-7
@@ -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.8';
12
+ exports.SDK_VERSION = '0.0.9';
13
13
  /**
14
14
  * Gets the current SDK version.
15
15
  * @returns The semantic version string of the SDK
@@ -5,7 +5,7 @@
5
5
  /**
6
6
  * Current version of the enyo Energy App SDK.
7
7
  */
8
- export declare const SDK_VERSION = "0.0.8";
8
+ export declare const SDK_VERSION = "0.0.9";
9
9
  /**
10
10
  * Gets the current SDK version.
11
11
  * @returns The semantic version string of the SDK
@@ -283,7 +283,7 @@ export class SunspecModbusClient {
283
283
  const baseAddr = model.address + 2; // Skip ID and Length
284
284
  try {
285
285
  // Read all scale factors first using fault-tolerant reader
286
- console.log(`Reading Inverter Data from Model 103 at base address: ${baseAddr}`);
286
+ console.log(`Reading Inverter Data from Model ${model.id} at base address: ${baseAddr}`);
287
287
  const scaleFactors = await this.readInverterScaleFactors(baseAddr);
288
288
  // Read values using fault-tolerant reader with proper data types
289
289
  // Read raw voltage values to check for unimplemented phases
@@ -608,17 +608,57 @@ export class SunspecModbusClient {
608
608
  const baseAddr = model.address + 2;
609
609
  console.log(`Reading Meter Data from Model ${model.id} at base address: ${baseAddr}`);
610
610
  try {
611
- // Model 201 (single phase meter) - Correct register offsets from Sunspec
612
- // All offsets are from data start (after ID and Length)
613
- console.log(`Meter is Model 201 (Single Phase Meter)`);
614
- // Model 201 register offsets according to Sunspec specification:
615
- const powerOffset = 18; // W - Total Real Power (int16) at offset 18
616
- const powerSFOffset = 21; // W_SF - Power scale factor at offset 21
617
- const freqOffset = 32; // Hz - Frequency (uint16) at offset 32
618
- const freqSFOffset = 35; // Hz_SF - Frequency scale factor at offset 35
619
- const exportOffset = 38; // TotWhExp - Total Wh Exported (acc32) at offset 38-39
620
- const importOffset = 46; // TotWhImp - Total Wh Imported (acc32) at offset 46-47
621
- const energySFOffset = 4; // TotWh_SF - Total Energy scale factor at offset 4
611
+ // Different meter models have different register offsets
612
+ console.log(`Meter is Model ${model.id}`);
613
+ let powerOffset;
614
+ let powerSFOffset;
615
+ let freqOffset;
616
+ let freqSFOffset;
617
+ let exportOffset;
618
+ let importOffset;
619
+ let energySFOffset;
620
+ switch (model.id) {
621
+ case 201: // Single-phase meter
622
+ console.log('Using Model 201 (Single-Phase Meter) offsets');
623
+ powerOffset = 18; // W - Total Real Power (int16)
624
+ powerSFOffset = 21; // W_SF - Power scale factor
625
+ freqOffset = 32; // Hz - Frequency (uint16)
626
+ freqSFOffset = 35; // Hz_SF - Frequency scale factor
627
+ exportOffset = 38; // TotWhExp - Total Wh Exported (acc32)
628
+ importOffset = 46; // TotWhImp - Total Wh Imported (acc32)
629
+ energySFOffset = 4; // TotWh_SF - Total Energy scale factor
630
+ break;
631
+ case 203: // 3-phase meter (Delta)
632
+ console.log('Using Model 203 (3-Phase Meter Delta) offsets');
633
+ powerOffset = 14; // W - Total Real Power (int16)
634
+ powerSFOffset = 17; // W_SF - Power scale factor
635
+ freqOffset = 24; // Hz - Frequency (uint16)
636
+ freqSFOffset = 27; // Hz_SF - Frequency scale factor
637
+ exportOffset = 38; // TotWhExp - Total Wh Exported (acc32)
638
+ importOffset = 46; // TotWhImp - Total Wh Imported (acc32)
639
+ energySFOffset = 4; // TotWh_SF - Total Energy scale factor
640
+ break;
641
+ case 204: // 3-phase meter (Wye)
642
+ console.log('Using Model 204 (3-Phase Meter Wye) offsets');
643
+ powerOffset = 14; // W - Total Real Power (int16)
644
+ powerSFOffset = 17; // W_SF - Power scale factor
645
+ freqOffset = 28; // Hz - Frequency (uint16)
646
+ freqSFOffset = 31; // Hz_SF - Frequency scale factor
647
+ exportOffset = 42; // TotWhExp - Total Wh Exported (acc32)
648
+ importOffset = 50; // TotWhImp - Total Wh Imported (acc32)
649
+ energySFOffset = 4; // TotWh_SF - Total Energy scale factor
650
+ break;
651
+ default:
652
+ console.error(`Unknown meter model ${model.id}, using Model 201 defaults`);
653
+ powerOffset = 18;
654
+ powerSFOffset = 21;
655
+ freqOffset = 32;
656
+ freqSFOffset = 35;
657
+ exportOffset = 38;
658
+ importOffset = 46;
659
+ energySFOffset = 4;
660
+ break;
661
+ }
622
662
  // Read scale factors
623
663
  const powerSF = await this.readRegisterValue(baseAddr + powerSFOffset, 1, 'int16');
624
664
  const freqSF = await this.readRegisterValue(baseAddr + freqSFOffset, 1, 'int16');
@@ -835,7 +875,7 @@ export class SunspecModbusClient {
835
875
  blockAddress: model.address,
836
876
  blockLength: model.length,
837
877
  // Connection control - Offsets 0-2
838
- Conn_WinTms: await this.readRegisterValue(baseAddr + 0, 1, 'uint16'),
878
+ Conn_WinTms: await this.readRegisterValue(baseAddr, 1, 'uint16'),
839
879
  Conn_RvrtTms: await this.readRegisterValue(baseAddr + 1, 1, 'uint16'),
840
880
  Conn: await this.readRegisterValue(baseAddr + 2, 1, 'uint16'),
841
881
  // Power limit control - Offsets 3-7
package/dist/version.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  /**
6
6
  * Current version of the enyo Energy App SDK.
7
7
  */
8
- export declare const SDK_VERSION = "0.0.8";
8
+ export declare const SDK_VERSION = "0.0.9";
9
9
  /**
10
10
  * Gets the current SDK version.
11
11
  * @returns The semantic version string of the SDK
package/dist/version.js CHANGED
@@ -5,7 +5,7 @@
5
5
  /**
6
6
  * Current version of the enyo Energy App SDK.
7
7
  */
8
- export const SDK_VERSION = '0.0.8';
8
+ export const SDK_VERSION = '0.0.9';
9
9
  /**
10
10
  * Gets the current SDK version.
11
11
  * @returns The semantic version string of the SDK
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enyo-energy/sunspec-sdk",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "description": "enyo Energy Sunspec SDK",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",