smithtek-mako-rf 3.0.1 → 3.0.2
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/package.json +1 -1
- package/smithtek-mako-rf-3.0.1.tgz +0 -0
- package/smithtek-mako-rf-3.0.2.tgz +0 -0
- package/smithtek-mako-rf.js +26 -17
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|
package/smithtek-mako-rf.js
CHANGED
|
@@ -411,25 +411,37 @@ state._rssiCleanup = cleanup;
|
|
|
411
411
|
return [5, 6, 15, 16].includes(fc) ? fc : 5;
|
|
412
412
|
}
|
|
413
413
|
|
|
414
|
+
async function closeClientSafe(state) {
|
|
415
|
+
// Best-effort: close and wait a moment for the fd to actually drop
|
|
416
|
+
try {
|
|
417
|
+
await new Promise((resolve) => {
|
|
418
|
+
try {
|
|
419
|
+
state.client.close(() => resolve());
|
|
420
|
+
} catch (_e) {
|
|
421
|
+
resolve();
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
} catch (_e) {}
|
|
425
|
+
|
|
426
|
+
// tiny settle time helps on Pi serial
|
|
427
|
+
await sleep(50);
|
|
428
|
+
}
|
|
429
|
+
|
|
414
430
|
async function connectIfNeeded(cfg, state) {
|
|
415
431
|
if (!cfg) throw new Error("Bus config missing");
|
|
416
432
|
|
|
417
|
-
// NOTE: we will hard-lock /dev/ttyAMA2 later (PassPort mode)
|
|
418
|
-
// if (process.env.SMITHTEK_PASSPORT === "1") cfg.serialPort = "/dev/ttyAMA2";
|
|
419
|
-
|
|
420
433
|
const portKey = makePortKey(cfg);
|
|
421
434
|
|
|
422
|
-
// If
|
|
435
|
+
// If settings changed, force reconnect
|
|
423
436
|
if (state.connected && state.lastPortKey !== portKey) {
|
|
424
437
|
state.connected = false;
|
|
425
|
-
|
|
426
|
-
state.client.close(() => {});
|
|
427
|
-
} catch (_e) {}
|
|
438
|
+
await closeClientSafe(state);
|
|
428
439
|
}
|
|
429
440
|
|
|
441
|
+
// Already connected
|
|
430
442
|
if (state.connected) return;
|
|
431
443
|
|
|
432
|
-
// If
|
|
444
|
+
// If already connecting, wait for that attempt to finish
|
|
433
445
|
if (state.connecting) {
|
|
434
446
|
for (let i = 0; i < 200; i++) {
|
|
435
447
|
if (state.connected) return;
|
|
@@ -451,10 +463,10 @@ state._rssiCleanup = cleanup;
|
|
|
451
463
|
parity: cfg.parity || "none",
|
|
452
464
|
};
|
|
453
465
|
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
} catch (_e) {}
|
|
466
|
+
// Always close cleanly before opening (and WAIT for it)
|
|
467
|
+
await closeClientSafe(state);
|
|
457
468
|
|
|
469
|
+
// Open
|
|
458
470
|
await state.client.connectRTUBuffered(port, options);
|
|
459
471
|
|
|
460
472
|
// UI uses seconds; library uses ms
|
|
@@ -799,18 +811,15 @@ try {
|
|
|
799
811
|
if (busCfg) {
|
|
800
812
|
const s = BUS.get(busCfg.id);
|
|
801
813
|
if (s) {
|
|
802
|
-
// NEW: stop any in-flight queue processor from the old deploy
|
|
803
814
|
s.queue = [];
|
|
804
815
|
s.busy = false;
|
|
805
816
|
|
|
806
817
|
if (typeof s._rssiCleanup === "function") {
|
|
807
818
|
try { s._rssiCleanup(); } catch (_e) {}
|
|
808
819
|
}
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
s.client = new (require("modbus-serial"))();
|
|
813
|
-
}
|
|
820
|
+
|
|
821
|
+
s.connected = false;
|
|
822
|
+
try { s.client.close(() => {}); } catch (_e) {}
|
|
814
823
|
}
|
|
815
824
|
}
|
|
816
825
|
} catch (_e) {}
|