From ce70974f99cd377579e9b07873c8ce79df6e05c3 Mon Sep 17 00:00:00 2001
From: zhangchengsong <zhangchengsong@hnkhzn.com>
Date: 星期二, 14 四月 2026 20:47:26 +0800
Subject: [PATCH] '完善二楼出库放货中屏蔽光栅'

---
 项目代码/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/WMSTaskService.cs |  204 +++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 181 insertions(+), 23 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/WMSTaskService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/WMSTaskService.cs"
index e852777..1370735 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/WMSTaskService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/WMSTaskService.cs"
@@ -16,7 +16,9 @@
 #endregion << 鐗� 鏈� 娉� 閲� >>
 
 using AutoMapper;
+using AutoMapper.Internal;
 using Castle.Components.DictionaryAdapter.Xml;
+using HslCommunication;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.AspNetCore.Mvc.RazorPages;
 using Microsoft.OpenApi.Any;
@@ -84,7 +86,7 @@
                 if (transfer.to == null || string.IsNullOrEmpty(transfer.to.code)) return apiResponse.ErrorResponse("鐩爣浣嶇疆涓嶈兘涓虹┖");
                 if (transfer.device == null || string.IsNullOrEmpty(transfer.device.uuid)) return apiResponse.ErrorResponse("璁惧鏍囪瘑涓嶈兘涓虹┖");
 
-                Dt_Task setask = BaseDal.QueryData(x => x.WMStaskid == transfer.barCode).FirstOrDefault();
+                Dt_Task? setask = BaseDal.QueryData(x => x.WMStaskid == transfer.barCode).FirstOrDefault();
                 if (setask != null) return apiResponse.ErrorResponse($"WCS宸叉湁褰撳墠浠诲姟锛屼笉鍙噸澶嶄笅鍙戯紝鎵樼洏缂栧彿锛歿transfer.barCode}");
 
 
@@ -158,23 +160,44 @@
             ApiResponse apiResponse = new ApiResponse();
             try
             {
-                //IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "1002");
-                //if (device == null) return apiResponse.ErrorResponse("WCS鏈兘鑾峰彇鍒板簱鍙e疄渚�");
-                //CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
+                
 
                 Dictionary<string, int> portStatusDict = new Dictionary<string, int>();
 
                 foreach (string DeStateName in datas)
                 {
-                    //鏆傛椂鏁版嵁
-                    portStatusDict[DeStateName] = 1;
+                    string DeciceCodes = "1003";
+                    if (DeStateName.StartsWith("C")) DeciceCodes = "1004";
 
-                    /*DeviceProDTO? deviceProDTO = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == DeStateName && x.DeviceProParamName == "StationFree");
-                    if (deviceProDTO == null) return apiResponse.ErrorResponse($"WCS鏈壘鍒板簱鍙o細{DeStateName},瀵瑰簲鐨勫崗璁�");
-                    conveyorLine.Communicator.Read<bool>(deviceProDTO.DeviceProAddress);
-                    bool portStatus = conveyorLine.Communicator.Read<bool>(deviceProDTO.DeviceProAddress);
-                    int statusValue = portStatus ? 1 : 0;
-                    portStatusDict[DeStateName] = statusValue;*/
+
+                    IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeciceCodes);
+                    if (device == null) return apiResponse.ErrorResponse("WCS鏈兘鑾峰彇鍒板簱鍙e疄渚�");
+                    CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
+
+
+                    //鏄惁鍙繘鍑�
+                    DeviceProDTO? deviceProDTO = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == DeStateName && x.DeviceProParamName == "PermitHandShake");
+                    //鏄惁鏈夎揣
+                    DeviceProDTO? StationNumProDTO = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == DeStateName && x.DeviceProParamName == "StationNum");
+                    if (deviceProDTO == null || StationNumProDTO ==null) return apiResponse.ErrorResponse($"WCS鏈壘鍒板簱鍙o細{DeStateName},瀵瑰簲鐨勫崗璁�");
+
+                    int statusValue = 0;
+                    //1鍏佽鍙�  2鍏佽鏀�
+                    int portStatus = conveyorLine.Communicator.Read<ushort>(deviceProDTO.DeviceProAddress);
+                    //鏄惁鏈夎揣
+                    int StationStatus = conveyorLine.Communicator.Read<ushort>(StationNumProDTO.DeviceProAddress);
+
+
+                    if(DeStateName== "G01" || DeStateName == "G06" || DeStateName == "G07")
+                    {
+                        //鏈夎揣锛屽彲杩涗俊鍙�
+                        statusValue = (portStatus == 1 && StationStatus == 1) ? 1 : (portStatus == 2 && StationStatus == 0) ?0: (portStatus == 0) ? 0 : 0;
+                    }
+                    else
+                    {
+                        statusValue = StationStatus == 1 ? 0 : 1;
+                    }
+                    portStatusDict[DeStateName] = statusValue;
                 }
 
                 return apiResponse.SuccessResponse(portStatusDict);
