node-red-contrib-symi-modbus 2.5.2 → 2.5.3

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.
@@ -0,0 +1,198 @@
1
+ [
2
+ {
3
+ "id": "modbus_master_1",
4
+ "type": "modbus-master",
5
+ "name": "Modbus主站",
6
+ "connectionType": "tcp",
7
+ "tcpHost": "127.0.0.1",
8
+ "tcpPort": "502",
9
+ "serialPort": "COM1",
10
+ "serialBaudRate": "9600",
11
+ "serialDataBits": "8",
12
+ "serialStopBits": "1",
13
+ "serialParity": "none",
14
+ "slaveStartAddress": "10",
15
+ "slaveCount": "1",
16
+ "coilStart": "0",
17
+ "coilEnd": "31",
18
+ "pollInterval": "100",
19
+ "enableMqtt": false,
20
+ "mqttBroker": "mqtt://localhost:1883",
21
+ "mqttUsername": "",
22
+ "mqttPassword": "",
23
+ "mqttBaseTopic": "modbus/relay",
24
+ "x": 320,
25
+ "y": 140,
26
+ "wires": [["debug_1"]]
27
+ },
28
+ {
29
+ "id": "debug_1",
30
+ "type": "debug",
31
+ "name": "轮询输出",
32
+ "active": true,
33
+ "tosidebar": true,
34
+ "console": false,
35
+ "tostatus": false,
36
+ "complete": "payload",
37
+ "targetType": "msg",
38
+ "x": 520,
39
+ "y": 140,
40
+ "wires": []
41
+ },
42
+ {
43
+ "id": "inject_start",
44
+ "type": "inject",
45
+ "name": "启动轮询",
46
+ "props": [
47
+ {
48
+ "p": "payload"
49
+ }
50
+ ],
51
+ "repeat": "",
52
+ "crontab": "",
53
+ "once": true,
54
+ "onceDelay": "1",
55
+ "topic": "",
56
+ "payload": "{\"cmd\":\"start\"}",
57
+ "payloadType": "json",
58
+ "x": 130,
59
+ "y": 100,
60
+ "wires": [["modbus_master_1"]]
61
+ },
62
+ {
63
+ "id": "inject_stop",
64
+ "type": "inject",
65
+ "name": "停止轮询",
66
+ "props": [
67
+ {
68
+ "p": "payload"
69
+ }
70
+ ],
71
+ "repeat": "",
72
+ "crontab": "",
73
+ "once": false,
74
+ "onceDelay": "0.1",
75
+ "topic": "",
76
+ "payload": "{\"cmd\":\"stop\"}",
77
+ "payloadType": "json",
78
+ "x": 130,
79
+ "y": 140,
80
+ "wires": [["modbus_master_1"]]
81
+ },
82
+ {
83
+ "id": "inject_write_coil",
84
+ "type": "inject",
85
+ "name": "打开线圈0",
86
+ "props": [
87
+ {
88
+ "p": "payload"
89
+ }
90
+ ],
91
+ "repeat": "",
92
+ "crontab": "",
93
+ "once": false,
94
+ "onceDelay": "0.1",
95
+ "topic": "",
96
+ "payload": "{\"cmd\":\"writeCoil\",\"slave\":10,\"coil\":0,\"value\":true}",
97
+ "payloadType": "json",
98
+ "x": 130,
99
+ "y": 180,
100
+ "wires": [["modbus_master_1"]]
101
+ },
102
+ {
103
+ "id": "inject_write_coil_off",
104
+ "type": "inject",
105
+ "name": "关闭线圈0",
106
+ "props": [
107
+ {
108
+ "p": "payload"
109
+ }
110
+ ],
111
+ "repeat": "",
112
+ "crontab": "",
113
+ "once": false,
114
+ "onceDelay": "0.1",
115
+ "topic": "",
116
+ "payload": "{\"cmd\":\"writeCoil\",\"slave\":10,\"coil\":0,\"value\":false}",
117
+ "payloadType": "json",
118
+ "x": 130,
119
+ "y": 220,
120
+ "wires": [["modbus_master_1"]]
121
+ },
122
+ {
123
+ "id": "switch_node_1",
124
+ "type": "modbus-slave-switch",
125
+ "name": "面板1按键1",
126
+ "connectionType": "shared",
127
+ "masterNode": "modbus_master_1",
128
+ "rs485Config": "",
129
+ "switchId": "1",
130
+ "buttonNumber": "1",
131
+ "targetSlaveAddress": "10",
132
+ "targetCoilNumber": "0",
133
+ "enableMqtt": false,
134
+ "mqttBroker": "",
135
+ "mqttUsername": "",
136
+ "mqttPassword": "",
137
+ "mqttBaseTopic": "homeassistant",
138
+ "haDeviceName": "面板1按键1",
139
+ "x": 320,
140
+ "y": 300,
141
+ "wires": [["debug_2"]]
142
+ },
143
+ {
144
+ "id": "debug_2",
145
+ "type": "debug",
146
+ "name": "开关状态",
147
+ "active": true,
148
+ "tosidebar": true,
149
+ "console": false,
150
+ "tostatus": false,
151
+ "complete": "payload",
152
+ "targetType": "msg",
153
+ "x": 520,
154
+ "y": 300,
155
+ "wires": []
156
+ },
157
+ {
158
+ "id": "inject_switch_on",
159
+ "type": "inject",
160
+ "name": "开关ON",
161
+ "props": [
162
+ {
163
+ "p": "payload"
164
+ }
165
+ ],
166
+ "repeat": "",
167
+ "crontab": "",
168
+ "once": false,
169
+ "onceDelay": "0.1",
170
+ "topic": "",
171
+ "payload": "true",
172
+ "payloadType": "bool",
173
+ "x": 130,
174
+ "y": 280,
175
+ "wires": [["switch_node_1"]]
176
+ },
177
+ {
178
+ "id": "inject_switch_off",
179
+ "type": "inject",
180
+ "name": "开关OFF",
181
+ "props": [
182
+ {
183
+ "p": "payload"
184
+ }
185
+ ],
186
+ "repeat": "",
187
+ "crontab": "",
188
+ "once": false,
189
+ "onceDelay": "0.1",
190
+ "topic": "",
191
+ "payload": "false",
192
+ "payloadType": "bool",
193
+ "x": 130,
194
+ "y": 320,
195
+ "wires": [["switch_node_1"]]
196
+ }
197
+ ]
198
+
@@ -4,16 +4,7 @@
4
4
  color: '#3FADB5',
