@enyo-energy/sunspec-sdk 0.0.3 → 0.0.5
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 +46 -12
- package/dist/cjs/sunspec-modbus-client.d.cts +9 -1
- package/dist/cjs/version.cjs +1 -1
- package/dist/cjs/version.d.cts +1 -1
- package/dist/sunspec-modbus-client.d.ts +9 -1
- package/dist/sunspec-modbus-client.js +46 -12
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
|
@@ -51,29 +51,63 @@ class SunspecModbusClient {
|
|
|
51
51
|
this.scaleFactors = {};
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Detect the base address and addressing mode (0-based or 1-based) for SunSpec
|
|
56
|
+
*/
|
|
57
|
+
async detectSunspecBaseAddress() {
|
|
58
|
+
if (!this.modbusClient) {
|
|
59
|
+
throw new Error('Modbus client not initialized');
|
|
60
|
+
}
|
|
61
|
+
// Try 1-based addressing first (most common)
|
|
62
|
+
try {
|
|
63
|
+
const sunspecId = await this.modbusClient.readRegisterStringValue(40001, 2);
|
|
64
|
+
if (sunspecId.includes('SunS')) {
|
|
65
|
+
console.log('Detected 1-based addressing mode (base address: 40001)');
|
|
66
|
+
this.baseAddress = 40001;
|
|
67
|
+
return {
|
|
68
|
+
baseAddress: 40001,
|
|
69
|
+
isZeroBased: false,
|
|
70
|
+
nextAddress: 40003
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
console.debug('Could not read SunS at 40001:', error);
|
|
76
|
+
}
|
|
77
|
+
// Try 0-based addressing
|
|
78
|
+
try {
|
|
79
|
+
const sunspecId = await this.modbusClient.readRegisterStringValue(40000, 2);
|
|
80
|
+
if (sunspecId.includes('SunS')) {
|
|
81
|
+
console.log('Detected 0-based addressing mode (base address: 40000)');
|
|
82
|
+
this.baseAddress = 40000;
|
|
83
|
+
return {
|
|
84
|
+
baseAddress: 40000,
|
|
85
|
+
isZeroBased: true,
|
|
86
|
+
nextAddress: 40002
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
console.debug('Could not read SunS at 40000:', error);
|
|
92
|
+
}
|
|
93
|
+
throw new Error('Device is not SunSpec compliant - "SunS" identifier not found at addresses 40000 or 40001');
|
|
94
|
+
}
|
|
54
95
|
/**
|
|
55
96
|
* Discover all available Sunspec models
|
|
56
|
-
*
|
|
97
|
+
* Automatically detects base address (40000 or 40001) and scans from there
|
|
57
98
|
*/
|
|
58
99
|
async discoverModels() {
|
|
59
100
|
if (!this.connected) {
|
|
60
101
|
throw new Error('Not connected to Modbus device');
|
|
61
102
|
}
|
|
62
103
|
this.discoveredModels.clear();
|
|
63
|
-
let currentAddress = this.baseAddress;
|
|
64
104
|
const maxAddress = 50000; // Safety limit
|
|
105
|
+
let currentAddress = 0;
|
|
65
106
|
console.log('Starting Sunspec model discovery...');
|
|
66
107
|
try {
|
|
67
|
-
//
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
const sunspecId = await this.modbusClient.readRegisterStringValue(40001, 2);
|
|
72
|
-
if (!sunspecId.includes('SunS')) {
|
|
73
|
-
console.warn('Device may not be Sunspec compliant - missing SunS identifier');
|
|
74
|
-
}
|
|
75
|
-
// Start scanning after the SunS identifier
|
|
76
|
-
currentAddress = 40003;
|
|
108
|
+
// Detect the base address and addressing mode
|
|
109
|
+
const addressInfo = await this.detectSunspecBaseAddress();
|
|
110
|
+
currentAddress = addressInfo.nextAddress;
|
|
77
111
|
while (currentAddress < maxAddress) {
|
|
78
112
|
// Read model ID and length
|
|
79
113
|
if (!this.modbusClient) {
|
|
@@ -19,9 +19,17 @@ export declare class SunspecModbusClient {
|
|
|
19
19
|
* Disconnect from Modbus device
|
|
20
20
|
*/
|
|
21
21
|
disconnect(): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Detect the base address and addressing mode (0-based or 1-based) for SunSpec
|
|
24
|
+
*/
|
|
25
|
+
detectSunspecBaseAddress(): Promise<{
|
|
26
|
+
baseAddress: number;
|
|
27
|
+
isZeroBased: boolean;
|
|
28
|
+
nextAddress: number;
|
|
29
|
+
}>;
|
|
22
30
|
/**
|
|
23
31
|
* Discover all available Sunspec models
|
|
24
|
-
*
|
|
32
|
+
* Automatically detects base address (40000 or 40001) and scans from there
|
|
25
33
|
*/
|
|
26
34
|
discoverModels(): Promise<Map<number, SunspecModel>>;
|
|
27
35
|
/**
|
package/dist/cjs/version.cjs
CHANGED
package/dist/cjs/version.d.cts
CHANGED
|
@@ -19,9 +19,17 @@ export declare class SunspecModbusClient {
|
|
|
19
19
|
* Disconnect from Modbus device
|
|
20
20
|
*/
|
|
21
21
|
disconnect(): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Detect the base address and addressing mode (0-based or 1-based) for SunSpec
|
|
24
|
+
*/
|
|
25
|
+
detectSunspecBaseAddress(): Promise<{
|
|
26
|
+
baseAddress: number;
|
|
27
|
+
isZeroBased: boolean;
|
|
28
|
+
nextAddress: number;
|
|
29
|
+
}>;
|
|
22
30
|
/**
|
|
23
31
|
* Discover all available Sunspec models
|
|
24
|
-
*
|
|
32
|
+
* Automatically detects base address (40000 or 40001) and scans from there
|
|
25
33
|
*/
|
|
26
34
|
discoverModels(): Promise<Map<number, SunspecModel>>;
|
|
27
35
|
/**
|
|
@@ -48,29 +48,63 @@ export class SunspecModbusClient {
|
|
|
48
48
|
this.scaleFactors = {};
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Detect the base address and addressing mode (0-based or 1-based) for SunSpec
|
|
53
|
+
*/
|
|
54
|
+
async detectSunspecBaseAddress() {
|
|
55
|
+
if (!this.modbusClient) {
|
|
56
|
+
throw new Error('Modbus client not initialized');
|
|
57
|
+
}
|
|
58
|
+
// Try 1-based addressing first (most common)
|
|
59
|
+
try {
|
|
60
|
+
const sunspecId = await this.modbusClient.readRegisterStringValue(40001, 2);
|
|
61
|
+
if (sunspecId.includes('SunS')) {
|
|
62
|
+
console.log('Detected 1-based addressing mode (base address: 40001)');
|
|
63
|
+
this.baseAddress = 40001;
|
|
64
|
+
return {
|
|
65
|
+
baseAddress: 40001,
|
|
66
|
+
isZeroBased: false,
|
|
67
|
+
nextAddress: 40003
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
console.debug('Could not read SunS at 40001:', error);
|
|
73
|
+
}
|
|
74
|
+
// Try 0-based addressing
|
|
75
|
+
try {
|
|
76
|
+
const sunspecId = await this.modbusClient.readRegisterStringValue(40000, 2);
|
|
77
|
+
if (sunspecId.includes('SunS')) {
|
|
78
|
+
console.log('Detected 0-based addressing mode (base address: 40000)');
|
|
79
|
+
this.baseAddress = 40000;
|
|
80
|
+
return {
|
|
81
|
+
baseAddress: 40000,
|
|
82
|
+
isZeroBased: true,
|
|
83
|
+
nextAddress: 40002
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
console.debug('Could not read SunS at 40000:', error);
|
|
89
|
+
}
|
|
90
|
+
throw new Error('Device is not SunSpec compliant - "SunS" identifier not found at addresses 40000 or 40001');
|
|
91
|
+
}
|
|
51
92
|
/**
|
|
52
93
|
* Discover all available Sunspec models
|
|
53
|
-
*
|
|
94
|
+
* Automatically detects base address (40000 or 40001) and scans from there
|
|
54
95
|
*/
|
|
55
96
|
async discoverModels() {
|
|
56
97
|
if (!this.connected) {
|
|
57
98
|
throw new Error('Not connected to Modbus device');
|
|
58
99
|
}
|
|
59
100
|
this.discoveredModels.clear();
|
|
60
|
-
let currentAddress = this.baseAddress;
|
|
61
101
|
const maxAddress = 50000; // Safety limit
|
|
102
|
+
let currentAddress = 0;
|
|
62
103
|
console.log('Starting Sunspec model discovery...');
|
|
63
104
|
try {
|
|
64
|
-
//
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
const sunspecId = await this.modbusClient.readRegisterStringValue(40001, 2);
|
|
69
|
-
if (!sunspecId.includes('SunS')) {
|
|
70
|
-
console.warn('Device may not be Sunspec compliant - missing SunS identifier');
|
|
71
|
-
}
|
|
72
|
-
// Start scanning after the SunS identifier
|
|
73
|
-
currentAddress = 40003;
|
|
105
|
+
// Detect the base address and addressing mode
|
|
106
|
+
const addressInfo = await this.detectSunspecBaseAddress();
|
|
107
|
+
currentAddress = addressInfo.nextAddress;
|
|
74
108
|
while (currentAddress < maxAddress) {
|
|
75
109
|
// Read model ID and length
|
|
76
110
|
if (!this.modbusClient) {
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enyo-energy/sunspec-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
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.
|
|
40
|
+
"@enyo-energy/energy-app-sdk": "^0.0.39"
|
|
41
41
|
},
|
|
42
42
|
"volta": {
|
|
43
43
|
"node": "22.17.0"
|