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 作为历史根节点

---
 PLCHelper/BoolReader.cs |   60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 60 insertions(+), 0 deletions(-)

diff --git a/PLCHelper/BoolReader.cs b/PLCHelper/BoolReader.cs
new file mode 100644
index 0000000..ee8635c
--- /dev/null
+++ b/PLCHelper/BoolReader.cs
@@ -0,0 +1,60 @@
+锘縰sing HslCommunication.Profinet.Siemens;
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace PLCHelper
+{
+
+    public class BoolReader
+    {
+        private bool lastVallue = false;
+
+        private string Address = string.Empty;
+        private int Timeout = 1000;
+
+        private SiemensS7Net client;
+
+        private volatile bool isRunning = false;
+
+        public event EventHandler<DataChangedArg<bool>> DataChanged;
+
+        public BoolReader(SiemensS7Net client, string address, bool initValue = false)
+        {
+            this.client = client;
+            this.Address = address;
+            this.lastVallue = initValue;
+        }
+
+        public void Stop()
+        {
+            isRunning = false;
+        }
+
+        public void Run()
+        {
+            isRunning = true;
+            Task.Run(() =>
+            {
+                while (isRunning)
+                {
+                    var res = client.ReadBool(Address);
+                    if (res.IsSuccess)
+                    {
+                        bool val = res.Content;
+                        if (val != lastVallue)
+                        {
+                            DataChanged?.Invoke(this, new DataChangedArg<bool>
+                            {
+                                oldValue = lastVallue,
+                                newValue = val
+                            });
+                            lastVallue = val;
+                        }
+                    }
+                    Thread.Sleep(Timeout);
+                }
+            });
+        }
+    }
+}

--
Gitblit v1.9.1