@@ -187,7 +210,7 @@
 
 
         //鑾峰彇鍏夊箷鐘舵��
-        public ApiResponse getSafeStatus(string[] datas)
+        public ApiResponse getSafeStatus(string[]  datas)
         {
             WriteLog.Write_Log("鑾峰彇鍏夊箷鐘舵�佹帴鍙�", "鑾峰彇鍏夊箷鐘舵�佷俊鎭�", "璋冨彇鍙傛暟", setCurtain);
             ApiResponse apiResponse = new ApiResponse();
@@ -211,19 +234,63 @@
         //璁剧疆鍏夊箷
         public ApiResponse setCurtain(SetCurtainRequest setCurtain)
         {
-            //鑾峰彇WMS璋冨彇鐨勫弬鏁�
-            WriteLog.Write_Log("璁剧疆鍏夊箷鎺ュ彛", "璁剧疆鍏夊箷淇℃伅", "璋冨彇鍙傛暟", setCurtain);
 
             ApiResponse apiResponse = new ApiResponse();
+            bool HandShakeboolOPEN = false;
+            bool HandShakeboolCLOSE = false;
             try
             {
-                return apiResponse.SuccessResponse();
-            }
+                Dictionary<string, int> portStatusDict = new Dictionary<string, int>();
+                foreach (string DeStateName in setCurtain.Datas)
+                {
+                    string DeciceCodes = "1003";
+                    if (DeStateName.StartsWith("C")) DeciceCodes = "1004";
+
+                    IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeciceCodes);
+                    if (device == null) return apiResponse.ErrorResponse("WCS鏈兘鑾峰彇鍒板簱鍙e疄渚�");
+
+                    CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
+
+                    DeviceProDTO? HandShake = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == DeStateName && x.DeviceProParamName == "HandShake");
+                    if (HandShake == null) return apiResponse.ErrorResponse($"WCS鏈壘鍒板簱鍙o細{setCurtain.Datas},瀵瑰簲鐨勫崗璁�");
+                    DeviceProDTO? Request = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == DeStateName && x.DeviceProParamName == "Request");
+                    if (HandShake == null) return apiResponse.ErrorResponse($"WCS鏈壘鍒板簱鍙o細{setCurtain.Datas},瀵瑰簲鐨勫崗璁�");
+                    
+                    if (setCurtain.Operate.Equals("OPEN"))
+                    {
+                        //鍐欏叆plc锛宎gv閫�鍑轰腑鎵撳紑淇″彿
+                        HandShakeboolOPEN =  conveyorLine.Communicator.Write<short>(Request.DeviceProAddress, 0);
+
+                        WriteLog.Write_Log("璁剧疆鎵撳紑鍏夊箷鎺ュ彛", "璁剧疆鎵撳紑鍏夊箷淇℃伅", $"搴撳彛鍚嶇О锛氥�恵DeStateName}銆戯紝鎵撳紑鍏夊箷淇″彿鍦板潃锛氥�恵Request.DeviceProAddress}銆戯紝璇诲彇鏁版嵁锛氥�恵conveyorLine.Communicator.Read<ushort>(Request.DeviceProAddress)}銆慭n" +
+                        $"鍐欏叆鎵撳紑鍏夊箷淇″彿鏄惁鎴愬姛杩斿洖鍊硷細銆恵HandShakeboolOPEN}銆�");
+
+                    }
+                    else
+                    {
+                        //鍐欏叆plc锛宎gv杩涘叆鍏抽棴鍏夋爡淇″彿
+                        HandShakeboolCLOSE = conveyorLine.Communicator.Write<short>(HandShake.DeviceProAddress, 1)&& conveyorLine.Communicator.Write<short>(Request.DeviceProAddress, 1);
+
+                        WriteLog.Write_Log("璁剧疆鍏抽棴鍏夊箷鎺ュ彛", "璁剧疆鍏抽棴鍏夊箷鎺ュ彛淇℃伅", $"搴撳彛鍚嶇О锛氥�恵DeStateName}銆戯紝鍏抽棴鍏夊箷淇″彿鍦板潃锛氥�恵HandShake.DeviceProAddress}銆戯紝璇诲彇鏁版嵁锛氥�恵conveyorLine.Communicator.Read<ushort>(HandShake.DeviceProAddress)}銆�" +
+                            $"鍏抽棴鍏夊箷淇″彿澶囩敤鍦板潃锛氥�恵Request.DeviceProAddress}銆戯紝璇诲彇鏁版嵁锛氥�恵conveyorLine.Communicator.Read<ushort>(Request.DeviceProAddress)}銆慭n" +
+                        $"鍐欏叆鍏抽棴鍏夊箷淇″彿鏄惁鎴愬姛杩斿洖鍊硷細銆恵HandShakeboolCLOSE}銆�");
+                    }
+                }
+                 if ((HandShakeboolOPEN && setCurtain.Operate.Equals("OPEN") )|| (HandShakeboolCLOSE && setCurtain.Operate.Equals("CLOSE")))
+                 {
+                    return apiResponse.SuccessResponse();
+                 }
+                else
+                {
+                 return apiResponse.ErrorResponse("鍐欏叆plc杩涘叆淇″彿澶辫触");
+                }
+                }
             catch (Exception ex)
             {
                 return apiResponse.ErrorResponse($"WCS浠诲姟娣诲姞閿欒锛屽師鍥狅細{ex.Message}");
             }
         }
