node-zserial 1.0.2 → 1.0.3

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/zserial.js +9 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-zserial",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Node-RED nodes to talk to serial ports",
5
5
  "dependencies": {
6
6
  "serialport": "^12.0.0"
package/zserial.js CHANGED
@@ -129,11 +129,14 @@ module.exports = function (RED) {
129
129
  onMsg(msg, send, done);
130
130
  })
131
131
 
132
-
133
-
134
- function setCallback() {
132
+ function getConnection() {
135
133
  let conns = serialPool.curConnections();
136
134
  let connKeys = Object.keys(conns) || [];
135
+ return { conns, connKeys }
136
+ }
137
+
138
+ function setCallback() {
139
+ let { conns, connKeys } = getConnection();
137
140
  // node.warn(connKeys);
138
141
  node.status({ fill: "green", shape: "dot", text: "当前连接数:" + connKeys.length });
139
142
 
@@ -152,16 +155,19 @@ module.exports = function (RED) {
152
155
  node.send(msgout);
153
156
  });
154
157
  curPort.on('ready', function () {
158
+ let { conns, connKeys } = getConnection();
155
159
  //node.status({ fill: "green", shape: "dot", text: "node-red:common.status.connected" });
156
160
  node.status({ fill: "green", shape: "dot", text: "当前连接数:" + connKeys.length });
157
161
 
158
162
  });
159
163
  curPort.on('closed', function () {
164
+ let { conns, connKeys } = getConnection();
160
165
  //node.status({ fill: "red", shape: "ring", text: "node-red:common.status.not-connected" });
161
166
  node.status({ fill: "green", shape: "dot", text: "当前连接数:" + connKeys.length });
162
167
 
163
168
  });
164
169
  curPort.on('stopped', function () {
170
+ let { conns, connKeys } = getConnection();
165
171
  //node.status({ fill: "grey", shape: "ring", text: "serial.status.stopped" });
166
172
  node.status({ fill: "green", shape: "dot", text: "当前连接数:" + connKeys.length });
167
173