node-zserial 1.0.24 → 1.0.26
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 +13 -27
package/package.json
CHANGED
package/zserial.js
CHANGED
|
@@ -550,36 +550,19 @@ module.exports = function (RED) {
|
|
|
550
550
|
curPort.off('data', dataHandler);
|
|
551
551
|
curPort.off('timeout', timeoutHandler);
|
|
552
552
|
})
|
|
553
|
+
}
|
|
553
554
|
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
// // text: `请检查端口是否打开,重试次数${retryNum}`,
|
|
558
|
-
// // error: olderr,
|
|
559
|
-
// // port: port
|
|
560
|
-
// // }, null, curPort.serial.path, done);
|
|
561
|
-
// });
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
// curPort.on('retryerror', function (port, retryNum) {
|
|
565
|
-
// // curPort._retryNum = 0;
|
|
566
|
-
// // zsend(null, {
|
|
567
|
-
// // status: "ERR_retry",
|
|
568
|
-
// // text: `重试${retryNum}失败`,
|
|
569
|
-
// // port: port
|
|
570
|
-
// // }, null, curPort.serial.path, done);
|
|
571
|
-
// });
|
|
572
|
-
|
|
573
|
-
// curPort.on('closed', function (port) {
|
|
574
|
-
// // node.warn(`串口已关闭:${port}`);
|
|
575
|
-
// });
|
|
576
|
-
// curPort.on('ready', function (port) {
|
|
577
|
-
// // node.warn(`串口已准备好:${port}`);
|
|
578
|
-
// });
|
|
555
|
+
function afterClosed(port){
|
|
556
|
+
node[`_dataHandler_${port}`] = null
|
|
557
|
+
node[`_timeoutHandler_${port}`] = null
|
|
579
558
|
}
|
|
580
559
|
|
|
581
|
-
|
|
560
|
+
if(!node._afterClosed){
|
|
561
|
+
node._afterClosed = afterClosed;
|
|
562
|
+
serialPool.on('afterClosed', node._afterClosed);
|
|
563
|
+
}
|
|
582
564
|
|
|
565
|
+
this.on("input", function (msg, send, done) {
|
|
583
566
|
onMsg(msg, send, done);
|
|
584
567
|
})
|
|
585
568
|
this.on("close", function (done) {
|
|
@@ -587,7 +570,9 @@ module.exports = function (RED) {
|
|
|
587
570
|
node.successMsg = null;
|
|
588
571
|
node.errorMsg = null;
|
|
589
572
|
try {
|
|
573
|
+
serialPool.off('afterClosed', node._afterClosed);
|
|
590
574
|
serialPool.closeAll(done, node);
|
|
575
|
+
node._afterClosed = null;
|
|
591
576
|
} catch (error) {
|
|
592
577
|
done();
|
|
593
578
|
}
|
|
@@ -601,7 +586,7 @@ module.exports = function (RED) {
|
|
|
601
586
|
var serialPool = (function () {
|
|
602
587
|
var connections = {};
|
|
603
588
|
var _zemitter = new events.EventEmitter();
|
|
604
|
-
|
|
589
|
+
_zemitter.setMaxListeners(500); // 设置最大监听器数量为500,防止警告
|
|
605
590
|
return {
|
|
606
591
|
on: function (event, callback) { _zemitter.on(event, callback); },
|
|
607
592
|
off: function (event, callback) { _zemitter.off(event, callback); },
|
|
@@ -1248,6 +1233,7 @@ module.exports = function (RED) {
|
|
|
1248
1233
|
try {
|
|
1249
1234
|
connections[port].close(function () {
|
|
1250
1235
|
serialPool.zlog(node, "关闭成功");
|
|
1236
|
+
_zemitter.emit('afterClosed', port);
|
|
1251
1237
|
RED.log.info(RED._("serial.errors.closed", { port: port }), {});
|
|
1252
1238
|
done();
|
|
1253
1239
|
});
|