+        
+
 
 
         //agv杩涘嚭鐘舵�佸弽棣�
@@ -235,9 +302,93 @@
             ApiResponse apiResponse = new ApiResponse();
             try
             {
+                string DeciceCodes = "1003";
+                if (agvUpdateRequest.warehousenumber.StartsWith("C")) DeciceCodes = "1004";
 
+                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeciceCodes);
+                if (device == null) return apiResponse.ErrorResponse("WCS鏈兘鑾峰彇鍒板簱鍙e疄渚�");
+                CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
 
-                return apiResponse.SuccessResponse();
+                //鏄惁鍙繘鍑�
+                DeviceProDTO? HandShake = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == agvUpdateRequest.warehousenumber && x.DeviceProParamName == "HandShake");
+                if (HandShake == null) return apiResponse.ErrorResponse($"WCS鏈壘鍒板簱鍙o細{agvUpdateRequest.warehousenumber},瀵瑰簲鐨勫崗璁�");
+                DeviceProDTO? Request = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == agvUpdateRequest.warehousenumber && x.DeviceProParamName == "Request");
+              
+                    if (agvUpdateRequest.agvstatus == 1)
+                    {
+                        bool HandShakebool = conveyorLine.Communicator.Write<short>(HandShake.DeviceProAddress, 1);
+                        if (HandShakebool)
+                        {
+                        if (Request != null)
+                        {
+                            conveyorLine.Communicator.Write<short>(Request.DeviceProAddress, 1);
+                        }
+                            //鏄惁鍙繘鍑�    1鍏佽鍙�  2鍏佽鏀�
+                            DeviceProDTO? deviceProDTO = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == agvUpdateRequest.warehousenumber && x.DeviceProParamName == "PermitHandShake");
+                            //鏄惁鏈夎揣
+                            DeviceProDTO? StationNumProDTO = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == agvUpdateRequest.warehousenumber && x.DeviceProParamName == "StationNum");
+                            if (deviceProDTO == null || StationNumProDTO == null) return apiResponse.ErrorResponse($"WCS鏈壘鍒板簱鍙o細{agvUpdateRequest.warehousenumber},瀵瑰簲鐨勫崗璁�");
+                            int statusValue = 0;
+                            int portStatus = conveyorLine.Communicator.Read<ushort>(deviceProDTO.DeviceProAddress);
+                            int StationStatus = conveyorLine.Communicator.Read<ushort>(StationNumProDTO.DeviceProAddress);
+
+                            //鏈夎揣锛屽彲杩涗俊鍙�
+                            statusValue = ((portStatus == 1 && StationStatus == 1) || (portStatus == 2 && StationStatus == 0)) ? 1 : (portStatus == 0) ? 0 : 0;
+                            WriteLog.Write_Log("鐢宠杩涘叆AGV鍙嶉淇″彿淇℃伅", "鐢宠杩涘叆AGV鍙嶉淇″彿淇℃伅", $"搴撳彛缂栧彿锛氥�恵agvUpdateRequest.warehousenumber}銆戯紝鏄惁鍏佽杩涘叆鍦板潃锛氥�恵deviceProDTO.DeviceProAddress}銆戯紝璇诲彇鏁版嵁锛氥�恵portStatus}銆慭n" +
+                                $"鏄惁鏈夎揣鍦板潃锛氥�恵StationNumProDTO.DeviceProAddress}銆戯紝璇诲彇鏁版嵁锛氥�恵StationStatus}銆慭n" +
+                                $"鏄惁鍙繘鍏ヤ俊鍙凤細銆恵statusValue}銆�");
+                            if (agvUpdateRequest.warehousenumber == "G01" || agvUpdateRequest.warehousenumber == "G06" || agvUpdateRequest.warehousenumber == "G07")
+                            {
+                                if (statusValue == 1)
+                                {
+                                    return apiResponse.SuccessResponse();
+
+                                }
+                                else
+                                {
+                                    conveyorLine.Communicator.Write<short>(Request.DeviceProAddress, 0);
+                                    return apiResponse.ErrorResponse("璇诲彇plc涓嶅彲杩涘叆淇℃伅");
+                                }
+                            }
+                            else
+                            {
+                                return apiResponse.SuccessResponse();
+                            }
+                        }
+                        else
+                        {
+                            return apiResponse.ErrorResponse("鍐欏叆plc杩涘叆淇″彿澶辫触");
+                        }
+                    }
+                    else if (agvUpdateRequest.agvstatus == 2)
+                    {
+                        //鍐欏叆杈撻�佺嚎淇″彿
+                        bool portStatus = conveyorLine.Communicator.Write<short>(HandShake.DeviceProAddress, 0);
+                        if (portStatus)
+                        {
+                            if (Request != null)
+                            {
+                                conveyorLine.Communicator.Write<short>(Request.DeviceProAddress, 0);
+                                WriteLog.Write_Log("鐢宠绂诲紑AGV鍙嶉淇″彿淇℃伅", "鐢宠绂诲紑AGV鍙嶉淇″彿淇℃伅", $"搴撳彛缂栧彿锛氥�恵agvUpdateRequest.warehousenumber}銆戯紝鐢宠淇″彿鍦板潃锛氥�恵HandShake.DeviceProAddress}銆戯紝璇诲彇鏁版嵁锛氥�恵conveyorLine.Communicator.Read<ushort>(HandShake.DeviceProAddress)}銆慭n" +
+                                    $"澶囩敤淇″彿鍦板潃锛氥�恵Request.DeviceProAddress}銆戯紝璇诲彇鏁版嵁锛氥�恵conveyorLine.Communicator.Read<ushort>(Request.DeviceProAddress)}銆�");
+
+                            }
+                            else
+                            {
+                                WriteLog.Write_Log("鐢宠绂诲紑AGV鍙嶉淇″彿淇℃伅", "鐢宠绂诲紑AGV鍙嶉淇″彿淇℃伅", $"搴撳彛缂栧彿锛氥�恵agvUpdateRequest.warehousenumber}銆戯紝鐢宠淇″彿鍦板潃锛氥�恵HandShake.DeviceProAddress}銆戯紝璇诲彇鏁版嵁锛氥�恵conveyorLine.Communicator.Read<ushort>(HandShake.DeviceProAddress)}銆慭n" );
+                            }
+                            return apiResponse.SuccessResponse();
+                        }
+                        else
+                        {
+                            return apiResponse.ErrorResponse("鍐欏叆plc娓呴櫎淇″彿澶辫触");
+                        }
+                    }
+                    else
+                    {
+                        return apiResponse.ErrorResponse($"agv瀵瑰簲鐨勭敵璇烽敊璇紝瀛楁锛歛gvstatus锛岀敵璇风殑鍊硷細{agvUpdateRequest.agvstatus}");
+                    }
+
             }
             catch (Exception ex)
             {
@@ -259,17 +410,20 @@
                 taskInfo1.taskType = taskType;
                 taskInfo1.invType = invType;
                 taskInfo1.psd = "akjfapjfpadaoif";
+
                 commandResult = HttpHelper.Post<CommandResult>(urlWMStaskreturn, taskInfo1, "浠诲姟鐘舵�佸洖璋�");
 
-                WriteLog.Write_Log("鍚屾缁欎笂娓稿弽棣堜换鍔″畬鎴�", "浠诲姟淇℃伅", $"浠诲姟鍙凤細{taskId}", $"璋冨彇鍙傛暟锛歿taskInfo1.ToJson()},杩斿洖鍙傛暟锛歿commandResult.ToJson()}");
+                WriteLog.Write_Log("鍚屾缁欎笂娓稿弽棣堜换鍔″畬鎴�", "浠诲姟淇℃伅", $"浠诲姟鍙凤細{taskId}", $"璋冨彇鍙傛暟锛歿taskInfo1.ToJsonString()},杩斿洖鍙傛暟锛歿commandResult.ToJsonString()}");
                 return commandResult;
             }
             catch (Exception ex)
             {
+                Console.WriteLine("璋冨彇涓婃父鎺ュ彛閿欒锛氬師鍥狅細"+ex.Message);
                 commandResult.status = "error";
-                commandResult.result = $"WCS鎺ュ彛閿欒锛屽師鍥狅細{ex.Message}";
+                string resujos = $"WCS鎺ュ彛閿欒锛屽師鍥狅細{ex.Message}";
+                commandResult.result = resujos.ToJsonString();
 
-                WriteLog.Write_Log("鍚屾缁欎笂娓稿弽棣堜换鍔″畬鎴�", "浠诲姟淇℃伅", $"浠诲姟鍙凤細{taskId}", $"WCS鎺ュ彛閿欒锛屽師鍥狅細{ex.Message}");
+                WriteLog.Write_Log("鍚屾缁欎笂娓稿弽棣堜换鍔″畬鎴�", "浠诲姟淇℃伅", $"浠诲姟鍙凤細{taskId}", $"闇�瑕佷笂浼燱MS淇℃伅鍐呭锛歿commandResult.ToJsonString()},WCS鎺ュ彛閿欒锛屽師鍥狅細{ex.Message}");
                 return commandResult;
             }
             
