smithtek-mako-rf 2.9.6 → 2.9.8

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smithtek-mako-rf",
3
- "version": "2.9.6",
3
+ "version": "2.9.8",
4
4
  "description": "Smithtek dedicated node for communicating with the Mako PLC over RS485 or RF",
5
5
  "keywords": [
6
6
  "node-red",
@@ -117,7 +117,9 @@ module.exports = function (RED) {
117
117
  try { port.removeListener("data", onData); } catch (_e2) {}
118
118
  }
119
119
  try { if (typeof port.flush === "function") port.flush(() => {}); } catch (_e) {}
120
+ if (state._rssiCleanup === cleanup) delete state._rssiCleanup;
120
121
  }
122
+ state._rssiCleanup = cleanup;
121
123
 
122
124
  function onData(chunk) {
123
125
  rx = Buffer.concat([rx, Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)]);
@@ -498,6 +500,7 @@ module.exports = function (RED) {
498
500
  state.busy = true;
499
501
 
500
502
  (async () => {
503
+ await sleep(20);
501
504
  while (state.queue.length > 0) {
502
505
  const item = state.queue.shift();
503
506
  const { node, msg, send, done, req, items } = item;
@@ -548,8 +551,9 @@ module.exports = function (RED) {
548
551
  // Force reconnect next attempt
549
552
  state.connected = false;
550
553
  try {
551
- state.client.close(() => {});
552
- } catch (_e) {}
554
+ await new Promise((resolve) => state.client.close(() => resolve()));
555
+ } catch (_e) {}
556
+
553
557
 
554
558
  if (attempt < totalTries && gap_s > 0) {
555
559
  await sleep(Math.floor(gap_s * 1000));
@@ -598,6 +602,13 @@ module.exports = function (RED) {
598
602
 
599
603
 
600
604
  const rssiDbm = await queryRssiOnSamePort(state, guardMs, timeoutMs);
605
+ await sleep(30);
606
+ state.connected = false;
607
+ try {
608
+ await new Promise((resolve) => state.client.close(() => resolve()));
609
+ } catch (_e) {}
610
+
611
+
601
612
 
602
613
  const nodeKeyBase = sanitizeKey(node.name || busName || "mako_rf");
603
614
  const key = `${nodeKeyBase}_rssi_dbm`;
@@ -649,6 +660,7 @@ module.exports = function (RED) {
649
660
  this.gap_s = toNum(n.gap_s, 0);
650
661
  this.maxQueue = toNum(n.maxQueue, 50);
651
662
 
663
+ BUS.delete(this.id);
652
664
  ensureBusState(this);
653
665
 
654
666
  this.on("close", (removed, done) => {
@@ -766,9 +778,32 @@ module.exports = function (RED) {
766
778
  });
767
779
 
768
780
  node.on("close", function (_removed, done) {
781
+ try {
782
+ const busCfg = RED.nodes.getNode(config.bus);
783
+ if (busCfg) {
784
+ const s = BUS.get(busCfg.id);
785
+ if (s) {
786
+ // NEW: stop any in-flight queue processor from the old deploy
787
+ s.queue = [];
788
+ s.busy = false;
789
+
790
+ if (typeof s._rssiCleanup === "function") {
791
+ try { s._rssiCleanup(); } catch (_e) {}
792
+ }
793
+ if (s.client) {
794
+ try { s.client.close(() => {}); } catch (_e) {}
795
+ s.connected = false;
796
+ s.client = new (require("modbus-serial"))();
797
+ }
798
+ }
799
+ }
800
+ } catch (_e) {}
801
+
769
802
  node.status({});
770
803
  done();
771
804
  });
805
+
806
+
772
807
  }
773
808
 
774
809
  RED.nodes.registerType("smithtek-mako-rf", SmithtekMakoRfNode);