node-red-contrib-symi-modbus 2.6.0 → 2.6.1

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/README.md CHANGED
@@ -435,7 +435,7 @@ msg.payload = 1; // 或 0
435
435
 
436
436
  ## 项目信息
437
437
 
438
- **版本**: v2.6.0
438
+ **版本**: v2.6.1
439
439
 
440
440
  **核心功能**:
441
441
  - 支持多种Modbus协议(Telnet ASCII、RTU over TCP、Modbus TCP、Modbus RTU串口)
@@ -454,7 +454,12 @@ msg.payload = 1; // 或 0
454
454
  - Node.js: >=14.0.0
455
455
  - Node-RED: >=2.0.0
456
456
 
457
- **最新更新(v2.6.0)**:
457
+ **最新更新(v2.6.1)**:
458
+ - **串口自动重连**:断开后5秒自动重连,确保长期稳定运行
459
+ - **连接状态管理**:完善的串口和TCP连接状态监控
460
+ - **错误恢复**:串口拔插后自动恢复,无需重启Node-RED
461
+
462
+ **v2.6.0更新**:
458
463
  - **双模式支持**:完整支持开关按钮和场景按钮两种模式
459
464
  - 开关按钮:独立开/关控制 + SET协议LED反馈
460
465
  - 场景按钮:Toggle切换控制 + REPORT协议LED反馈
@@ -25,6 +25,7 @@ module.exports = function(RED) {
25
25
  // 共享的连接实例
26
26
  node.connection = null; // TCP socket 或 SerialPort
27
27
  node.isOpening = false; // 标记是否正在打开连接
28
+ node.isClosing = false; // 标记节点是否正在关闭
28
29
 
29
30
  // 数据监听器列表(每个从站开关节点注册一个)
30
31
  node.dataListeners = [];
@@ -131,6 +132,18 @@ module.exports = function(RED) {
131
132
  // 监听关闭
132
133
  node.connection.on('close', () => {
133
134
  node.log('串口已关闭');
135
+ // 自动重连(如果还有监听器在使用)
136
+ setTimeout(() => {
137
+ if (node.dataListeners.length > 0 && !node.isClosing) {
138
+ node.log('检测到串口断开,5秒后尝试重新连接...');
139
+ node.openSerialConnection();
140
+ }
141
+ }, 5000);
142
+ });
143
+
144
+ // 监听断开连接
145
+ node.connection.on('disconnect', () => {
146
+ node.log('串口设备已拔出');
134
147
  });
135
148
  });
136
149
  } catch (err) {
@@ -226,6 +239,8 @@ module.exports = function(RED) {
226
239
 
227
240
  // 节点关闭时清理
228
241
  node.on('close', function(done) {
242
+ node.isClosing = true; // 标记正在关闭,防止自动重连
243
+
229
244
  // 清空所有监听器
230
245
  node.dataListeners = [];
231
246
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-symi-modbus",
3
- "version": "2.6.0",
3
+ "version": "2.6.1",
4
4
  "description": "Node-RED Modbus节点,支持TCP/串口通信、串口自动搜索、多设备轮询、智能MQTT连接(自动fallback HassOS/Docker环境)、Home Assistant自动发现和物理开关面板双向同步,工控机长期稳定运行",
5
5
  "main": "nodes/modbus-master.js",
6
6
  "scripts": {
@@ -42,7 +42,6 @@
42
42
  "dependencies": {
43
43
  "modbus-serial": "^8.0.23",
44
44
  "mqtt": "^5.14.1",
45
- "node-red-contrib-symi-modbus": "file:node-red-contrib-symi-modbus-2.6.0.tgz",
46
45
  "serialport": "^12.0.0"
47
46
  },
48
47
  "repository": {