node-zserial 1.0.10 → 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 +21 -19
package/package.json
CHANGED
package/zserial.js
CHANGED
|
@@ -309,7 +309,8 @@ module.exports = function (RED) {
|
|
|
309
309
|
node.errorMsg = {};
|
|
310
310
|
node._msg = null
|
|
311
311
|
|
|
312
|
-
function initMsg() {
|
|
312
|
+
function initMsg(msg) {
|
|
313
|
+
node.totallenth = msg.serialConfigs.length;
|
|
313
314
|
node.totalMsg = {};
|
|
314
315
|
node.successMsg = {};
|
|
315
316
|
node.errorMsg = {};
|
|
@@ -319,6 +320,7 @@ module.exports = function (RED) {
|
|
|
319
320
|
let payload = msg || err;
|
|
320
321
|
node._msg.payload = payload;
|
|
321
322
|
node.totalMsg[port] = payload
|
|
323
|
+
|
|
322
324
|
if (msg) {
|
|
323
325
|
node.successMsg[port] = msg
|
|
324
326
|
node.send([node._msg, null, null]);
|
|
@@ -328,18 +330,17 @@ module.exports = function (RED) {
|
|
|
328
330
|
node.send([null, node._msg, null]);
|
|
329
331
|
}
|
|
330
332
|
sendAll(done);
|
|
331
|
-
|
|
332
333
|
}
|
|
333
334
|
function onMsg(msg, send, done) {
|
|
334
335
|
node._msg = msg;
|
|
335
|
-
initMsg();
|
|
336
|
+
initMsg(msg);
|
|
336
337
|
if (!msg.serialConfigs) {
|
|
337
338
|
node.error("需要配置批量配置:msg.serialConfigs");
|
|
338
339
|
// zsend(msg, null, null)
|
|
339
340
|
done();
|
|
340
341
|
return;
|
|
341
342
|
}
|
|
342
|
-
|
|
343
|
+
|
|
343
344
|
for (var i = 0; i < msg.serialConfigs.length; i++) {
|
|
344
345
|
var serialConfig = msg.serialConfigs[i];
|
|
345
346
|
serialConfig._msgid = msg._msgid + "_" + i;
|
|
@@ -350,6 +351,7 @@ module.exports = function (RED) {
|
|
|
350
351
|
function sendAll(done) {
|
|
351
352
|
try {
|
|
352
353
|
let len = Object.keys(node.totalMsg).length;
|
|
354
|
+
|
|
353
355
|
if (len == node.totallenth) {
|
|
354
356
|
let payload = {
|
|
355
357
|
totalMsg: node.totalMsg,
|
|
@@ -461,22 +463,22 @@ module.exports = function (RED) {
|
|
|
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,
|