5
5
  defaults: {
6
6
  name: {value: "Modbus主站"},
7
- connectionType: {value: "tcp"},
8
- // TCP配置
9
- tcpHost: {value: "127.0.0.1"},
10
- tcpPort: {value: 502},
11
- // 串口配置
12
- serialPort: {value: "COM1"},
13
- serialBaudRate: {value: 9600},
14
- serialDataBits: {value: 8},
15
- serialStopBits: {value: 1},
16
- serialParity: {value: "none"},
7
+ modbusServer: {value: "", type: "modbus-server-config"},
17
8
  // 从站配置列表(数组)
18
9
  slaves: {value: [{
19
10
  address: 10,
@@ -22,7 +13,7 @@
22
13
  pollInterval: 200
23
14
  }]},
24
15
  // MQTT配置(引用config节点)
25
- enableMqtt: {value: false},
16
+ enableMqtt: {value: true},
26
17
  mqttServer: {value: "", type: "mqtt-server-config"}
27
18
  },
28
19
  inputs: 1,
@@ -44,6 +35,8 @@
44
35
  }];
45
36
  }
46
37
 
38
+ // 移除旧的连接类型切换逻辑(现在使用服务器配置节点)
39
+
47
40
  // 渲染从站列表
48
41
  function renderSlaveList() {
49
42
  var container = $("#slave-list-container");
@@ -172,21 +165,6 @@
172
165
  // 初始化渲染
173
166
  renderSlaveList();
174
167
 
175
- // 切换连接类型时显示/隐藏相关配置
176
- $("#node-input-connectionType").on("change", function() {
177
- var connType = $(this).val();
178
- if (connType === "tcp") {
179
- $(".form-row-tcp").show();
180
- $(".form-row-serial").hide();
181
- } else {
182
- $(".form-row-tcp").hide();
183
- $(".form-row-serial").show();
184
- }
185
- });
186
-
187
- // 初始化显示
188
- $("#node-input-connectionType").trigger("change");
189
-
190
168
  // MQTT开关
191
169
  $("#node-input-enableMqtt").on("change", function() {
192
170
  if ($(this).is(":checked")) {
@@ -198,67 +176,6 @@
198
176
 
199
177
  // 初始化MQTT显示
200
178
  $("#node-input-enableMqtt").trigger("change");
201
-
202
- // 搜索串口按钮
203
- $("#btn-search-ports-master").on("click", function() {
204
- var btn = $(this);
205
- var inputBox = $("#node-input-serialPort");
206
- var selectBox = $("#port-list-master");
207
-
208
- btn.prop("disabled", true).html('<i class="fa fa-spinner fa-spin"></i> 搜索中');
209
-
210
- $.ajax({
211
- url: 'modbus-master/serialports',
212
- type: 'GET',
213
- success: function(ports) {
214
- selectBox.empty().append('<option value="">-- 选择检测到的串口 --</option>');
215
-
216
- if (ports.length === 0) {
217
- selectBox.append('<option disabled>未找到可用串口</option>');
218
- RED.notify("未找到可用串口,请手动输入串口路径", "warning");
219
- } else if (ports.length === 1 && ports[0].isError) {
220
- // 显示错误提示
221
- selectBox.append('<option disabled>' + ports[0].comName + '</option>');
222
- selectBox.append('<option disabled style="font-size:11px;">' + ports[0].manufacturer + '</option>');
223
- RED.notify(ports[0].manufacturer, "warning");
224
- } else {
225
- var hasValidPort = false;
226
- ports.forEach(function(port) {
227
- if (!port.isError) {
228
- var label = port.comName;
229
- if (port.manufacturer && port.manufacturer !== '未知设备') {
230
- label += ' - ' + port.manufacturer;
231
- }
232
- selectBox.append('<option value="' + port.comName + '">' + label + '</option>');
233
- hasValidPort = true;
234
- }
235
- });
236
- if (hasValidPort) {
237
- // 显示下拉框,隐藏输入框
238
- inputBox.hide();
239
- selectBox.show();
240
- } else {
241
- RED.notify("未检测到可用串口,请手动输入", "warning");
242
- }
243
- }
244
-
245
- btn.prop("disabled", false).html('<i class="fa fa-search"></i> 搜索');
246
- },
247
- error: function() {
248
- RED.notify("搜索串口失败。如运行在Docker容器,需要映射USB设备", "error");
249
- btn.prop("disabled", false).html('<i class="fa fa-search"></i> 搜索');
250
- }
251
- });
252
- });
253
-
254
- // 选择串口(下拉选择)
255
- $("#port-list-master").on("change", function() {
256
- var selectedPort = $(this).val();
257
- if (selectedPort) {
258
- $("#node-input-serialPort").val(selectedPort).show();
259
- $(this).hide();
260
- }
261
- });
262
179
  },
263
180
  oneditsave: function() {
264
181
  // 保存从站配置到节点
@@ -274,99 +191,10 @@
274
191
  <input type="text" id="node-input-name" placeholder="Modbus主站">
275
192
  </div>
276
193
 
277
- <!-- 连接配置区域 -->
278
- <hr style="margin: 15px 0; border: 0; border-top: 2px solid #e0e0e0;">
279
- <div class="form-row">
280
- <label style="width: 100%; margin-bottom: 8px;">
281
- <i class="fa fa-plug" style="color: #2196f3;"></i>
282
- <span style="font-size: 14px; font-weight: 600; color: #333;">连接配置</span>
283
- </label>
284
- </div>
285
-
194
+ <!-- Modbus服务器配置 -->
286
195
  <div class="form-row">
287
- <label for="node-input-connectionType" style="width: 110px;"><i class="fa fa-exchange"></i> 连接类型</label>
288
- <select id="node-input-connectionType" style="width: calc(70% - 110px);">
289
- <option value="tcp">TCP/IP</option>
290
- <option value="serial">串口</option>
291
- </select>
292
- </div>
293
-
294
- <!-- TCP配置 -->
295
- <div class="form-row form-row-tcp">
296
- <label for="node-input-tcpHost" style="width: 110px;"><i class="fa fa-server"></i> TCP主机</label>
297
- <input type="text" id="node-input-tcpHost" placeholder="192.168.1.100" style="width: calc(70% - 110px);">
298
- <div style="font-size: 11px; color: #888; margin-left: 110px; margin-top: 3px;">
299
- Modbus TCP服务器IP地址
300
- </div>
301
- </div>
302
-
303
- <div class="form-row form-row-tcp">
304
- <label for="node-input-tcpPort" style="width: 110px;"><i class="fa fa-plug"></i> TCP端口</label>
305
- <input type="number" id="node-input-tcpPort" placeholder="502" style="width: 100px;">
306
- <span style="margin-left: 10px; font-size: 12px; color: #666;">默认 502</span>
307
- </div>
308
-
309
- <!-- 串口配置 -->
310
- <div class="form-row form-row-serial">
311
- <label for="node-input-serialPort" style="width: 110px;"><i class="fa fa-terminal"></i> 串口</label>
312
- <div style="display: inline-block; width: calc(70% - 110px);">
313
- <div style="display: flex; gap: 5px; align-items: center;">
314
- <input type="text" id="node-input-serialPort" placeholder="COM1, /dev/ttyUSB0, /dev/cu.usbserial-xxx" style="flex: 1; padding: 5px 8px; border: 1px solid #ccc; border-radius: 4px; font-size: 13px;">
315
- <select id="port-list-master" style="flex: 1; padding: 5px; font-family: monospace; font-size: 12px; border: 1px solid #ccc; border-radius: 4px; display: none;">
316
- <option value="">-- 选择检测到的串口 --</option>
317
- </select>
318
- <button type="button" id="btn-search-ports-master" style="padding: 6px 12px; background: #2196f3; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 12px; white-space: nowrap; transition: background 0.3s;">
319
- <i class="fa fa-search"></i> 搜索
320
- </button>
321
- </div>
322
- <div style="font-size: 11px; color: #555; padding: 8px 10px; background: linear-gradient(135deg, #e8f5e9 0%, #f1f8e9 100%); border-left: 4px solid #4caf50; border-radius: 4px; margin-top: 6px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); line-height: 1.5;">
323
- <strong style="color: #2e7d32;">💡 串口说明:</strong><br>
324
- <span style="color: #555; font-size: 11px;">
325
- • <strong>Windows</strong>: COM1, COM2, COM3...<br>
326
- • <strong>Linux</strong>: /dev/ttyUSB0, /dev/ttyS0, /dev/ttyAMA0<br>
327
- • <strong>macOS</strong>: <span style="background: #fff3cd; padding: 1px 4px; border-radius: 2px; font-weight: 600;">/dev/cu.*</span> (例如 /dev/cu.usbserial-xxx, /dev/cu.wchusbserial*)<br>
328
- • <strong>HassOS</strong>: 插件配置添加设备映射即可<br>
329
- • <strong>Docker</strong>: 需映射设备 <code style="background: #c8e6c9; padding: 2px 6px; border-radius: 3px; font-size: 10px;">--device=/dev/ttyUSB0</code> 或 <code style="background: #c8e6c9; padding: 2px 6px; border-radius: 3px; font-size: 10px;">--privileged</code>
330
- </span>
331
- </div>
332
- </div>
333
- </div>
334
-
335
- <div class="form-row form-row-serial">
336
- <label for="node-input-serialBaudRate" style="width: 110px;"><i class="fa fa-tachometer"></i> 波特率</label>
337
- <select id="node-input-serialBaudRate" style="width: 150px;">
338
- <option value="9600">9600</option>
339
- <option value="19200">19200</option>
340
- <option value="38400">38400</option>
341
- <option value="57600">57600</option>
342
- <option value="115200">115200</option>
343
- </select>
344
- <span style="margin-left: 10px; font-size: 11px; color: #888;">8-N-1固定配置</span>
345
- </div>
346
-
347
- <div class="form-row form-row-serial" style="display: none;">
348
- <label for="node-input-serialDataBits" style="width: 110px;"><i class="fa fa-database"></i> 数据位</label>
349
- <select id="node-input-serialDataBits" style="width: 100px;">
350
- <option value="7">7</option>
351
- <option value="8" selected>8</option>
352
- </select>
353
- </div>
354
-
355
- <div class="form-row form-row-serial" style="display: none;">
356
- <label for="node-input-serialStopBits" style="width: 110px;"><i class="fa fa-stop"></i> 停止位</label>
357
- <select id="node-input-serialStopBits" style="width: 100px;">
358
- <option value="1" selected>1</option>
359
- <option value="2">2</option>
360
- </select>
361
- </div>
362
-
363
- <div class="form-row form-row-serial" style="display: none;">
364
- <label for="node-input-serialParity" style="width: 110px;"><i class="fa fa-check"></i> 校验位</label>
365
- <select id="node-input-serialParity" style="width: 100px;">
366
- <option value="none" selected>无</option>
367
- <option value="even">偶校验</option>
368
- <option value="odd">奇校验</option>
369
- </select>
196
+ <label for="node-input-modbusServer"><i class="fa fa-server"></i> Modbus服务器</label>
197
+ <input type="text" id="node-input-modbusServer" placeholder="选择或添加Modbus服务器">
370
198
  </div>
371
199
 
372
200
  <!-- 从站配置 -->
@@ -377,7 +205,7 @@
377
205
  <span style="font-size: 14px; font-weight: 600; color: #333;">从站设备配置</span>
378
206
  </label>
379
207
  <div style="font-size: 11px; color: #555; padding: 10px 12px; background: linear-gradient(135deg, #e3f2fd 0%, #f0f7ff 100%); border-left: 4px solid #2196f3; border-radius: 4px; margin-bottom: 12px; box-shadow: 0 1px 3px rgba(0,0,0,0.08);">
380
- <strong>配置说明:</strong>最多添加10台设备,地址从10开始递增(10=0x0A, 11=0x0B...),推荐轮询间隔≥200ms
208
+ <strong>配置说明:</strong>最多添加10台设备,地址从10开始递增(10=0x0A, 11=0x0B...),推荐轮询间隔≥1000ms
381
209
  </div>
382
210
  <div id="slave-list-container" style="width: 100%; margin-top: 10px;">
383
211
  <!-- 从站列表将在这里动态生成 -->
@@ -406,12 +234,12 @@
406
234
  <label for="node-input-mqttServer" style="width: 110px;"><i class="fa fa-server"></i> MQTT服务器</label>
407
235
  <input type="text" id="node-input-mqttServer" placeholder="选择或添加MQTT服务器配置" style="width: calc(70% - 110px);">
408
236
  <div style="font-size: 11px; color: #555; padding: 10px 12px; background: linear-gradient(135deg, #fff3cd 0%, #fff8e1 100%); border-left: 4px solid #ff9800; border-radius: 4px; margin-left: 110px; margin-top: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); line-height: 1.6;">
409
- <strong style="color: #e65100; font-size: 11px;">🔧 MQTT配置说明:</strong><br>
237
+ <strong style="color: #e65100; font-size: 11px;">MQTT配置说明:</strong><br>
410
238
  <span style="color: #666; font-size: 11px;">
411
- • <strong>HassOS</strong>:直接填 <code style="background: #ffe0b2; padding: 2px 6px; border-radius: 3px; font-size: 10px;">127.0.0.1:1883</code> 即可(无需任何额外设置)<br>
412
- • <strong>局域网IP</strong>:直接填具体IP,如 <code style="background: #ffe0b2; padding: 2px 6px; border-radius: 3px; font-size: 10px;">192.168.1.100:1883</code><br>
413
- <strong>本机</strong>:填 <code style="background: #ffe0b2; padding: 2px 6px; border-radius: 3px; font-size: 10px;">localhost:1883</code> 或 <code style="background: #ffe0b2; padding: 2px 6px; border-radius: 3px; font-size: 10px;">127.0.0.1:1883</code><br>
414
- 支持智能fallback,配置错误也能自动尝试其他地址
239
+ HassOS:直接填 <code style="background: #ffe0b2; padding: 2px 6px; border-radius: 3px; font-size: 10px;">127.0.0.1:1883</code> 即可<br>
240
+ 局域网IP:直接填具体IP,如 <code style="background: #ffe0b2; padding: 2px 6px; border-radius: 3px; font-size: 10px;">192.168.1.100:1883</code><br>
241
+ 本机:填 <code style="background: #ffe0b2; padding: 2px 6px; border-radius: 3px; font-size: 10px;">localhost:1883</code> 或 <code style="background: #ffe0b2; padding: 2px 6px; border-radius: 3px; font-size: 10px;">127.0.0.1:1883</code><br>
242
+ 支持智能fallback,配置错误也能自动尝试其他地址
415
243
  </span>
416
244
  </div>
417
245
  </div>