node-zserial 1.0.10 → 1.0.12
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/zserial.js +26 -24
package/package.json
CHANGED
package/zserial.js
CHANGED
|
@@ -269,6 +269,7 @@ module.exports = function (RED) {
|
|
|
269
269
|
curPort.on('timeout', function (msgout, sender) {
|
|
270
270
|
if (sender !== node) { return; }
|
|
271
271
|
msgout.status = "ERR_TIMEOUT";
|
|
272
|
+
msgout.port = curPort.serial.path;
|
|
272
273
|
node.status({ fill: "red", shape: "ring", text: "timeout:::" + curPort.serial.path });
|
|
273
274
|
node.send(msgout);
|
|
274
275
|
if (done) done();
|
|
@@ -309,7 +310,9 @@ module.exports = function (RED) {
|
|
|
309
310
|
node.errorMsg = {};
|
|
310
311
|
node._msg = null
|
|
311
312
|
|
|
312
|
-
function initMsg() {
|
|
313
|
+
function initMsg(msg) {
|
|
314
|
+
node._msg = msg;
|
|
315
|
+
node.totallenth = msg.serialConfigs.length;
|
|
313
316
|
node.totalMsg = {};
|
|
314
317
|
node.successMsg = {};
|
|
315
318
|
node.errorMsg = {};
|
|
@@ -319,6 +322,7 @@ module.exports = function (RED) {
|
|
|
319
322
|
let payload = msg || err;
|
|
320
323
|
node._msg.payload = payload;
|
|
321
324
|
node.totalMsg[port] = payload
|
|
325
|
+
|
|
322
326
|
if (msg) {
|
|
323
327
|
node.successMsg[port] = msg
|
|
324
328
|
node.send([node._msg, null, null]);
|
|
@@ -328,18 +332,17 @@ module.exports = function (RED) {
|
|
|
328
332
|
node.send([null, node._msg, null]);
|
|
329
333
|
}
|
|
330
334
|
sendAll(done);
|
|
331
|
-
|
|
332
335
|
}
|
|
333
336
|
function onMsg(msg, send, done) {
|
|
334
|
-
|
|
335
|
-
initMsg();
|
|
337
|
+
|
|
338
|
+
initMsg(msg);
|
|
336
339
|
if (!msg.serialConfigs) {
|
|
337
340
|
node.error("需要配置批量配置:msg.serialConfigs");
|
|
338
341
|
// zsend(msg, null, null)
|
|
339
342
|
done();
|
|
340
343
|
return;
|
|
341
344
|
}
|
|
342
|
-
|
|
345
|
+
|
|
343
346
|
for (var i = 0; i < msg.serialConfigs.length; i++) {
|
|
344
347
|
var serialConfig = msg.serialConfigs[i];
|
|
345
348
|
serialConfig._msgid = msg._msgid + "_" + i;
|
|
@@ -350,6 +353,7 @@ module.exports = function (RED) {
|
|
|
350
353
|
function sendAll(done) {
|
|
351
354
|
try {
|
|
352
355
|
let len = Object.keys(node.totalMsg).length;
|
|
356
|
+
|
|
353
357
|
if (len == node.totallenth) {
|
|
354
358
|
let payload = {
|
|
355
359
|
totalMsg: node.totalMsg,
|
|
@@ -453,30 +457,28 @@ module.exports = function (RED) {
|
|
|
453
457
|
curPort.on('timeout', function (msgout, sender) {
|
|
454
458
|
if (sender !== node) { return; }
|
|
455
459
|
msgout.status = "ERR_TIMEOUT";
|
|
460
|
+
msgout.port = curPort.serial.path;
|
|
456
461
|
node.status({ fill: "red", shape: "ring", text: "timeout:::" + curPort.serial.path });
|
|
457
|
-
zsend(null,
|
|
458
|
-
status: "ERR_TIMEOUT",
|
|
459
|
-
port: curPort.serial.path
|
|
460
|
-
}, null, curPort.serial.path, done);
|
|
462
|
+
zsend(null,msgout, null, curPort.serial.path, done);
|
|
461
463
|
});
|
|
462
464
|
|
|
463
465
|
curPort.on('initerror', function (port, retryNum, olderr) {
|
|
464
|
-
zsend(null, {
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
}, null, curPort.serial.path, done);
|
|
466
|
+
// zsend(null, {
|
|
467
|
+
// status: "ERR_INIT",
|
|
468
|
+
// text: `请检查端口是否打开,重试次数${retryNum}`,
|
|
469
|
+
// error: olderr,
|
|
470
|
+
// port: port
|
|
471
|
+
// }, null, curPort.serial.path, done);
|
|
470
472
|
});
|
|
471
473
|
|
|
472
474
|
|
|
473
475
|
curPort.on('retryerror', function (port, retryNum) {
|
|
474
|
-
curPort._retryNum = 0;
|
|
475
|
-
zsend(null, {
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
}, null, curPort.serial.path, done);
|
|
476
|
+
// curPort._retryNum = 0;
|
|
477
|
+
// zsend(null, {
|
|
478
|
+
// status: "ERR_retry",
|
|
479
|
+
// text: `重试${retryNum}失败`,
|
|
480
|
+
// port: port
|
|
481
|
+
// }, null, curPort.serial.path, done);
|
|
480
482
|
});
|
|
481
483
|
|
|
482
484
|
curPort.on('closed', function (port) {
|
|
@@ -532,7 +534,7 @@ module.exports = function (RED) {
|
|
|
532
534
|
binoutput = serialConfig.bin || 'false',
|
|
533
535
|
addchar = serialConfig.addchar || '',
|
|
534
536
|
responsetimeout = serialConfig.responsetimeout || 10000,
|
|
535
|
-
retryNum = serialConfig.retryNum ||
|
|
537
|
+
retryNum = serialConfig.retryNum || 1;
|
|
536
538
|
var id = port;
|
|
537
539
|
// just return the connection object if already have one
|
|
538
540
|
// key is the port (file path)
|
|
@@ -667,9 +669,9 @@ module.exports = function (RED) {
|
|
|
667
669
|
obj._retryNum++;
|
|
668
670
|
RED.log.info(obj._retryNum)
|
|
669
671
|
if (obj._retryNum > retryNum) {
|
|
670
|
-
serialPool.zlog("已经重试" + retryNum + "次,请检查串口是否正常!", {});
|
|
672
|
+
// serialPool.zlog("已经重试" + retryNum + "次,请检查串口是否正常!", {});
|
|
671
673
|
obj._emitter.emit('retryerror', id, retryNum);
|
|
672
|
-
return;
|
|
674
|
+
return null;
|
|
673
675
|
}
|
|
674
676
|
obj.serial = new SerialPort({
|
|
675
677
|
path: port,
|