@enyo-energy/sunspec-sdk 0.0.58 → 0.0.59

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.
@@ -584,7 +584,7 @@ class SunspecModbusClient {
584
584
  return value.replace(/\u0000/g, '').trim();
585
585
  }
586
586
  /**
587
- * Read an entire model's register block in a single Modbus call.
587
+ * Read an entire model's register block, chunking if needed.
588
588
  * Returns a Buffer containing all registers for the model.
589
589
  */
590
590
  async readModelBlock(unitId, model) {
@@ -593,12 +593,21 @@ class SunspecModbusClient {
593
593
  // This way buffer offsets match the convention used throughout: offset 0 = model ID,
594
594
  // offset 1 = model length, offset 2 = first data register, etc.
595
595
  const totalRegisters = model.length + 2;
596
- const result = await reader.readHoldingRegisters(model.address, totalRegisters);
597
- if (!result.success || !result.value) {
598
- throw new Error(`Failed to read model block ${model.id} at address ${model.address} (unit ${unitId}): ${result.error?.message || 'Unknown error'}`);
596
+ // Modbus FC03 caps a single read at 125 registers. Float models (211–214) have
597
+ // length 124, which combined with the 2-register header (126) exceeds the limit,
598
+ // so chunk reads larger than 125 registers and concatenate the results.
599
+ const MAX_REGISTERS_PER_READ = 125;
600
+ const chunks = [];
601
+ for (let offset = 0; offset < totalRegisters; offset += MAX_REGISTERS_PER_READ) {
602
+ const quantity = Math.min(MAX_REGISTERS_PER_READ, totalRegisters - offset);
603
+ const result = await reader.readHoldingRegisters(model.address + offset, quantity);
604
+ if (!result.success || !result.value) {
605
+ throw new Error(`Failed to read model block ${model.id} at address ${model.address + offset} (unit ${unitId}): ${result.error?.message || 'Unknown error'}`);
606
+ }
607
+ chunks.push(result.value);
599
608
  }
600
609
  this.connectionHealth.recordSuccess();
601
- return result.value;
610
+ return chunks.length === 1 ? chunks[0] : Buffer.concat(chunks);
602
611
  }
603
612
  /**
604
613
  * Extract a typed value from a model block buffer at a given register offset.
@@ -180,7 +180,7 @@ export declare class SunspecModbusClient {
180
180
  */
181
181
  private cleanString;
182
182
  /**
183
- * Read an entire model's register block in a single Modbus call.
183
+ * Read an entire model's register block, chunking if needed.
184
184
  * Returns a Buffer containing all registers for the model.
185
185
  */
186
186
  private readModelBlock;
@@ -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.58';
12
+ exports.SDK_VERSION = '0.0.59';
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.58";
8
+ export declare const SDK_VERSION = "0.0.59";
9
9
  /**
10
10
  * Gets the current SDK version.
11
11
  * @returns The semantic version string of the SDK
@@ -180,7 +180,7 @@ export declare class SunspecModbusClient {
180
180
  */
181
181
  private cleanString;
182
182
  /**
183
- * Read an entire model's register block in a single Modbus call.
183
+ * Read an entire model's register block, chunking if needed.
184
184
  * Returns a Buffer containing all registers for the model.
185
185
  */
186
186
  private readModelBlock;
@@ -579,7 +579,7 @@ export class SunspecModbusClient {
579
579
  return value.replace(/\u0000/g, '').trim();
580
580
  }
581
581
  /**
582
- * Read an entire model's register block in a single Modbus call.
582
+ * Read an entire model's register block, chunking if needed.
583
583
  * Returns a Buffer containing all registers for the model.
584
584
  */
585
585
  async readModelBlock(unitId, model) {
@@ -588,12 +588,21 @@ export class SunspecModbusClient {
588
588
  // This way buffer offsets match the convention used throughout: offset 0 = model ID,
589
589
  // offset 1 = model length, offset 2 = first data register, etc.
590
590
  const totalRegisters = model.length + 2;
591
- const result = await reader.readHoldingRegisters(model.address, totalRegisters);
592
- if (!result.success || !result.value) {
593
- throw new Error(`Failed to read model block ${model.id} at address ${model.address} (unit ${unitId}): ${result.error?.message || 'Unknown error'}`);
591
+ // Modbus FC03 caps a single read at 125 registers. Float models (211–214) have
592
+ // length 124, which combined with the 2-register header (126) exceeds the limit,
593
+ // so chunk reads larger than 125 registers and concatenate the results.
594
+ const MAX_REGISTERS_PER_READ = 125;
595
+ const chunks = [];
596
+ for (let offset = 0; offset < totalRegisters; offset += MAX_REGISTERS_PER_READ) {
597
+ const quantity = Math.min(MAX_REGISTERS_PER_READ, totalRegisters - offset);
598
+ const result = await reader.readHoldingRegisters(model.address + offset, quantity);
599
+ if (!result.success || !result.value) {
600
+ throw new Error(`Failed to read model block ${model.id} at address ${model.address + offset} (unit ${unitId}): ${result.error?.message || 'Unknown error'}`);
601
+ }
602
+ chunks.push(result.value);
594
603
  }
595
604
  this.connectionHealth.recordSuccess();
596
- return result.value;
605
+ return chunks.length === 1 ? chunks[0] : Buffer.concat(chunks);
597
606
  }
598
607
  /**
599
608
  * Extract a typed value from a model block buffer at a given register offset.
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.58";
8
+ export declare const SDK_VERSION = "0.0.59";
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.58';
8
+ export const SDK_VERSION = '0.0.59';
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.58",
3
+ "version": "0.0.59",
4
4
  "description": "enyo Energy Sunspec SDK",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -37,7 +37,7 @@
37
37
  "typescript": "^5.8.3"
38
38
  },
39
39
  "dependencies": {
40
- "@enyo-energy/energy-app-sdk": "^0.0.121"
40
+ "@enyo-energy/energy-app-sdk": "^0.0.122"
41
41
  },
42
42
  "volta": {
43
43
  "node": "22.17.0"