@enyo-energy/sunspec-sdk 0.0.105 → 1.0.0
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/README.md +90 -0
- package/dist/cjs/sunspec-devices.cjs +104 -9
- package/dist/cjs/sunspec-devices.d.cts +32 -3
- package/dist/cjs/sunspec-interfaces.d.cts +62 -0
- package/dist/cjs/sunspec-modbus-client.cjs +256 -105
- package/dist/cjs/sunspec-modbus-client.d.cts +82 -5
- package/dist/cjs/version.cjs +1 -1
- package/dist/cjs/version.d.cts +1 -1
- package/dist/sunspec-devices.d.ts +32 -3
- package/dist/sunspec-devices.js +104 -9
- package/dist/sunspec-interfaces.d.ts +62 -0
- package/dist/sunspec-modbus-client.d.ts +82 -5
- package/dist/sunspec-modbus-client.js +253 -104
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SunspecModbusClient = exports.ModbusOperationTimeoutError = void 0;
|
|
3
|
+
exports.SunspecModbusClient = exports.SunspecUnavailableError = exports.ModbusOperationTimeoutError = void 0;
|
|
4
|
+
exports.isSunspecUnavailableError = isSunspecUnavailableError;
|
|
4
5
|
exports.getOrCreateSunspecClient = getOrCreateSunspecClient;
|
|
5
6
|
exports.releaseSunspecClient = releaseSunspecClient;
|
|
6
7
|
exports.retryAsync = retryAsync;
|
|
@@ -41,8 +42,66 @@ class ModbusOperationTimeoutError extends Error {
|
|
|
41
42
|
this.timeoutMs = timeoutMs;
|
|
42
43
|
this.name = 'ModbusOperationTimeoutError';
|
|
43
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* `Error` has no enumerable own properties, so a consumer that logs `{ err }` through a
|
|
47
|
+
* JSON serializer emits `{}` and loses the message entirely. Give every error this client
|
|
48
|
+
* rejects with an explicit JSON shape so it survives `JSON.stringify` with a usable message.
|
|
49
|
+
*/
|
|
50
|
+
toJSON() {
|
|
51
|
+
return {
|
|
52
|
+
name: this.name,
|
|
53
|
+
message: this.message,
|
|
54
|
+
operation: this.operation,
|
|
55
|
+
unitId: this.unitId,
|
|
56
|
+
timeoutMs: this.timeoutMs
|
|
57
|
+
};
|
|
58
|
+
}
|
|
44
59
|
}
|
|
45
60
|
exports.ModbusOperationTimeoutError = ModbusOperationTimeoutError;
|
|
61
|
+
/**
|
|
62
|
+
* Thrown when the client refuses a transaction because the unit is **already known to be down**,
|
|
63
|
+
* as opposed to a transaction that was actually attempted and failed.
|
|
64
|
+
*
|
|
65
|
+
* The distinction matters for logging. A poisoned socket produces exactly one genuine event (the
|
|
66
|
+
* timeout that poisoned it), but every read that lands during the outage would otherwise throw an
|
|
67
|
+
* error indistinguishable from real I/O failure — so a consumer catching per read has no choice but
|
|
68
|
+
* to log each one at ERROR. Callers should log the first {@link SunspecUnavailableError} of an
|
|
69
|
+
* outage (or nothing at all: the SDK already logs the transition) and stay quiet on the rest.
|
|
70
|
+
*
|
|
71
|
+
* {@link sinceMs} is how long the unit has been in this state, so a consumer that does want one
|
|
72
|
+
* line can say how stale the link is without tracking the outage itself.
|
|
73
|
+
*/
|
|
74
|
+
class SunspecUnavailableError extends Error {
|
|
75
|
+
reason;
|
|
76
|
+
unitId;
|
|
77
|
+
sinceMs;
|
|
78
|
+
constructor(reason, unitId, sinceMs) {
|
|
79
|
+
super(`Modbus unit ${unitId} is unavailable (${reason}, for ${sinceMs}ms) — ` +
|
|
80
|
+
`transaction refused without attempting I/O`);
|
|
81
|
+
this.reason = reason;
|
|
82
|
+
this.unitId = unitId;
|
|
83
|
+
this.sinceMs = sinceMs;
|
|
84
|
+
this.name = 'SunspecUnavailableError';
|
|
85
|
+
}
|
|
86
|
+
/** See {@link ModbusOperationTimeoutError.toJSON}. */
|
|
87
|
+
toJSON() {
|
|
88
|
+
return {
|
|
89
|
+
name: this.name,
|
|
90
|
+
message: this.message,
|
|
91
|
+
reason: this.reason,
|
|
92
|
+
unitId: this.unitId,
|
|
93
|
+
sinceMs: this.sinceMs
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.SunspecUnavailableError = SunspecUnavailableError;
|
|
98
|
+
/**
|
|
99
|
+
* Type guard for {@link SunspecUnavailableError}. Prefer this over `instanceof` at package
|
|
100
|
+
* boundaries, where a duplicated copy of the SDK in the module graph would break identity.
|
|
101
|
+
*/
|
|
102
|
+
function isSunspecUnavailableError(error) {
|
|
103
|
+
return error instanceof Error && error.name === 'SunspecUnavailableError';
|
|
104
|
+
}
|
|
46
105
|
/**
|
|
47
106
|
* Module-level registry: one SunspecModbusClient per network device (host:port).
|
|
48
107
|
* Refcounted so the underlying connection only tears down when the last consumer releases.
|
|
@@ -53,7 +112,7 @@ const registryKey = (host, port) => `${host}:${port}`;
|
|
|
53
112
|
* Get (or create) the singleton SunspecModbusClient for this network device.
|
|
54
113
|
* Increments the refcount; pair with `releaseSunspecClient` on teardown.
|
|
55
114
|
*
|
|
56
|
-
* NOTE: `
|
|
115
|
+
* NOTE: `transport`, `resilience` and `modbusFactory` are only applied when the client is FIRST
|
|
57
116
|
* created for a given host:port. Because the client is cached and refcounted, a later caller
|
|
58
117
|
* passing different config receives the already-created instance and its config is ignored.
|
|
59
118
|
*
|
|
@@ -61,11 +120,11 @@ const registryKey = (host, port) => `${host}:${port}`;
|
|
|
61
120
|
* opens a per-unit connection) instead of the one from `energyApp.useModbus()` — e.g. a mock for
|
|
62
121
|
* tests, or an alternative transport. When provided, `energyApp` may be passed as `undefined`.
|
|
63
122
|
*/
|
|
64
|
-
function getOrCreateSunspecClient(energyApp, host, port = 502,
|
|
123
|
+
function getOrCreateSunspecClient(energyApp, host, port = 502, transport, resilience, modbusFactory) {
|
|
65
124
|
const key = registryKey(host, port);
|
|
66
125
|
let entry = CLIENT_REGISTRY.get(key);
|
|
67
126
|
if (!entry) {
|
|
68
|
-
entry = { client: new SunspecModbusClient(energyApp,
|
|
127
|
+
entry = { client: new SunspecModbusClient(energyApp, transport, resilience, modbusFactory), refcount: 0 };
|
|
69
128
|
CLIENT_REGISTRY.set(key, entry);
|
|
70
129
|
}
|
|
71
130
|
entry.refcount++;
|
|
@@ -130,7 +189,7 @@ async function retryAsync(fn, opts) {
|
|
|
130
189
|
}
|
|
131
190
|
class SunspecModbusClient {
|
|
132
191
|
energyApp;
|
|
133
|
-
|
|
192
|
+
transport;
|
|
134
193
|
modbusFactory;
|
|
135
194
|
// Per-unit Modbus instance/reader/discovered-models maps. One client = one network device,
|
|
136
195
|
// many unit IDs share that client (each unit ID is one EnergyAppModbusInstance underneath).
|
|
@@ -171,18 +230,29 @@ class SunspecModbusClient {
|
|
|
171
230
|
// transaction's framing. So a poisoned unit refuses further I/O until reconnectUnit() tears
|
|
172
231
|
// the socket down and reopens it (which clears the flag).
|
|
173
232
|
poisonedUnits = new Set();
|
|
233
|
+
// Wall-clock of the transition INTO the poisoned state, per unit. Survives the close half of a
|
|
234
|
+
// recycle (`_closeUnit` clears the poison flag, not this) so the reopen can report how long the
|
|
235
|
+
// outage lasted. Cleared on the recovery log, which is the one place the outage is considered
|
|
236
|
+
// over. Presence here is "was poisoned at some point since the last successful open".
|
|
237
|
+
poisonedAtByUnit = new Map();
|
|
174
238
|
// Wall-clock of each unit's last SUCCESSFUL transaction. Drives half-open detection: a socket
|
|
175
239
|
// the transport still reports connected but that has gone quiet past staleSocketMs is presumed
|
|
176
240
|
// dead. Absent entry = no successful op yet (never treated as stale — give it a chance).
|
|
177
241
|
lastOkAtByUnit = new Map();
|
|
242
|
+
// Consecutive failed (re)connect attempts, keyed by attempt target. Drives transition-only
|
|
243
|
+
// logging: the first failure of a run is the news, every repeat while the peer stays down is
|
|
244
|
+
// the same news again. Cleared on the first success for that key.
|
|
245
|
+
consecutiveConnectFailures = new Map();
|
|
178
246
|
constructor(
|
|
179
247
|
// The host application. Only used to obtain the default Modbus backend via
|
|
180
248
|
// `energyApp.useModbus()`. May be omitted (`undefined`) when a `modbusFactory` is supplied.
|
|
181
249
|
energyApp,
|
|
182
|
-
// Opt-in
|
|
183
|
-
// serializes frames (`noParallelRequests`)
|
|
184
|
-
//
|
|
185
|
-
|
|
250
|
+
// Opt-in transport options (all default off). Passed straight through to
|
|
251
|
+
// `useModbus().connect()`, which serializes frames (`noParallelRequests`), spaces them
|
|
252
|
+
// (`waitBetweenMessagesMs`) and decides whether the socket comes from the host's shared pool
|
|
253
|
+
// (`pooledConnection`). An empty object leaves them all undefined so the SDK applies its own
|
|
254
|
+
// defaults. Typed as the superset so a plain IModbusPacingConfig still assigns.
|
|
255
|
+
transport = {},
|
|
186
256
|
// Per-operation timeouts + half-open detection. Merged with DEFAULT_MODBUS_RESILIENCE_CONFIG
|
|
187
257
|
// so omitted fields keep their defaults.
|
|
188
258
|
resilience = {},
|
|
@@ -194,7 +264,7 @@ class SunspecModbusClient {
|
|
|
194
264
|
// connections on its own schedule and needs a factory to call.
|
|
195
265
|
modbusFactory) {
|
|
196
266
|
this.energyApp = energyApp;
|
|
197
|
-
this.
|
|
267
|
+
this.transport = transport;
|
|
198
268
|
this.modbusFactory = modbusFactory;
|
|
199
269
|
if (!energyApp && !modbusFactory) {
|
|
200
270
|
throw new Error("SunspecModbusClient requires either an EnergyApp or a modbusFactory");
|
|
@@ -365,21 +435,29 @@ class SunspecModbusClient {
|
|
|
365
435
|
}
|
|
366
436
|
const { primaryHost, secondaryHost, port } = this.connectionParams;
|
|
367
437
|
const units = [...this.knownUnits];
|
|
368
|
-
|
|
438
|
+
const failureKey = 'reconnect:all';
|
|
439
|
+
const retrying = this.isRetryingAfterFailure(failureKey);
|
|
440
|
+
const logAttempt = (message) => { if (retrying)
|
|
441
|
+
console.debug(message);
|
|
442
|
+
else
|
|
443
|
+
console.log(message); };
|
|
444
|
+
logAttempt(`Attempting to reconnect to primary host ${primaryHost}:${port} units [${units.join(',')}]...`);
|
|
369
445
|
const primarySuccess = await this.attemptConnection(primaryHost, port, units);
|
|
370
446
|
if (primarySuccess) {
|
|
447
|
+
this.clearConnectFailures(failureKey);
|
|
371
448
|
console.log(`Successfully reconnected to primary host ${primaryHost}:${port} units [${units.join(',')}]`);
|
|
372
449
|
return true;
|
|
373
450
|
}
|
|
374
451
|
if (secondaryHost && secondaryHost !== primaryHost) {
|
|
375
|
-
|
|
452
|
+
logAttempt(`Primary host failed, attempting secondary host ${secondaryHost}:${port} units [${units.join(',')}]...`);
|
|
376
453
|
const secondarySuccess = await this.attemptConnection(secondaryHost, port, units);
|
|
377
454
|
if (secondarySuccess) {
|
|
455
|
+
this.clearConnectFailures(failureKey);
|
|
378
456
|
console.log(`Successfully reconnected to secondary host ${secondaryHost}:${port} units [${units.join(',')}]`);
|
|
379
457
|
return true;
|
|
380
458
|
}
|
|
381
459
|
}
|
|
382
|
-
|
|
460
|
+
this.logConnectFailure(failureKey, `Reconnection failed to all available hosts`);
|
|
383
461
|
return false;
|
|
384
462
|
});
|
|
385
463
|
}
|
|
@@ -397,21 +475,29 @@ class SunspecModbusClient {
|
|
|
397
475
|
return false;
|
|
398
476
|
}
|
|
399
477
|
const { primaryHost, secondaryHost, port } = this.connectionParams;
|
|
400
|
-
|
|
478
|
+
const failureKey = `reconnect:unit${unitId}`;
|
|
479
|
+
const retrying = this.isRetryingAfterFailure(failureKey);
|
|
480
|
+
const logAttempt = (message) => { if (retrying)
|
|
481
|
+
console.debug(message);
|
|
482
|
+
else
|
|
483
|
+
console.log(message); };
|
|
484
|
+
logAttempt(`Attempting to reconnect unit ${unitId} on primary host ${primaryHost}:${port}...`);
|
|
401
485
|
const primarySuccess = await this.attemptConnection(primaryHost, port, [unitId]);
|
|
402
486
|
if (primarySuccess) {
|
|
487
|
+
this.clearConnectFailures(failureKey);
|
|
403
488
|
console.log(`Successfully reconnected unit ${unitId} on primary host ${primaryHost}:${port}`);
|
|
404
489
|
return true;
|
|
405
490
|
}
|
|
406
491
|
if (secondaryHost && secondaryHost !== primaryHost) {
|
|
407
|
-
|
|
492
|
+
logAttempt(`Primary host failed for unit ${unitId}, attempting secondary host ${secondaryHost}:${port}...`);
|
|
408
493
|
const secondarySuccess = await this.attemptConnection(secondaryHost, port, [unitId]);
|
|
409
494
|
if (secondarySuccess) {
|
|
495
|
+
this.clearConnectFailures(failureKey);
|
|
410
496
|
console.log(`Successfully reconnected unit ${unitId} on secondary host ${secondaryHost}:${port}`);
|
|
411
497
|
return true;
|
|
412
498
|
}
|
|
413
499
|
}
|
|
414
|
-
|
|
500
|
+
this.logConnectFailure(failureKey, `Reconnection failed for unit ${unitId} on all available hosts`);
|
|
415
501
|
return false;
|
|
416
502
|
});
|
|
417
503
|
}
|
|
@@ -426,15 +512,17 @@ class SunspecModbusClient {
|
|
|
426
512
|
await this._closeUnit(unitId);
|
|
427
513
|
}
|
|
428
514
|
}
|
|
515
|
+
const failureKey = `connect:${host}:${port}:[${units.join(',')}]`;
|
|
429
516
|
try {
|
|
430
517
|
for (const unitId of units) {
|
|
431
518
|
await this._openUnit(host, port, unitId);
|
|
432
519
|
}
|
|
520
|
+
this.clearConnectFailures(failureKey);
|
|
433
521
|
console.log(`Connection attempt to ${host}:${port} units [${units.join(',')}] succeeded (opens=${this.openCount}, closes=${this.closeCount}, openUnits=${this.modbusInstances.size})`);
|
|
434
522
|
return true;
|
|
435
523
|
}
|
|
436
524
|
catch (error) {
|
|
437
|
-
|
|
525
|
+
this.logConnectFailure(failureKey, `Connection attempt to ${host}:${port} failed: ${error}`);
|
|
438
526
|
return false;
|
|
439
527
|
}
|
|
440
528
|
}
|
|
@@ -516,8 +604,9 @@ class SunspecModbusClient {
|
|
|
516
604
|
key: this.connectionParams?.key,
|
|
517
605
|
ca: this.connectionParams?.ca,
|
|
518
606
|
rejectUnauthorized: this.connectionParams?.rejectUnauthorized,
|
|
519
|
-
noParallelRequests: this.
|
|
520
|
-
waitBetweenMessagesMs: this.
|
|
607
|
+
noParallelRequests: this.transport.noParallelRequests,
|
|
608
|
+
waitBetweenMessagesMs: this.transport.waitBetweenMessagesMs,
|
|
609
|
+
pooledConnection: this.transport.pooledConnection
|
|
521
610
|
}));
|
|
522
611
|
if (!candidate) {
|
|
523
612
|
throw new Error(`useModbus().connect returned null for ${host}:${port} unit ${unitId}`);
|
|
@@ -528,6 +617,7 @@ class SunspecModbusClient {
|
|
|
528
617
|
// Fresh socket: clear any prior poison and start the freshness clock so a just-opened
|
|
529
618
|
// unit isn't immediately judged stale.
|
|
530
619
|
this.poisonedUnits.delete(unitId);
|
|
620
|
+
this.logPoisonRecovery(unitId);
|
|
531
621
|
this.lastOkAtByUnit.set(unitId, Date.now());
|
|
532
622
|
this.connectionHealth.recordSuccess();
|
|
533
623
|
this.recordOpen();
|
|
@@ -552,7 +642,9 @@ class SunspecModbusClient {
|
|
|
552
642
|
this.faultTolerantReaders.delete(unitId);
|
|
553
643
|
this.discoveredModelsByUnit.delete(unitId);
|
|
554
644
|
this.discoveredModelListByUnit.delete(unitId);
|
|
555
|
-
// Drop per-unit resilience state so a later reopen starts clean.
|
|
645
|
+
// Drop per-unit resilience state so a later reopen starts clean. `poisonedAtByUnit` is
|
|
646
|
+
// deliberately NOT dropped: a recycle closes before it reopens, and the reopen is where the
|
|
647
|
+
// recovery line reports how long the unit was down.
|
|
556
648
|
this.poisonedUnits.delete(unitId);
|
|
557
649
|
this.lastOkAtByUnit.delete(unitId);
|
|
558
650
|
if (instance) {
|
|
@@ -612,7 +704,10 @@ class SunspecModbusClient {
|
|
|
612
704
|
*/
|
|
613
705
|
async guardTransaction(unitId, fn) {
|
|
614
706
|
if (this.poisonedUnits.has(unitId)) {
|
|
615
|
-
|
|
707
|
+
// Known-down, not newly-failed: a typed rejection so callers can stay quiet for the
|
|
708
|
+
// duration of an outage the SDK has already logged once. See SunspecUnavailableError.
|
|
709
|
+
const since = this.poisonedAtByUnit.get(unitId);
|
|
710
|
+
throw new SunspecUnavailableError('socket-poisoned', unitId, since === undefined ? 0 : Date.now() - since);
|
|
616
711
|
}
|
|
617
712
|
try {
|
|
618
713
|
const result = await this.withTimeout('transaction', unitId, this.resilience.readTimeoutMs, fn);
|
|
@@ -641,17 +736,72 @@ class SunspecModbusClient {
|
|
|
641
736
|
clearTimeout(timer);
|
|
642
737
|
});
|
|
643
738
|
}
|
|
739
|
+
/**
|
|
740
|
+
* Log a failed Modbus transaction from a reader/writer catch block.
|
|
741
|
+
*
|
|
742
|
+
* A {@link SunspecUnavailableError} is not a failure — it is this client refusing I/O on a link
|
|
743
|
+
* it has already reported dead once (one WARN on the transition, one INFO on recovery). Logging
|
|
744
|
+
* it at ERROR once per read, per read path, per poll cycle, for the whole outage, is what buries
|
|
745
|
+
* the errors that are actually actionable. So it drops to debug; everything else stays ERROR.
|
|
746
|
+
*/
|
|
747
|
+
logConnectFailure(key, message) {
|
|
748
|
+
const count = (this.consecutiveConnectFailures.get(key) ?? 0) + 1;
|
|
749
|
+
this.consecutiveConnectFailures.set(key, count);
|
|
750
|
+
if (count === 1) {
|
|
751
|
+
console.error(message);
|
|
752
|
+
}
|
|
753
|
+
else {
|
|
754
|
+
console.debug(`${message} (consecutive failure #${count})`);
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
/** True while `key`'s last attempt failed — used to keep repeat attempt chatter at debug. */
|
|
758
|
+
isRetryingAfterFailure(key) {
|
|
759
|
+
return (this.consecutiveConnectFailures.get(key) ?? 0) > 0;
|
|
760
|
+
}
|
|
761
|
+
/** Forget `key`'s failure run on a success, so the next outage logs its first failure again. */
|
|
762
|
+
clearConnectFailures(key) {
|
|
763
|
+
this.consecutiveConnectFailures.delete(key);
|
|
764
|
+
}
|
|
765
|
+
logTransactionError(context, error) {
|
|
766
|
+
if (isSunspecUnavailableError(error)) {
|
|
767
|
+
console.debug(`${context}: ${error.message}`);
|
|
768
|
+
return;
|
|
769
|
+
}
|
|
770
|
+
console.error(`${context}: ${error}`);
|
|
771
|
+
}
|
|
644
772
|
/**
|
|
645
773
|
* Mark a unit's socket as poisoned after a timeout and reflect the hang in the shared health
|
|
646
774
|
* gate immediately, so isHealthy() flips false this cycle instead of after the coarse
|
|
647
775
|
* 5-failure / 5-minute-staleness thresholds. Idempotent; only logs on the first poison.
|
|
648
776
|
*/
|
|
649
777
|
poisonUnit(unitId, error) {
|
|
778
|
+
this.enterPoisoned(unitId, `${error.message} — poisoning unit ${unitId} socket; reconnect path will recycle it`);
|
|
779
|
+
this.connectionHealth.recordFailure(error);
|
|
780
|
+
}
|
|
781
|
+
/**
|
|
782
|
+
* Enter the poisoned state for a unit, logging the TRANSITION only. Everything downstream of
|
|
783
|
+
* this (every refused read, every poll cycle) is the same known state and must stay silent —
|
|
784
|
+
* one WARN in, one INFO out (see {@link logPoisonRecovery}), nothing in between.
|
|
785
|
+
*/
|
|
786
|
+
enterPoisoned(unitId, reason) {
|
|
650
787
|
if (!this.poisonedUnits.has(unitId)) {
|
|
651
|
-
console.warn(`SunspecModbusClient: ${
|
|
788
|
+
console.warn(`SunspecModbusClient: ${reason}`);
|
|
789
|
+
this.poisonedAtByUnit.set(unitId, Date.now());
|
|
652
790
|
}
|
|
653
791
|
this.poisonedUnits.add(unitId);
|
|
654
|
-
|
|
792
|
+
}
|
|
793
|
+
/**
|
|
794
|
+
* Close out a poisoned episode on a successful (re)open: one INFO carrying how long the unit
|
|
795
|
+
* was refusing I/O. No-op for a unit that was never poisoned, so a normal first connect stays
|
|
796
|
+
* quiet.
|
|
797
|
+
*/
|
|
798
|
+
logPoisonRecovery(unitId) {
|
|
799
|
+
const since = this.poisonedAtByUnit.get(unitId);
|
|
800
|
+
if (since === undefined)
|
|
801
|
+
return;
|
|
802
|
+
this.poisonedAtByUnit.delete(unitId);
|
|
803
|
+
console.info(`SunspecModbusClient: unit ${unitId} socket recovered after reconnect ` +
|
|
804
|
+
`(poisonedForMs=${Date.now() - since})`);
|
|
655
805
|
}
|
|
656
806
|
/**
|
|
657
807
|
* Publicly invalidate a unit's socket so {@link isHealthy} returns false and the next
|
|
@@ -666,10 +816,7 @@ class SunspecModbusClient {
|
|
|
666
816
|
* schedule firing until a real discovery lands. Idempotent; only logs on the first call.
|
|
667
817
|
*/
|
|
668
818
|
invalidateUnit(unitId, reason) {
|
|
669
|
-
|
|
670
|
-
console.warn(`SunspecModbusClient: invalidating unit ${unitId} socket — ${reason}; reconnect path will recycle it`);
|
|
671
|
-
}
|
|
672
|
-
this.poisonedUnits.add(unitId);
|
|
819
|
+
this.enterPoisoned(unitId, `invalidating unit ${unitId} socket — ${reason}; reconnect path will recycle it`);
|
|
673
820
|
this.connectionHealth.recordFailure(new Error(reason));
|
|
674
821
|
}
|
|
675
822
|
/**
|
|
@@ -928,7 +1075,7 @@ class SunspecModbusClient {
|
|
|
928
1075
|
}
|
|
929
1076
|
}
|
|
930
1077
|
catch (error) {
|
|
931
|
-
|
|
1078
|
+
this.logTransactionError(`Error during model discovery at address ${currentAddress} (unit ${unitId})`, error);
|
|
932
1079
|
}
|
|
933
1080
|
if (discovered.length > 0) {
|
|
934
1081
|
// Commit the fresh discovery atomically. Keep the FIRST (lowest-address) instance per
|
|
@@ -1230,7 +1377,7 @@ class SunspecModbusClient {
|
|
|
1230
1377
|
}
|
|
1231
1378
|
catch (error) {
|
|
1232
1379
|
this.connectionHealth.recordFailure(error);
|
|
1233
|
-
|
|
1380
|
+
this.logTransactionError(`Error writing register at address ${address}`, error);
|
|
1234
1381
|
throw error;
|
|
1235
1382
|
}
|
|
1236
1383
|
}
|
|
@@ -1376,7 +1523,7 @@ class SunspecModbusClient {
|
|
|
1376
1523
|
return data;
|
|
1377
1524
|
}
|
|
1378
1525
|
catch (error) {
|
|
1379
|
-
|
|
1526
|
+
this.logTransactionError(`Error reading inverter data`, error);
|
|
1380
1527
|
return null;
|
|
1381
1528
|
}
|
|
1382
1529
|
}
|
|
@@ -1440,7 +1587,7 @@ class SunspecModbusClient {
|
|
|
1440
1587
|
return data;
|
|
1441
1588
|
}
|
|
1442
1589
|
catch (error) {
|
|
1443
|
-
|
|
1590
|
+
this.logTransactionError(`Error reading single phase inverter data`, error);
|
|
1444
1591
|
return null;
|
|
1445
1592
|
}
|
|
1446
1593
|
}
|
|
@@ -1504,7 +1651,7 @@ class SunspecModbusClient {
|
|
|
1504
1651
|
return data;
|
|
1505
1652
|
}
|
|
1506
1653
|
catch (error) {
|
|
1507
|
-
|
|
1654
|
+
this.logTransactionError(`Error reading float inverter data (Model ${blockNumber})`, error);
|
|
1508
1655
|
return null;
|
|
1509
1656
|
}
|
|
1510
1657
|
}
|
|
@@ -1623,7 +1770,7 @@ class SunspecModbusClient {
|
|
|
1623
1770
|
return this.extractMPPTScaleFactors(buffer);
|
|
1624
1771
|
}
|
|
1625
1772
|
catch (error) {
|
|
1626
|
-
|
|
1773
|
+
this.logTransactionError(`Error reading MPPT scale factors (unit ${unitId})`, error);
|
|
1627
1774
|
return null;
|
|
1628
1775
|
}
|
|
1629
1776
|
}
|
|
@@ -1697,7 +1844,7 @@ class SunspecModbusClient {
|
|
|
1697
1844
|
return this.extractMPPTModuleData(buffer, model, moduleId, scaleFactors);
|
|
1698
1845
|
}
|
|
1699
1846
|
catch (error) {
|
|
1700
|
-
|
|
1847
|
+
this.logTransactionError(`Error reading MPPT data for module ${moduleId} (unit ${unitId})`, error);
|
|
1701
1848
|
return null;
|
|
1702
1849
|
}
|
|
1703
1850
|
}
|
|
@@ -1747,7 +1894,7 @@ class SunspecModbusClient {
|
|
|
1747
1894
|
}
|
|
1748
1895
|
}
|
|
1749
1896
|
catch (error) {
|
|
1750
|
-
|
|
1897
|
+
this.logTransactionError(`Error reading all MPPT data`, error);
|
|
1751
1898
|
}
|
|
1752
1899
|
return mpptData;
|
|
1753
1900
|
}
|
|
@@ -2009,7 +2156,7 @@ class SunspecModbusClient {
|
|
|
2009
2156
|
return data;
|
|
2010
2157
|
}
|
|
2011
2158
|
catch (error) {
|
|
2012
|
-
|
|
2159
|
+
this.logTransactionError(`Error reading battery base data`, error);
|
|
2013
2160
|
return null;
|
|
2014
2161
|
}
|
|
2015
2162
|
}
|
|
@@ -2187,7 +2334,7 @@ class SunspecModbusClient {
|
|
|
2187
2334
|
}
|
|
2188
2335
|
}
|
|
2189
2336
|
catch (error) {
|
|
2190
|
-
|
|
2337
|
+
this.logTransactionError(`Error reading battery data`, error);
|
|
2191
2338
|
return null;
|
|
2192
2339
|
}
|
|
2193
2340
|
}
|
|
@@ -2269,7 +2416,7 @@ class SunspecModbusClient {
|
|
|
2269
2416
|
return true;
|
|
2270
2417
|
}
|
|
2271
2418
|
catch (error) {
|
|
2272
|
-
|
|
2419
|
+
this.logTransactionError(`Error writing battery controls`, error);
|
|
2273
2420
|
return false;
|
|
2274
2421
|
}
|
|
2275
2422
|
}
|
|
@@ -2369,7 +2516,7 @@ class SunspecModbusClient {
|
|
|
2369
2516
|
return controls;
|
|
2370
2517
|
}
|
|
2371
2518
|
catch (error) {
|
|
2372
|
-
|
|
2519
|
+
this.logTransactionError(`Error reading battery controls`, error);
|
|
2373
2520
|
return null;
|
|
2374
2521
|
}
|
|
2375
2522
|
}
|
|
@@ -2501,7 +2648,7 @@ class SunspecModbusClient {
|
|
|
2501
2648
|
return data;
|
|
2502
2649
|
}
|
|
2503
2650
|
catch (error) {
|
|
2504
|
-
|
|
2651
|
+
this.logTransactionError(`Error reading meter data`, error);
|
|
2505
2652
|
return null;
|
|
2506
2653
|
}
|
|
2507
2654
|
}
|
|
@@ -2543,7 +2690,7 @@ class SunspecModbusClient {
|
|
|
2543
2690
|
return data;
|
|
2544
2691
|
}
|
|
2545
2692
|
catch (error) {
|
|
2546
|
-
|
|
2693
|
+
this.logTransactionError(`Error reading float meter data (Model ${blockNumber})`, error);
|
|
2547
2694
|
return null;
|
|
2548
2695
|
}
|
|
2549
2696
|
}
|
|
@@ -2621,7 +2768,7 @@ class SunspecModbusClient {
|
|
|
2621
2768
|
return data;
|
|
2622
2769
|
}
|
|
2623
2770
|
catch (error) {
|
|
2624
|
-
|
|
2771
|
+
this.logTransactionError(`Error reading common block`, error);
|
|
2625
2772
|
return null;
|
|
2626
2773
|
}
|
|
2627
2774
|
}
|
|
@@ -2747,7 +2894,7 @@ class SunspecModbusClient {
|
|
|
2747
2894
|
return settings;
|
|
2748
2895
|
}
|
|
2749
2896
|
catch (error) {
|
|
2750
|
-
|
|
2897
|
+
this.logTransactionError(`Error reading inverter settings`, error);
|
|
2751
2898
|
return null;
|
|
2752
2899
|
}
|
|
2753
2900
|
}
|
|
@@ -2764,74 +2911,76 @@ class SunspecModbusClient {
|
|
|
2764
2911
|
try {
|
|
2765
2912
|
// Read entire model block in a single Modbus call
|
|
2766
2913
|
const buffer = await this.readModelBlock(unitId, model);
|
|
2767
|
-
//
|
|
2914
|
+
// Buffer offsets are SunSpec point offsets + 2: readModelBlock() returns the
|
|
2915
|
+
// 2-register model header (ID + length) ahead of the data registers. Scale
|
|
2916
|
+
// factors are points 21-23 -> buffer offsets 23-25.
|
|
2768
2917
|
const scaleFactors = {
|
|
2769
|
-
WMaxLimPct_SF: this.extractValue(buffer,
|
|
2770
|
-
OutPFSet_SF: this.extractValue(buffer,
|
|
2771
|
-
VArPct_SF: this.extractValue(buffer,
|
|
2918
|
+
WMaxLimPct_SF: this.extractValue(buffer, 23, 'int16'),
|
|
2919
|
+
OutPFSet_SF: this.extractValue(buffer, 24, 'int16'),
|
|
2920
|
+
VArPct_SF: this.extractValue(buffer, 25, 'int16')
|
|
2772
2921
|
};
|
|
2773
|
-
this.logRegisterRead(123,
|
|
2774
|
-
this.logRegisterRead(123,
|
|
2775
|
-
this.logRegisterRead(123,
|
|
2922
|
+
this.logRegisterRead(123, 23, 'WMaxLimPct_SF', scaleFactors.WMaxLimPct_SF, 'int16');
|
|
2923
|
+
this.logRegisterRead(123, 24, 'OutPFSet_SF', scaleFactors.OutPFSet_SF, 'int16');
|
|
2924
|
+
this.logRegisterRead(123, 25, 'VArPct_SF', scaleFactors.VArPct_SF, 'int16');
|
|
2776
2925
|
// Extract non-scaled fields from buffer
|
|
2777
|
-
const connWinTmsRaw = this.extractValue(buffer,
|
|
2778
|
-
const connRvrtTmsRaw = this.extractValue(buffer,
|
|
2779
|
-
const connRaw = this.extractValue(buffer,
|
|
2780
|
-
const wMaxLimPctWinTmsRaw = this.extractValue(buffer,
|
|
2781
|
-
const wMaxLimPctRvrtTmsRaw = this.extractValue(buffer,
|
|
2782
|
-
const wMaxLimPctRmpTmsRaw = this.extractValue(buffer,
|
|
2783
|
-
const wMaxLimEnaRaw = this.extractValue(buffer,
|
|
2784
|
-
const outPFSetWinTmsRaw = this.extractValue(buffer,
|
|
2785
|
-
const outPFSetRvrtTmsRaw = this.extractValue(buffer,
|
|
2786
|
-
const outPFSetRmpTmsRaw = this.extractValue(buffer,
|
|
2787
|
-
const outPFSetEnaRaw = this.extractValue(buffer,
|
|
2788
|
-
const vArPctWinTmsRaw = this.extractValue(buffer,
|
|
2789
|
-
const vArPctRvrtTmsRaw = this.extractValue(buffer,
|
|
2790
|
-
const vArPctRmpTmsRaw = this.extractValue(buffer,
|
|
2791
|
-
const vArPctModRaw = this.extractValue(buffer,
|
|
2792
|
-
const vArPctEnaRaw = this.extractValue(buffer,
|
|
2793
|
-
this.logRegisterRead(123,
|
|
2794
|
-
this.logRegisterRead(123,
|
|
2795
|
-
this.logRegisterRead(123,
|
|
2796
|
-
this.logRegisterRead(123,
|
|
2797
|
-
this.logRegisterRead(123,
|
|
2798
|
-
this.logRegisterRead(123,
|
|
2799
|
-
this.logRegisterRead(123,
|
|
2800
|
-
this.logRegisterRead(123,
|
|
2801
|
-
this.logRegisterRead(123,
|
|
2802
|
-
this.logRegisterRead(123,
|
|
2803
|
-
this.logRegisterRead(123,
|
|
2804
|
-
this.logRegisterRead(123,
|
|
2805
|
-
this.logRegisterRead(123,
|
|
2806
|
-
this.logRegisterRead(123,
|
|
2807
|
-
this.logRegisterRead(123,
|
|
2808
|
-
this.logRegisterRead(123,
|
|
2926
|
+
const connWinTmsRaw = this.extractValue(buffer, 2, 'uint16');
|
|
2927
|
+
const connRvrtTmsRaw = this.extractValue(buffer, 3, 'uint16');
|
|
2928
|
+
const connRaw = this.extractValue(buffer, 4, 'uint16');
|
|
2929
|
+
const wMaxLimPctWinTmsRaw = this.extractValue(buffer, 6, 'uint16');
|
|
2930
|
+
const wMaxLimPctRvrtTmsRaw = this.extractValue(buffer, 7, 'uint16');
|
|
2931
|
+
const wMaxLimPctRmpTmsRaw = this.extractValue(buffer, 8, 'uint16');
|
|
2932
|
+
const wMaxLimEnaRaw = this.extractValue(buffer, 9, 'uint16');
|
|
2933
|
+
const outPFSetWinTmsRaw = this.extractValue(buffer, 11, 'uint16');
|
|
2934
|
+
const outPFSetRvrtTmsRaw = this.extractValue(buffer, 12, 'uint16');
|
|
2935
|
+
const outPFSetRmpTmsRaw = this.extractValue(buffer, 13, 'uint16');
|
|
2936
|
+
const outPFSetEnaRaw = this.extractValue(buffer, 14, 'uint16');
|
|
2937
|
+
const vArPctWinTmsRaw = this.extractValue(buffer, 18, 'uint16');
|
|
2938
|
+
const vArPctRvrtTmsRaw = this.extractValue(buffer, 19, 'uint16');
|
|
2939
|
+
const vArPctRmpTmsRaw = this.extractValue(buffer, 20, 'uint16');
|
|
2940
|
+
const vArPctModRaw = this.extractValue(buffer, 21, 'uint16');
|
|
2941
|
+
const vArPctEnaRaw = this.extractValue(buffer, 22, 'uint16');
|
|
2942
|
+
this.logRegisterRead(123, 2, 'Conn_WinTms', connWinTmsRaw, 'uint16');
|
|
2943
|
+
this.logRegisterRead(123, 3, 'Conn_RvrtTms', connRvrtTmsRaw, 'uint16');
|
|
2944
|
+
this.logRegisterRead(123, 4, 'Conn', connRaw, 'enum16');
|
|
2945
|
+
this.logRegisterRead(123, 6, 'WMaxLimPct_WinTms', wMaxLimPctWinTmsRaw, 'uint16');
|
|
2946
|
+
this.logRegisterRead(123, 7, 'WMaxLimPct_RvrtTms', wMaxLimPctRvrtTmsRaw, 'uint16');
|
|
2947
|
+
this.logRegisterRead(123, 8, 'WMaxLimPct_RmpTms', wMaxLimPctRmpTmsRaw, 'uint16');
|
|
2948
|
+
this.logRegisterRead(123, 9, 'WMaxLim_Ena', wMaxLimEnaRaw, 'enum16');
|
|
2949
|
+
this.logRegisterRead(123, 11, 'OutPFSet_WinTms', outPFSetWinTmsRaw, 'uint16');
|
|
2950
|
+
this.logRegisterRead(123, 12, 'OutPFSet_RvrtTms', outPFSetRvrtTmsRaw, 'uint16');
|
|
2951
|
+
this.logRegisterRead(123, 13, 'OutPFSet_RmpTms', outPFSetRmpTmsRaw, 'uint16');
|
|
2952
|
+
this.logRegisterRead(123, 14, 'OutPFSet_Ena', outPFSetEnaRaw, 'enum16');
|
|
2953
|
+
this.logRegisterRead(123, 18, 'VArPct_WinTms', vArPctWinTmsRaw, 'uint16');
|
|
2954
|
+
this.logRegisterRead(123, 19, 'VArPct_RvrtTms', vArPctRvrtTmsRaw, 'uint16');
|
|
2955
|
+
this.logRegisterRead(123, 20, 'VArPct_RmpTms', vArPctRmpTmsRaw, 'uint16');
|
|
2956
|
+
this.logRegisterRead(123, 21, 'VArPct_Mod', vArPctModRaw, 'enum16');
|
|
2957
|
+
this.logRegisterRead(123, 22, 'VArPct_Ena', vArPctEnaRaw, 'enum16');
|
|
2809
2958
|
const controls = {
|
|
2810
2959
|
blockNumber: 123,
|
|
2811
2960
|
blockAddress: model.address,
|
|
2812
2961
|
blockLength: model.length,
|
|
2813
|
-
// Connection control -
|
|
2962
|
+
// Connection control - points 0-2 (buffer 2-4)
|
|
2814
2963
|
Conn_WinTms: connWinTmsRaw,
|
|
2815
2964
|
Conn_RvrtTms: connRvrtTmsRaw,
|
|
2816
2965
|
Conn: connRaw,
|
|
2817
|
-
// Power limit control -
|
|
2818
|
-
WMaxLimPct: this.applyScaleFactor(this.extractValue(buffer,
|
|
2966
|
+
// Power limit control - points 3-7 (buffer 5-9)
|
|
2967
|
+
WMaxLimPct: this.applyScaleFactor(this.extractValue(buffer, 5, 'uint16'), scaleFactors.WMaxLimPct_SF, 'uint16', 'Power Limit Percentage', 5, 123),
|
|
2819
2968
|
WMaxLimPct_SF: scaleFactors.WMaxLimPct_SF,
|
|
2820
2969
|
WMaxLimPct_WinTms: wMaxLimPctWinTmsRaw,
|
|
2821
2970
|
WMaxLimPct_RvrtTms: wMaxLimPctRvrtTmsRaw,
|
|
2822
2971
|
WMaxLimPct_RmpTms: wMaxLimPctRmpTmsRaw,
|
|
2823
2972
|
WMaxLim_Ena: wMaxLimEnaRaw,
|
|
2824
|
-
// Power factor control -
|
|
2825
|
-
OutPFSet: this.applyScaleFactor(this.extractValue(buffer,
|
|
2973
|
+
// Power factor control - points 8-12 (buffer 10-14)
|
|
2974
|
+
OutPFSet: this.applyScaleFactor(this.extractValue(buffer, 10, 'int16'), scaleFactors.OutPFSet_SF, 'int16', 'Output Power Factor Set', 10, 123),
|
|
2826
2975
|
OutPFSet_SF: scaleFactors.OutPFSet_SF,
|
|
2827
2976
|
OutPFSet_WinTms: outPFSetWinTmsRaw,
|
|
2828
2977
|
OutPFSet_RvrtTms: outPFSetRvrtTmsRaw,
|
|
2829
2978
|
OutPFSet_RmpTms: outPFSetRmpTmsRaw,
|
|
2830
2979
|
OutPFSet_Ena: outPFSetEnaRaw,
|
|
2831
|
-
// Reactive power control -
|
|
2832
|
-
VArWMaxPct: this.applyScaleFactor(this.extractValue(buffer,
|
|
2833
|
-
VArMaxPct: this.applyScaleFactor(this.extractValue(buffer,
|
|
2834
|
-
VArAvalPct: this.applyScaleFactor(this.extractValue(buffer,
|
|
2980
|
+
// Reactive power control - points 13-20 (buffer 15-22)
|
|
2981
|
+
VArWMaxPct: this.applyScaleFactor(this.extractValue(buffer, 15, 'int16'), scaleFactors.VArPct_SF, 'int16', 'Reactive Power at Max Power %', 15, 123),
|
|
2982
|
+
VArMaxPct: this.applyScaleFactor(this.extractValue(buffer, 16, 'int16'), scaleFactors.VArPct_SF, 'int16', 'Max Reactive Power %', 16, 123),
|
|
2983
|
+
VArAvalPct: this.applyScaleFactor(this.extractValue(buffer, 17, 'int16'), scaleFactors.VArPct_SF, 'int16', 'Available Reactive Power %', 17, 123),
|
|
2835
2984
|
VArPct_SF: scaleFactors.VArPct_SF,
|
|
2836
2985
|
VArPct_WinTms: vArPctWinTmsRaw,
|
|
2837
2986
|
VArPct_RvrtTms: vArPctRvrtTmsRaw,
|
|
@@ -2843,7 +2992,7 @@ class SunspecModbusClient {
|
|
|
2843
2992
|
return controls;
|
|
2844
2993
|
}
|
|
2845
2994
|
catch (error) {
|
|
2846
|
-
|
|
2995
|
+
this.logTransactionError(`Error reading inverter controls`, error);
|
|
2847
2996
|
return null;
|
|
2848
2997
|
}
|
|
2849
2998
|
}
|
|
@@ -2881,7 +3030,7 @@ class SunspecModbusClient {
|
|
|
2881
3030
|
return true;
|
|
2882
3031
|
}
|
|
2883
3032
|
catch (error) {
|
|
2884
|
-
|
|
3033
|
+
this.logTransactionError(`Error writing inverter settings`, error);
|
|
2885
3034
|
return false;
|
|
2886
3035
|
}
|
|
2887
3036
|
}
|
|
@@ -2894,43 +3043,45 @@ class SunspecModbusClient {
|
|
|
2894
3043
|
console.error(`Controls model 123 not found on unit ${unitId}`);
|
|
2895
3044
|
return false;
|
|
2896
3045
|
}
|
|
3046
|
+
// model.address points at the 2-register model header (ID + length), so a
|
|
3047
|
+
// SunSpec point at offset N lives at baseAddr + 2 + N.
|
|
2897
3048
|
const baseAddr = model.address;
|
|
2898
3049
|
try {
|
|
2899
3050
|
// Per-field inverter-control writes are debug-only; the high-level callers
|
|
2900
3051
|
// (`setFeedInLimit`, etc.) still log the action and outcome at info level.
|
|
2901
3052
|
if (controls.Conn !== undefined) {
|
|
2902
|
-
await this.writeRegisterValue(unitId, baseAddr +
|
|
3053
|
+
await this.writeRegisterValue(unitId, baseAddr + 4, controls.Conn, 'uint16');
|
|
2903
3054
|
console.debug(`Set connection control to ${controls.Conn}`);
|
|
2904
3055
|
}
|
|
2905
|
-
// Power limit control (
|
|
3056
|
+
// Power limit control (point 3 -> baseAddr + 5) - needs scale factor
|
|
2906
3057
|
if (controls.WMaxLimPct !== undefined) {
|
|
2907
|
-
const scaleFactor = await this.readRegisterValue(unitId, baseAddr +
|
|
3058
|
+
const scaleFactor = await this.readRegisterValue(unitId, baseAddr + 23, 1, 'int16');
|
|
2908
3059
|
const scaledValue = Math.round(controls.WMaxLimPct / Math.pow(10, scaleFactor));
|
|
2909
|
-
await this.writeRegisterValue(unitId, baseAddr +
|
|
3060
|
+
await this.writeRegisterValue(unitId, baseAddr + 5, scaledValue, 'uint16');
|
|
2910
3061
|
console.debug(`Set power limit to ${controls.WMaxLimPct}% (scaled: ${scaledValue})`);
|
|
2911
3062
|
}
|
|
2912
|
-
// Throttle enable/disable (
|
|
3063
|
+
// Throttle enable/disable (point 7 -> baseAddr + 9)
|
|
2913
3064
|
if (controls.WMaxLim_Ena !== undefined) {
|
|
2914
|
-
await this.writeRegisterValue(unitId, baseAddr +
|
|
3065
|
+
await this.writeRegisterValue(unitId, baseAddr + 9, controls.WMaxLim_Ena, 'uint16');
|
|
2915
3066
|
console.debug(`Set throttle enable to ${controls.WMaxLim_Ena}`);
|
|
2916
3067
|
}
|
|
2917
|
-
// Power factor control (
|
|
3068
|
+
// Power factor control (point 8 -> baseAddr + 10) - needs scale factor
|
|
2918
3069
|
if (controls.OutPFSet !== undefined) {
|
|
2919
|
-
const scaleFactor = await this.readRegisterValue(unitId, baseAddr +
|
|
3070
|
+
const scaleFactor = await this.readRegisterValue(unitId, baseAddr + 24, 1, 'int16');
|
|
2920
3071
|
const scaledValue = Math.round(controls.OutPFSet / Math.pow(10, scaleFactor));
|
|
2921
|
-
await this.writeRegisterValue(unitId, baseAddr +
|
|
3072
|
+
await this.writeRegisterValue(unitId, baseAddr + 10, scaledValue, 'int16');
|
|
2922
3073
|
console.debug(`Set power factor to ${controls.OutPFSet} (scaled: ${scaledValue})`);
|
|
2923
3074
|
}
|
|
2924
|
-
// Power factor enable/disable (
|
|
3075
|
+
// Power factor enable/disable (point 12 -> baseAddr + 14)
|
|
2925
3076
|
if (controls.OutPFSet_Ena !== undefined) {
|
|
2926
|
-
await this.writeRegisterValue(unitId, baseAddr +
|
|
3077
|
+
await this.writeRegisterValue(unitId, baseAddr + 14, controls.OutPFSet_Ena, 'uint16');
|
|
2927
3078
|
console.debug(`Set PF enable to ${controls.OutPFSet_Ena}`);
|
|
2928
3079
|
}
|
|
2929
3080
|
console.debug('Inverter controls written successfully');
|
|
2930
3081
|
return true;
|
|
2931
3082
|
}
|
|
2932
3083
|
catch (error) {
|
|
2933
|
-
|
|
3084
|
+
this.logTransactionError(`Error writing inverter controls`, error);
|
|
2934
3085
|
return false;
|
|
2935
3086
|
}
|
|
2936
3087
|
}
|