From f56441867f2cc77567f97a92348a5d878f0dca05 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期四, 12 三月 2026 18:24:15 +0800
Subject: [PATCH] Add AGENTS instructions and updates

---
 Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/ConveyorLine/CommonConveyorLine.cs |   53 +++++++++++++++++++++++++++++++----------------------
 1 files changed, 31 insertions(+), 22 deletions(-)

diff --git a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/ConveyorLine/CommonConveyorLine.cs b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/ConveyorLine/CommonConveyorLine.cs
index efcb519..7ff5c39 100644
--- a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/ConveyorLine/CommonConveyorLine.cs
+++ b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/ConveyorLine/CommonConveyorLine.cs
@@ -23,6 +23,7 @@
 using System.Text;
 using System.Threading.Tasks;
 using WIDESEAWCS_Communicator;
+using WIDESEAWCS_Core.Helper;
 using WIDESEAWCS_QuartzJob.ConveyorLine.Enum;
 using WIDESEAWCS_QuartzJob.DeviceBase;
 using WIDESEAWCS_QuartzJob.DTO;
@@ -180,7 +181,7 @@
         /// <exception cref="Exception"></exception>
         public bool SendCommand<T>(T command, string deviceChildCode) where T : IDataTransfer, new()
         {
-            if(Communicator is SiemensS7)
+            if (Communicator is SiemensS7)
             {
                 if (!IsConnected) throw new Exception($"閫氳杩炴帴閿欒锛岃妫�鏌ョ綉缁�");
                 DeviceProDTO? devicePro = _deviceProDTOs.Where(x => x.DeviceProParamType == nameof(DeviceCommand) && x.DeviceChildCode == deviceChildCode).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
@@ -271,29 +272,37 @@
         /// <exception cref="Exception"></exception>
         public bool IsOccupied(string deviceChildCode)
         {
-            if (Communicator.IsConnected)
+            // 1. 鍏堟鏌ラ�氫俊鐘舵��
+            if (!Communicator.IsConnected)
             {
-                List<DeviceProDTO> devicePros = _deviceProDTOs.Where(x => x.DeviceProParamType == ConveyorLineStatus.CV_State.ToString()).ToList();
-                if (devicePros.Count == 0)
-                {
-                    //todo 鍗忚淇℃伅鏈幏鍙栧埌鏃舵姏鍑哄紓甯�
-                    throw new Exception();
-                }
-                for (int i = 0; i < devicePros.Count; i++)
-                {
-                    object readStatus = Communicator.ReadAsObj(devicePros[i].DeviceProAddress, devicePros[i].DeviceDataType);
-                    //todo 鍗忚鏄庣粏淇℃伅鏈幏鍙栧埌鏃舵姏鍑哄紓甯�
-                    DeviceProtocolDetailDTO? deviceProtocolDetail = _deviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == devicePros[i].DeviceProParamName) ?? throw new Exception();
-                    deviceProtocolDetail = _deviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == devicePros[i].DeviceProParamType && x.ProtocalDetailValue.Equals(readStatus.ToString()));
-                    if (deviceProtocolDetail != null)
-                    {
-                        return true;
-                    }
-                    return false;
-                }
+                throw new InvalidOperationException($"閫氫俊鏈繛鎺ワ紝鏃犳硶鑾峰彇璁惧[{deviceChildCode}]鐨勫崰鐢ㄧ姸鎬�");
             }
-            //todo 閫氳鏈繛鎺ユ椂鎶涘嚭寮傚父
-            return false;
+            // 2. 鑾峰彇璁惧鍗忚淇℃伅
+            var devicePro = _deviceProDTOs.FirstOrDefault(x =>
+                x.DeviceProParamType == ConveyorLineStatus.IsOccupied.ToString() &&
+                x.DeviceChildCode == deviceChildCode);
+
+            if (devicePro == null)
+            {
+                throw new KeyNotFoundException($"鏈壘鍒拌澶嘯{deviceChildCode}]鐨勫崰鐢ㄧ姸鎬佸崗璁厤缃�");
+            }
+
+            // 3. 璇诲彇璁惧鐘舵�佸��
+            object readStatus;
+            try
+            {
+                readStatus = Communicator.ReadAsObj(devicePro.DeviceProAddress, devicePro.DeviceDataType);
+            }
+            catch (Exception ex)
+            {
+                throw new Exception($"璇诲彇璁惧[{deviceChildCode}]鍦板潃[{devicePro.DeviceProAddress}]澶辫触", ex);
+            }
+
+            // 4. 鍒ゆ柇鐘舵�佸�兼槸鍚﹀尮閰嶅崰鐢ㄧ姸鎬佹槑缁�
+            var readStatusValue = readStatus?.ToString() ?? string.Empty;
+            return _deviceProtocolDetailDTOs.Any(x =>
+                x.ProtocolDetailType == devicePro.DeviceProParamType &&
+                string.Equals(x.ProtocalDetailValue, readStatusValue, StringComparison.Ordinal));
         }
 
         /// <summary>

--
Gitblit v1.9.3