Admin
2026-03-23 f679f58dba34055bd579a603762c13fbe1650c9b
ÏîÄ¿´úÂë/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/WMSTaskService.cs
@@ -158,23 +158,28 @@
            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;
                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;
                    //是否可进出
                    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},对应的协议");
                    /*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;*/
                    int statusValue = 0;
                    int portStatus = conveyorLine.Communicator.Read<int>(deviceProDTO.DeviceProAddress);
                    int StationStatus = conveyorLine.Communicator.Read<int>(StationNumProDTO.DeviceProAddress);
                    //有货,可进信号
                    statusValue = ((portStatus == 1 && StationStatus == 1) || (portStatus == 2 && StationStatus == 0)) ? 1 : (portStatus == 0) ? 0 : 0;
                    portStatusDict[DeStateName] = statusValue;
                }
                return apiResponse.SuccessResponse(portStatusDict);
@@ -235,9 +240,71 @@
            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;
                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)
                {
                    //是否可进出
                    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<int>(deviceProDTO.DeviceProAddress);
                    int StationStatus = conveyorLine.Communicator.Read<int>(StationNumProDTO.DeviceProAddress);
                    //有货,可进信号
                    statusValue = ((portStatus == 1 && StationStatus == 1) || (portStatus == 2 && StationStatus == 0)) ? 1 : (portStatus == 0) ? 0 : 0;
                    if (statusValue == 1)
                    {//写入输送线信号
                        bool HandShakebool = conveyorLine.Communicator.Write<short>(HandShake.DeviceProAddress, 1);
                        if (HandShakebool)
                        {
                            return apiResponse.SuccessResponse();
                        }
                        else
                        {
                            return apiResponse.ErrorResponse("agv写入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)
            {