From e57938fbda9bff702004038f76d009422968bff5 Mon Sep 17 00:00:00 2001
From: alielie <alielie@git.com>
Date: 星期五, 06 十一月 2026 18:05:07 +0800
Subject: [PATCH] 提交代码

---
 DeviceService/DeviceManager/PLCDevice.cs |  138 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 138 insertions(+), 0 deletions(-)

diff --git a/DeviceService/DeviceManager/PLCDevice.cs b/DeviceService/DeviceManager/PLCDevice.cs
new file mode 100644
index 0000000..04efea0
--- /dev/null
+++ b/DeviceService/DeviceManager/PLCDevice.cs
@@ -0,0 +1,138 @@
+锘縰sing DeviceService.Core;
+using DeviceService.Core.Api;
+using DeviceService.Driver;
+using DeviceService.Entity;
+
+namespace DeviceService.Device
+{
+    [DeviceDesc("PLC")]
+    public class PLCDevice : NotifyBase, IDevice
+    {
+        private long _id;
+        public long Id
+        {
+            get => _id;
+            set
+            {
+                SetProperty(ref _id, value);
+            }
+        }
+
+        private string _deviceId;
+        public string DeviceId
+        {
+            get => _deviceId;
+            set
+            {
+                SetProperty(ref _deviceId, value);
+            }
+        }
+
+        private string _type = "PLC";
+        public string Type
+        {
+            get => _type;
+            private set
+            {
+                SetProperty(ref _type, value);
+            }
+        }
+
+        private string _brand;
+        public string Brand
+        {
+            get => _brand;
+            set
+            {
+                SetProperty(ref _brand, value);
+            }
+        }
+
+        private string _connectStr;
+        public string ConnectStr
+        {
+            get => _connectStr;
+            set
+            {
+                SetProperty(ref _connectStr, value);
+            }
+        }
+
+        private DeviceStatus _status;
+        public DeviceStatus Status
+        {
+            get => _status;
+            set
+            {
+                SetProperty(ref _status, value);
+            }
+        }
+
+        private AccessType _accessType;
+        public AccessType AccessType
+        {
+            get => _accessType;
+            set
+            {
+                SetProperty(ref _accessType, value);
+            }
+        }
+
+        private IPLCDriver driver;
+
+        public bool Init(out string msg)
+        {
+            msg = string.Empty;
+            try
+            {
+                driver = DriverManager.Instance.CreateDriverByTypeAndBrand<IPLCDriver>(Type, Brand);
+                return true;
+            }
+            catch (Exception ex)
+            {
+                msg = ex.Message;
+                return false;
+            }
+        }
+
+        public bool Open(out string msg)
+        {
+            if (driver == null)
+            {
+                msg = "璁惧灏氭湭鍒濆鍖栨垨鍒濆鍖栧け璐ャ��";
+                return false;
+            }
+
+            var res = driver.Open(out msg);
+            if (res)
+            {
+                Status = DeviceStatus.Busy;
+            }
+            return res;
+        }
+        public bool Close(out string msg)
+        {
+            if (driver == null)
+            {
+                msg = "璁惧灏氭湭鍒濆鍖栨垨鍒濆鍖栧け璐ャ��";
+                return false;
+            }
+
+            var res = driver.Close(out msg);
+            if (res)
+            {
+                Status = DeviceStatus.Idle;
+            }
+            return res;
+        }
+
+        public ResponseData HandleRequest(RequestData req)
+        {
+            return new ResponseData
+            {
+                Success = false,
+                Message = "鏈疄鐜�"
+            };
+        }
+    }
+}

--
Gitblit v1.9.1