node-red-contrib-symi-modbus 2.8.7 → 2.8.8
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/nodes/serial-port-config.js +13 -30
- package/package.json +1 -1
|
@@ -169,13 +169,21 @@ module.exports = function(RED) {
|
|
|
169
169
|
|
|
170
170
|
// 打开串口连接
|
|
171
171
|
node.openSerialConnection = function() {
|
|
172
|
+
// 如果串口已经打开,直接返回(不要关闭重开)
|
|
172
173
|
if (node.connection && node.connection.isOpen) {
|
|
173
|
-
node.
|
|
174
|
+
node.debug('串口已打开,跳过重复打开');
|
|
174
175
|
return;
|
|
175
176
|
}
|
|
176
177
|
|
|
178
|
+
// 如果正在打开中,跳过
|
|
177
179
|
if (node.isOpening) {
|
|
178
|
-
node.
|
|
180
|
+
node.debug('串口正在打开中,跳过重复打开');
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// 如果节点正在关闭,不要打开
|
|
185
|
+
if (node.isClosing) {
|
|
186
|
+
node.debug('节点正在关闭,取消串口打开操作');
|
|
179
187
|
return;
|
|
180
188
|
}
|
|
181
189
|
|
|
@@ -185,33 +193,8 @@ module.exports = function(RED) {
|
|
|
185
193
|
node.reconnectTimer = null;
|
|
186
194
|
}
|
|
187
195
|
|
|
188
|
-
//
|
|
189
|
-
|
|
190
|
-
if (node.connection) {
|
|
191
|
-
try {
|
|
192
|
-
node.connection.removeAllListeners();
|
|
193
|
-
if (node.connection.isOpen) {
|
|
194
|
-
node.connection.close((closeErr) => {
|
|
195
|
-
if (closeErr) {
|
|
196
|
-
node.debug(`串口关闭时出错: ${closeErr.message}`);
|
|
197
|
-
}
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
} catch (err) {
|
|
201
|
-
// 忽略清理错误
|
|
202
|
-
}
|
|
203
|
-
node.connection = null;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
// 如果之前串口是打开的,等待500ms让系统完全释放资源
|
|
207
|
-
const openDelay = needDelay ? 500 : 0;
|
|
208
|
-
|
|
209
|
-
setTimeout(() => {
|
|
210
|
-
// 检查节点是否正在关闭
|
|
211
|
-
if (node.isClosing) {
|
|
212
|
-
node.debug('节点正在关闭,取消串口打开操作');
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
196
|
+
// 只有在连接不存在或已关闭时才创建新连接
|
|
197
|
+
if (!node.connection || !node.connection.isOpen) {
|
|
215
198
|
|
|
216
199
|
node.isOpening = true;
|
|
217
200
|
|
|
@@ -340,7 +323,7 @@ module.exports = function(RED) {
|
|
|
340
323
|
}, delay);
|
|
341
324
|
}
|
|
342
325
|
}
|
|
343
|
-
}
|
|
326
|
+
} // 关闭 if (!node.connection || !node.connection.isOpen)
|
|
344
327
|
};
|
|
345
328
|
|
|
346
329
|
// 获取连接对象(用于Mesh设备发现等场景)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-symi-modbus",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.8",
|
|
4
4
|
"description": "Node-RED Modbus节点,支持TCP/串口通信、串口自动搜索、多设备轮询、可选MQTT集成(支持纯本地模式和MQTT模式)、Home Assistant自动发现、HomeKit网桥、可视化控制看板、自定义协议转换和物理开关面板双向同步,工控机长期稳定运行",
|
|
5
5
|
"main": "nodes/modbus-master.js",
|
|
6
6
|
"scripts": {
|