zhangchengsong
8 天以前 f590d457f629d4a7cf6a5e2f77f5454d807e90db
ÏîÄ¿´úÂë/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/WMSTaskService.cs
@@ -17,6 +17,7 @@
using AutoMapper;
using Castle.Components.DictionaryAdapter.Xml;
using HslCommunication;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.OpenApi.Any;
@@ -158,23 +159,44 @@
            ApiResponse apiResponse = new ApiResponse();
            try
            {
                //IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "1002");
                //if (device == null) return apiResponse.ErrorResponse("WCS未能获取到库口实例");
                //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未找到库口:{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未能获取到库口实例");
                    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未找到库口:{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);
@@ -235,9 +257,69 @@
            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未能获取到库口实例");
                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未找到库口:{agvUpdateRequest.warehousenumber},对应的协议");
                if (agvUpdateRequest.agvstatus == 1)
                {
                    //写入plc,agv进入信号
                    bool HandShakebool = conveyorLine.Communicator.Write<short>(HandShake.DeviceProAddress, 1);
                    if (HandShakebool)
                    {
                        //是否可进出    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未找到库口:{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反馈信号信息", $"是否允许进入地址:【{deviceProDTO.DeviceProAddress}】,读取数据:【{portStatus}】\n" +
                            $"是否有货地址:【{StationNumProDTO.DeviceProAddress}】,读取数据:【{StationStatus}】\n" +
                            $"有货可进入信号:【{statusValue}】");
                        if (statusValue == 1)
                        {
                            return apiResponse.SuccessResponse();
                        }
                        else
                        {
                            return apiResponse.ErrorResponse("读取plc不可进入信息");
                        }
                    }
                    else
                    {
                        return apiResponse.ErrorResponse("写入plc进入信号失败");
                    }
                }
                else if(agvUpdateRequest.agvstatus == 2)
                {
                    //写入输送线信号
                    bool portStatus = conveyorLine.Communicator.Write<short>(HandShake.DeviceProAddress, 0);
                    if (portStatus)
                    {
                        return apiResponse.SuccessResponse();
                    }
                    else
                    {
                        return apiResponse.ErrorResponse("写入plc清除信号失败");
                    }
                }
                else
                {
                    return apiResponse.ErrorResponse($"agv对应的申请错误,字段:agvstatus,申请的值:{agvUpdateRequest.agvstatus}");
                }
            }
            catch (Exception ex)
            {
@@ -259,17 +341,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}", $"需要上传WMS信息内容:{commandResult.ToJsonString()},WCS接口错误,原因:{ex.Message}");
                return commandResult;
            }
            
@@ -307,7 +392,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 +422,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;
            }