@@ -307,7 +461,9 @@
             catch (Exception ex)
             {
                 commandResult.status = "error";
-                commandResult.result = $"WCS鎺ュ彛閿欒锛屽師鍥狅細{ex.Message}";
+                string resujos = $"WCS鎺ュ彛閿欒锛屽師鍥狅細{ex.Message}";
+                commandResult.result = resujos.ToJsonString();
+
 
                 WriteLog.Write_Log("鍚屾缁欎笂娓歌澶囨晠闅滀俊鎭�", "璁惧鏁呴殰淇℃伅", $"璁惧id锛歿devuuid}锛屽け璐�", $"WCS鎺ュ彛閿欒锛屽師鍥狅細{ex.Message}");
                 return commandResult;
@@ -335,7 +491,9 @@
             catch (Exception ex)
             {
                 commandResult.status = "error";
-                commandResult.result = $"WCS鎺ュ彛閿欒锛屽師鍥狅細{ex.Message}";
+                string resujos = $"WCS鎺ュ彛閿欒锛屽師鍥狅細{ex.Message}";
+                commandResult.result = resujos.ToJsonString();
+
                 WriteLog.Write_Log("鍚屾缁欎笂娓告彁鍗囧埌浣嶄俊鎭�", "淇℃伅鍐呭", $"閿欒淇℃伅", $"WCS鎺ュ彛閿欒锛屽師鍥狅細{ex.Message}");
                 return commandResult;
             }

--
Gitblit v1.9.3