From 9d1660270272180cd71147d6ddd53d1382643d2e Mon Sep 17 00:00:00 2001
From: wenxiangchao <wenxiangchao@ihengxin.com.cn>
Date: 星期一, 02 十一月 2026 18:00:14 +0800
Subject: [PATCH] merge: 并入远程 Initial commit 作为历史根节点

---
 Plugin.DODriverControl/Api/ModBusTcpController.cs |   63 +++++++++++++++++++++++++++++++
 1 files changed, 63 insertions(+), 0 deletions(-)

diff --git a/Plugin.DODriverControl/Api/ModBusTcpController.cs b/Plugin.DODriverControl/Api/ModBusTcpController.cs
new file mode 100644
index 0000000..e1b9fbf
--- /dev/null
+++ b/Plugin.DODriverControl/Api/ModBusTcpController.cs
@@ -0,0 +1,63 @@
+锘縰sing HslCommunication.ModBus;
+
+namespace Plugin.DODriverControl.Api
+{
+    public class ModBusTcpController : IDIOController
+    {
+        public string Ip { get; set; }
+        public int Port { get; set; }
+
+        private ModbusTcpNet client;
+
+        public bool Start(out string errMsg)
+        {
+            errMsg = string.Empty;
+            client = new ModbusTcpNet(Ip, Port);
+            var res = client.ConnectServer();
+            errMsg = res.Message;
+            return res.IsSuccess;
+        }
+
+        public bool ReadDIBool(string address, out bool res, out string msg)
+        {
+            var result = client?.ReadBool($"x=2;{address}");
+            msg = result?.Message;
+            res = result?.Content == true;
+            return result?.IsSuccess == true;
+        }
+
+        public bool ReadDOBool(string address, out bool res, out string msg)
+        {
+            var result = client?.ReadBool(address);
+            msg = result?.Message;
+            res = result?.Content == true;
+            return result?.IsSuccess == true;
+        }
+
+        public bool WriteBool(string address, bool value, out string msg)
+        {
+            msg = string.Empty;
+            var res = client?.Write(address, value);
+            msg = res.Message;
+            return res?.IsSuccess == true;
+        }
+
+        public bool Close()
+        {
+            return client?.ConnectClose()?.IsSuccess == true;
+
+        }
+        public void Dispose()
+        {
+            client?.Dispose();
+        }
+
+        public bool ReadDIDouble(string address, out double? res, out string msg)
+        {
+            var result = client?.ReadDouble($"x=2;{address}");
+            msg = result?.Message;
+            res = result?.Content;
+            return result?.IsSuccess == true;
+        }
+    }
+}

--
Gitblit v1.9.1