Skip to content
This repository was archived by the owner on Jun 18, 2026. It is now read-only.

Commit ca34b3b

Browse files
author
changlin.cai
committed
[新增] Modbus TCP Master Connector + WebUI 卡片化 + Unobserved Task 修正
主要功能: - 新增 Modbus TCP Master port 類型 — 內建 FluentModbus polling, 支援 FC 01/02/03/04,dataType bit/bits/uint16/int16/uint32/int32/float32, scale + offset,自動重連節流,連線失敗逐步退避。 - PortData 加 ModbusConfig + ModbusRegisterMap,向後相容(nullable)。 - NetworkMessageRouter 加 InjectSynthesizedMessageAsync — 讓 Modbus poller 把組好的 id:X;reg:N 訊息餵進既有 mask + forward pipeline。 - WebUI Port 管理頁從 table 改成 card grid,含協定 badge、連線細條、 Mask tag、metadata icon 區、stats、device IDs 摘要、icon-only 操作按鈕。 - WebUI 表單加 Modbus 設定區(Slave ID / Polling 間隔 / Device ID / Registers JSON),3 語系補上 selectAll / totalPort / sourceLabel key。 - Polling 重撈 (3 秒一次) 不再清除使用者勾選 — 重 render 前保留 checked 狀態,render 後恢復。 - 4 處 fire-and-forget task 補上 ContinueWith — 不再噴 Critical Unobserved Task exception (TCPServer NotifyAsync、UDP SweepStaleDevices、 UDP SendAsync forward)。 工具: - modbus_slave_sim.py — pymodbus 迷你 slave 模擬器,無需安裝 runtime, 自動產生 GrayCode + sine wave 測試資料。
1 parent 8fedd7e commit ca34b3b

13 files changed

Lines changed: 812 additions & 98 deletions

File tree

SDK/Arduino/EdgeLink/examples/tcp_sensor/tcp_sensor.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212

1313
#include <WiFi.h>
14-
#include <EdgeLink.h>
14+
#include <EdgeLinkTCP.h>
1515

1616
// ── 設定 ──────────────────────────────────
1717
const char* WIFI_SSID = "your-ssid";

Server/EdgeLinkServer.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="8.0.0" />
1818
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
1919
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
20+
<PackageReference Include="FluentModbus" Version="5.3.0" />
2021
</ItemGroup>
2122

2223
<ItemGroup>

Server/NetworkServer/Base/Models/PortData.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class PortData
2929
public string RequestMode = "";
3030
public string SourceProtocolName = "";
3131
public string SourceProtocolId = "";
32+
public ModbusConfig? Modbus;
3233

3334
[JsonIgnore] public int CurrentConnections;
3435
[JsonIgnore] public int TotalConnections;
@@ -42,3 +43,27 @@ public class PortDetails
4243
public string Port = "";
4344
public string Description = "";
4445
}
46+
47+
// Modbus TCP Master polling 配置
48+
[Serializable]
49+
public class ModbusConfig
50+
{
51+
public int SlaveId = 1;
52+
public int PollIntervalMs = 100; // 10 Hz default
53+
public int ConnectTimeoutMs = 1000;
54+
public int ReadTimeoutMs = 1000;
55+
public string DeviceId = ""; // 變成 id:xxx 欄位的值
56+
public List<ModbusRegisterMap> Registers = new();
57+
}
58+
59+
[Serializable]
60+
public class ModbusRegisterMap
61+
{
62+
public string Name = ""; // 欄位名 (yaw, pitch, jx, jy ...)
63+
public int FunctionCode = 3; // 1=Coil, 2=DI, 3=Holding, 4=Input
64+
public int StartAddress;
65+
public int Quantity = 1;
66+
public string DataType = "uint16"; // bit | uint16 | int16 | uint32 | int32 | float32 | bits-int (GrayCode 8-16 bits 組合)
67+
public double Scale = 1.0;
68+
public double Offset;
69+
}

Server/NetworkServer/Connector/NetworkConnectorCore.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using EdgeLink.NetworkServer.Base;
22
using EdgeLink.NetworkServer.Base.Models;
33
using EdgeLink.NetworkServer.Logging;
4+
using EdgeLink.NetworkServer.Modbus;
45
using EdgeLink.NetworkServer.TCP;
56
using EdgeLink.NetworkServer.Udp;
67

@@ -18,9 +19,10 @@ public NetworkConnectorCore(IMainThreadDispatcher? dispatcher = null)
1819
_udpConnector = new UdpConnector(dispatcher);
1920
_connectors = new Dictionary<string, NetworkConnectorBase>
2021
{
21-
{ "UDP", _udpConnector },
22-
{ "TCP SERVER", _tcpServerConnector },
23-
{ "TCP CLIENT", new TCPClientConnector(dispatcher) }
22+
{ "UDP", _udpConnector },
23+
{ "TCP SERVER", _tcpServerConnector },
24+
{ "TCP CLIENT", new TCPClientConnector(dispatcher) },
25+
{ "MODBUS TCP MASTER", new ModbusTcpMasterConnector() }
2426
};
2527
}
2628

0 commit comments

Comments
 (0)