node-zserial 1.0.9 → 1.0.11
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 +28 -18
package/package.json
CHANGED
package/zserial.js
CHANGED
|
@@ -308,11 +308,19 @@ module.exports = function (RED) {
|
|
|
308
308
|
node.successMsg = {};
|
|
309
309
|
node.errorMsg = {};
|
|
310
310
|
node._msg = null
|
|
311
|
+
|
|
312
|
+
function initMsg(msg) {
|
|
313
|
+
node.totallenth = msg.serialConfigs.length;
|
|
314
|
+
node.totalMsg = {};
|
|
315
|
+
node.successMsg = {};
|
|
316
|
+
node.errorMsg = {};
|
|
317
|
+
}
|
|
311
318
|
function zsend(msg, err, alldone, port, done) {
|
|
312
319
|
|
|
313
320
|
let payload = msg || err;
|
|
314
321
|
node._msg.payload = payload;
|
|
315
322
|
node.totalMsg[port] = payload
|
|
323
|
+
|
|
316
324
|
if (msg) {
|
|
317
325
|
node.successMsg[port] = msg
|
|
318
326
|
node.send([node._msg, null, null]);
|
|
@@ -322,17 +330,17 @@ module.exports = function (RED) {
|
|
|
322
330
|
node.send([null, node._msg, null]);
|
|
323
331
|
}
|
|
324
332
|
sendAll(done);
|
|
325
|
-
|
|
326
333
|
}
|
|
327
334
|
function onMsg(msg, send, done) {
|
|
328
335
|
node._msg = msg;
|
|
336
|
+
initMsg(msg);
|
|
329
337
|
if (!msg.serialConfigs) {
|
|
330
338
|
node.error("需要配置批量配置:msg.serialConfigs");
|
|
331
339
|
// zsend(msg, null, null)
|
|
332
340
|
done();
|
|
333
341
|
return;
|
|
334
342
|
}
|
|
335
|
-
|
|
343
|
+
|
|
336
344
|
for (var i = 0; i < msg.serialConfigs.length; i++) {
|
|
337
345
|
var serialConfig = msg.serialConfigs[i];
|
|
338
346
|
serialConfig._msgid = msg._msgid + "_" + i;
|
|
@@ -343,13 +351,14 @@ module.exports = function (RED) {
|
|
|
343
351
|
function sendAll(done) {
|
|
344
352
|
try {
|
|
345
353
|
let len = Object.keys(node.totalMsg).length;
|
|
354
|
+
|
|
346
355
|
if (len == node.totallenth) {
|
|
347
356
|
let payload = {
|
|
348
357
|
totalMsg: node.totalMsg,
|
|
349
358
|
successMsg: node.successMsg,
|
|
350
359
|
errorMsg: node.errorMsg,
|
|
351
360
|
}
|
|
352
|
-
node.send([null, null,Object.assign({}, node._msg,{
|
|
361
|
+
node.send([null, null, Object.assign({}, node._msg, {
|
|
353
362
|
payload: payload
|
|
354
363
|
})]);
|
|
355
364
|
done()
|
|
@@ -454,22 +463,22 @@ module.exports = function (RED) {
|
|
|
454
463
|
});
|
|
455
464
|
|
|
456
465
|
curPort.on('initerror', function (port, retryNum, olderr) {
|
|
457
|
-
zsend(null, {
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
}, 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);
|
|
463
472
|
});
|
|
464
473
|
|
|
465
474
|
|
|
466
475
|
curPort.on('retryerror', function (port, retryNum) {
|
|
467
|
-
curPort._retryNum = 0;
|
|
468
|
-
zsend(null, {
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
}, 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);
|
|
473
482
|
});
|
|
474
483
|
|
|
475
484
|
curPort.on('closed', function (port) {
|
|
@@ -481,6 +490,7 @@ module.exports = function (RED) {
|
|
|
481
490
|
}
|
|
482
491
|
|
|
483
492
|
this.on("input", function (msg, send, done) {
|
|
493
|
+
|
|
484
494
|
onMsg(msg, send, done);
|
|
485
495
|
})
|
|
486
496
|
this.on("close", function (done) {
|
|
@@ -524,7 +534,7 @@ module.exports = function (RED) {
|
|
|
524
534
|
binoutput = serialConfig.bin || 'false',
|
|
525
535
|
addchar = serialConfig.addchar || '',
|
|
526
536
|
responsetimeout = serialConfig.responsetimeout || 10000,
|
|
527
|
-
retryNum = serialConfig.retryNum ||
|
|
537
|
+
retryNum = serialConfig.retryNum || 1;
|
|
528
538
|
var id = port;
|
|
529
539
|
// just return the connection object if already have one
|
|
530
540
|
// key is the port (file path)
|
|
@@ -659,9 +669,9 @@ module.exports = function (RED) {
|
|
|
659
669
|
obj._retryNum++;
|
|
660
670
|
RED.log.info(obj._retryNum)
|
|
661
671
|
if (obj._retryNum > retryNum) {
|
|
662
|
-
serialPool.zlog("已经重试" + retryNum + "次,请检查串口是否正常!", {});
|
|
672
|
+
// serialPool.zlog("已经重试" + retryNum + "次,请检查串口是否正常!", {});
|
|
663
673
|
obj._emitter.emit('retryerror', id, retryNum);
|
|
664
|
-
return;
|
|
674
|
+
return null;
|
|
665
675
|
}
|
|
666
676
|
obj.serial = new SerialPort({
|
|
667
677
|
path: port,
|