| | |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using AutoMapper; |
| | | using AutoMapper.Internal; |
| | | using Castle.Components.DictionaryAdapter.Xml; |
| | | using HslCommunication; |
| | | using Microsoft.AspNetCore.Mvc; |
| | |
| | | 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}"); |
| | | |
| | | |
| | |
| | | |
| | | |
| | | //è·åå
å¹ç¶æ |
| | | public ApiResponse getSafeStatus(string[] datas) |
| | | public ApiResponse getSafeStatus(string[] datas) |
| | | { |
| | | WriteLog.Write_Log("è·åå
å¹ç¶ææ¥å£", "è·åå
å¹ç¶æä¿¡æ¯", "è°ååæ°", setCurtain); |
| | | ApiResponse apiResponse = new ApiResponse(); |
| | |
| | | return apiResponse.ErrorResponse($"WCS任塿·»å é误ï¼åå ï¼{ex.Message}"); |
| | | } |
| | | } |
| | | |
| | | |
| | | //设置å
å¹ |
| | | /// <summary> |
| | | /// 设置å
å¹ |
| | | /// </summary> |
| | | /// <param name="setCurtain"></param> |
| | | /// <returns></returns> |
| | | public ApiResponse setCurtain(SetCurtainRequest setCurtain) |
| | | { |
| | | //è·åWMSè°åçåæ° |
| | | WriteLog.Write_Log("设置å
广¥å£", "设置å
å¹ä¿¡æ¯", "è°ååæ°", setCurtain); |
| | | if (setCurtain == null || setCurtain.Datas == null || setCurtain.Datas.Length == 0) |
| | | { |
| | | return new ApiResponse().ErrorResponse("请æ±åæ°æåºå£å表ä¸è½ä¸ºç©º"); |
| | | } |
| | | if (string.IsNullOrWhiteSpace(setCurtain.Operate)) |
| | | { |
| | | return new ApiResponse().ErrorResponse("æä½ç±»å(Operate)ä¸è½ä¸ºç©º"); |
| | | } |
| | | |
| | | WriteLog.Write_Log("设置å
广¥å£", "设置å
广¥å£ä¿¡æ¯", $"åºå£åç§°ï¼ã{string.Join(",", setCurtain.Datas)}ã,ç³è¯·ç¶æï¼ã{setCurtain.Operate}ã"); |
| | | ApiResponse apiResponse = new ApiResponse(); |
| | | bool allSuccess = true; |
| | | var specialPorts = new[] { "G01", "G06", "G07" }; |
| | | |
| | | try |
| | | { |
| | | return apiResponse.SuccessResponse(); |
| | | foreach (string portName in setCurtain.Datas) |
| | | { |
| | | if (string.IsNullOrWhiteSpace(portName)) { allSuccess = false; continue; } |
| | | string deviceCode = portName.StartsWith("C") ? "1004" : "1003"; |
| | | |
| | | CommonConveyorLine? conveyorLine = Storage.Devices.FirstOrDefault(x => x.DeviceCode == deviceCode) as CommonConveyorLine; |
| | | if (conveyorLine == null) { allSuccess = false; continue; } |
| | | |
| | | DeviceProDTO? handShakeDto = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == portName && x.DeviceProParamName == "HandShake"); |
| | | DeviceProDTO? requestDto = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == portName && x.DeviceProParamName == "Request"); |
| | | if (handShakeDto == null) { allSuccess = false; continue; } |
| | | |
| | | bool writeResult = false; |
| | | //StringComparison.OrdinalIgnoreCaseæ¯å
¼å®¹å¤§å°å |
| | | if (setCurtain.Operate.Equals("OPEN", StringComparison.OrdinalIgnoreCase)) |
| | | { |
| | | if (specialPorts.Contains(portName)) |
| | | writeResult = conveyorLine.Communicator.Write<short>(requestDto.DeviceProAddress, 0); |
| | | else |
| | | writeResult = conveyorLine.Communicator.Write<short>(handShakeDto.DeviceProAddress, 0); |
| | | } |
| | | else if (setCurtain.Operate.Equals("CLOSE", StringComparison.OrdinalIgnoreCase)) |
| | | { |
| | | if (specialPorts.Contains(portName)) |
| | | writeResult = conveyorLine.Communicator.Write<short>(handShakeDto.DeviceProAddress, 1) && conveyorLine.Communicator.Write<short>(requestDto.DeviceProAddress, 1); |
| | | else |
| | | writeResult = conveyorLine.Communicator.Write<short>(handShakeDto.DeviceProAddress, 1); |
| | | } |
| | | if (!writeResult) allSuccess = false; |
| | | } |
| | | |
| | | return allSuccess ? apiResponse.SuccessResponse() : apiResponse.ErrorResponse("é¨å/å
¨é¨åºå£åå
¥PLCä¿¡å·å¤±è´¥"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return apiResponse.ErrorResponse($"WCS任塿·»å é误ï¼åå ï¼{ex.Message}"); |
| | | WriteLog.Write_Log("设置å
广¥å£å¼å¸¸", "é误信æ¯", ex.ToString()); |
| | | return apiResponse.ErrorResponse($"WCS设置å
å¹é误ï¼åå ï¼{ex.Message}"); |
| | | } |
| | | } |
| | | |
| | | |
| | | //agvè¿åºç¶æåé¦ |
| | | #endregion |
| | | /// <summary> |
| | | /// agvè¿åºå
¥åé¦ |
| | | /// </summary> |
| | | /// <param name="agvUpdateRequest"></param> |
| | | /// <returns></returns> |
| | | public ApiResponse getAGVStatus(AgvUpdateRequest agvUpdateRequest) |
| | | { |
| | | //è·åWMSè°åçåæ° |
| | | WriteLog.Write_Log("agvè¿åºç¶æå馿¥å£", "agvè¿åºç¶æä¿¡æ¯", "è°ååæ°", setCurtain); |
| | | if (agvUpdateRequest == null) return new ApiResponse().ErrorResponse("请æ±åæ°ä¸è½ä¸ºç©º"); |
| | | if (string.IsNullOrWhiteSpace(agvUpdateRequest.warehousenumber)) return new ApiResponse().ErrorResponse("åºå£ç¼å·ä¸è½ä¸ºç©º"); |
| | | |
| | | WriteLog.Write_Log("agvè¿åºç¶æå馿¥å£", "agvè¿åºç¶æä¿¡æ¯", $"åºå£åç§°ï¼ã{agvUpdateRequest.warehousenumber}ãï¼ç³è¯·ç¶æï¼ã{agvUpdateRequest.agvstatus}ã"); |
| | | ApiResponse apiResponse = new ApiResponse(); |
| | | |
| | | try |
| | | { |
| | | string DeciceCodes = "1003"; |
| | | if (agvUpdateRequest.warehousenumber.StartsWith("C")) DeciceCodes = "1004"; |
| | | string deviceCode = agvUpdateRequest.warehousenumber.StartsWith("C") ? "1004" : "1003"; |
| | | |
| | | IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeciceCodes); |
| | | if (device == null) return apiResponse.ErrorResponse("WCSæªè½è·åå°åºå£å®ä¾"); |
| | | CommonConveyorLine conveyorLine = (CommonConveyorLine)device; |
| | | CommonConveyorLine? conveyorLine = Storage.Devices.FirstOrDefault(x => x.DeviceCode == deviceCode) as CommonConveyorLine; |
| | | if (conveyorLine == null) return apiResponse.ErrorResponse("WCSæªè½è·åå°åºå£å®ä¾"); |
| | | |
| | | //æ¯å¦å¯è¿åº |
| | | 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) |
| | | DeviceProDTO? handShake = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == agvUpdateRequest.warehousenumber && x.DeviceProParamName == "HandShake"); |
| | | if (handShake == null) return apiResponse.ErrorResponse($"WCSæªæ¾å°åºå£ï¼{agvUpdateRequest.warehousenumber},对åºçåè®®"); |
| | | DeviceProDTO? request = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == agvUpdateRequest.warehousenumber && x.DeviceProParamName == "Request"); |
| | | |
| | | if (agvUpdateRequest.agvstatus == 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æªæ¾å°åºå£ï¼{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; |
| | | if (statusValue == 1) |
| | | bool writeHandShake = conveyorLine.Communicator.Write<short>(handShake.DeviceProAddress, 1); |
| | | if (!writeHandShake) return apiResponse.ErrorResponse("åå
¥plcè¿å
¥ä¿¡å·å¤±è´¥"); |
| | | if (request != null) conveyorLine.Communicator.Write<short>(request.DeviceProAddress, 1); |
| | | |
| | | var specialPorts = new[] { "G01", "G06", "G07" }; |
| | | if (specialPorts.Contains(agvUpdateRequest.warehousenumber)) |
| | | { |
| | | return apiResponse.SuccessResponse(); |
| | | DeviceProDTO? permitHandShake = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == agvUpdateRequest.warehousenumber && x.DeviceProParamName == "PermitHandShake"); |
| | | DeviceProDTO? stationNum = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == agvUpdateRequest.warehousenumber && x.DeviceProParamName == "StationNum"); |
| | | if (permitHandShake == null || stationNum == null) return apiResponse.ErrorResponse($"WCSæªæ¾å°åºå£ï¼{agvUpdateRequest.warehousenumber},对åºçåè®®"); |
| | | |
| | | int portStatus = conveyorLine.Communicator.Read<ushort>(permitHandShake.DeviceProAddress); |
| | | int stationStatus = conveyorLine.Communicator.Read<ushort>(stationNum.DeviceProAddress); |
| | | bool canEnter = (portStatus == 1 && stationStatus == 1) || (portStatus == 2 && stationStatus == 0); |
| | | if (!canEnter) |
| | | { |
| | | if (request != null) conveyorLine.Communicator.Write<short>(request.DeviceProAddress, 0); |
| | | return apiResponse.ErrorResponse("读åplcä¸å¯è¿å
¥ä¿¡æ¯"); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | return apiResponse.ErrorResponse("读åplcä¸å¯è¿å
¥ä¿¡æ¯"); |
| | | } |
| | | return apiResponse.SuccessResponse(); |
| | | } |
| | | else |
| | | else if (agvUpdateRequest.agvstatus == 2) |
| | | { |
| | | return apiResponse.ErrorResponse("åå
¥plcè¿å
¥ä¿¡å·å¤±è´¥"); |
| | | } |
| | | } |
| | | else if(agvUpdateRequest.agvstatus == 2) |
| | | { |
| | | //åå
¥è¾éçº¿ä¿¡å· |
| | | bool portStatus = conveyorLine.Communicator.Write<short>(HandShake.DeviceProAddress, 0); |
| | | if (portStatus) |
| | | { |
| | | bool clearHandShake = conveyorLine.Communicator.Write<short>(handShake.DeviceProAddress, 0); |
| | | if (!clearHandShake) return apiResponse.ErrorResponse("åå
¥plcæ¸
é¤ä¿¡å·å¤±è´¥"); |
| | | if (request != null) conveyorLine.Communicator.Write<short>(request.DeviceProAddress, 0); |
| | | return apiResponse.SuccessResponse(); |
| | | } |
| | | else |
| | | { |
| | | return apiResponse.ErrorResponse("åå
¥plcæ¸
é¤ä¿¡å·å¤±è´¥"); |
| | | return apiResponse.ErrorResponse($"agv对åºçç³è¯·é误ï¼å段ï¼agvstatusï¼ç³è¯·çå¼ï¼{agvUpdateRequest.agvstatus}"); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | return apiResponse.ErrorResponse($"agv对åºçç³è¯·é误ï¼å段ï¼agvstatusï¼ç³è¯·çå¼ï¼{agvUpdateRequest.agvstatus}"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return apiResponse.ErrorResponse($"WCS任塿·»å é误ï¼åå ï¼{ex.Message}"); |
| | | return apiResponse.ErrorResponse($"WCS AGVç¶æé误ï¼åå ï¼{ex.Message}"); |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | |
| | | |
| | | #region è°å䏿¸¸æ¥å£ |
| | | public CommandResult taskreturn(int taskId, string taskType, string invType, string psd) |
| | |
| | | |
| | | commandResult = HttpHelper.Post<CommandResult>(urlWMStaskreturn, taskInfo1, "ä»»å¡ç¶æåè°"); |
| | | |
| | | WriteLog.Write_Log("忥ç»ä¸æ¸¸åé¦ä»»å¡å®æ", "ä»»å¡ä¿¡æ¯", $"ä»»å¡å·ï¼{taskId}", $"è°ååæ°ï¼{taskInfo1.ToJsonString()},è¿ååæ°ï¼{commandResult.ToJsonString()}"); |
| | | WriteLog.Write_Log("忥ç»ä¸æ¸¸åé¦ä»»å¡å®æ", "ä»»å¡ä¿¡æ¯", $"ä»»å¡å·ï¼ã{taskId}ã", $"è°ååæ°ï¼ã{taskInfo1.ToJsonString()}ã\nè¿ååæ°ï¼{commandResult.ToJsonString()}ã"); |
| | | return commandResult; |
| | | } |
| | | catch (Exception ex) |
| | |
| | | string resujos = $"WCSæ¥å£é误ï¼åå ï¼{ex.Message}"; |
| | | commandResult.result = resujos.ToJsonString(); |
| | | |
| | | WriteLog.Write_Log("忥ç»ä¸æ¸¸åé¦ä»»å¡å®æ", "ä»»å¡ä¿¡æ¯", $"ä»»å¡å·ï¼{taskId}", $"éè¦ä¸ä¼ WMSä¿¡æ¯å
容ï¼{commandResult.ToJsonString()},WCSæ¥å£é误ï¼åå ï¼{ex.Message}"); |
| | | WriteLog.Write_Log("忥ç»ä¸æ¸¸åé¦ä»»å¡å®æ", "ä»»å¡ä¿¡æ¯", $"ä»»å¡å·ï¼ã{taskId}ã", $"éè¦ä¸ä¼ WMSä¿¡æ¯å
容ï¼ã{commandResult.ToJsonString()}ã\nWCSæ¥å£é误ï¼åå ï¼{ex.Message}"); |
| | | return commandResult; |
| | | } |
| | | |