| | |
| | | using WIDESEAWCS_Common.AGVEnum; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Common.AGVEnum; |
| | | using WIDESEAWCS_Common.TaskEnum; |
| | | using WIDESEAWCS_DTO.TaskInfo; |
| | | using WIDESEAWCS_ITaskInfoRepository; |
| | | using WIDESEAWCS_Model.Models; |
| | | using WIDESEAWCS_QuartzJob; |
| | | |
| | | namespace WIDESEAWCS_Tasks.AGVJob |
| | | namespace WIDESEAWCS_Tasks |
| | | { |
| | | public class UpdateTaskAGV |
| | | { |
| | |
| | | plcClient.Communicator.Write(taskFbInteractive2, 1); |
| | | //throw new Exception("ä»»å¡ç¶ææ´æ¹ä¸º4ç»ç¹å·²å®æå¤±è´¥,ä»»å¡ID:" + agvTask.agv_tasknum + DateTime.Now + ",ä»»å¡ç¶æä¸æ¯ç»ç¹æ§è¡ä¸!"); |
| | | } |
| | | if (agvTask.TargetAddress.Contains("HXWLX")) |
| | | { |
| | | if (agvTask.SourceAddress.Contains("KPHLX")) |
| | | { |
| | | // 空ç线è¿çç®± |
| | | // TODO: è°ç¨åæºæ¥å£è·å宿´æ¡ç |
| | | var materials = new List<BakingClass> |
| | | { |
| | | new BakingClass { BarCode = "1", MaterialType = "1" }, |
| | | }; |
| | | MESback WMSbackresult = MESAPIInvoke.BakingFeedingBinding(agvTask.TargetAddress, materials); |
| | | if (WMSbackresult.Code > 0) { new Exception(WMSbackresult.Message); return; } |
| | | } |
| | | else |
| | | { |
| | | // æåæºè¿çç®± |
| | | // TODO: è°ç¨åæºæ¥å£è·å宿´æ¡ç |
| | | var materials = new List<BakingClass> |
| | | { |
| | | new BakingClass { BarCode = "1", MaterialType = "1" }, |
| | | }; |
| | | MESback WMSbackresult = MESAPIInvoke.BakingFeedingBinding(agvTask.TargetAddress, materials); |
| | | if (WMSbackresult.Code > 0) { new Exception(WMSbackresult.Message); return; } |
| | | } |
| | | } |
| | | |
| | | //agvtask_HtyRepository.AddTaskHistory(agvTask, OperateType.Finished.ToString()); |
| | | _taskRepository.DeleteData(agvTask); |
| | |
| | | } |
| | | } |
| | | |
| | | public static void UpdateTask(AGV plcClient, ITaskRepository taskRepository) |
| | | public static void UpdateTask(AGV plcClient, ITaskRepository taskRepository, ITaskCZRepository _taskCZRepository, ITaskCZDetailsRepository _detailsRepository) |
| | | { |
| | | // 使ç¨Interlocked.Exchangeä¿è¯å䏿¶é´åªæä¸ä¸ªçº¿ç¨å¯ä»¥æ§è¡ä»»å¡æ´æ° |
| | | if (Interlocked.Exchange(ref _readUpdateAGVTaskSignalso, 1) == 0) |
| | |
| | | } |
| | | |
| | | // 读åä»»å¡ç¶æ |
| | | int taskFbInteractive = plcClient.Communicator.Read<int>(taskFbInteractiveR); |
| | | int taskFbInteractiveW = plcClient.Communicator.Read<int>(taskFbInteractive2); |
| | | int resetTaskFbInteractiveRValue = plcClient.Communicator.Read<int>(resetTaskFbInteractiveR); |
| | | int taskFbInteractive = plcClient.Communicator.Read<ushort>(taskFbInteractiveR); |
| | | int taskFbInteractiveW = plcClient.Communicator.Read<ushort>(taskFbInteractive2); |
| | | int resetTaskFbInteractiveRValue = plcClient.Communicator.Read<ushort>(resetTaskFbInteractiveR); |
| | | |
| | | // 妿resetTaskFbInteractiveR为1ï¼åéç½®taskFbInteractiveW为0ï¼å¹¶çå¾
å
¶å为0 |
| | | if (resetTaskFbInteractiveRValue == 1) |
| | | { |
| | | plcClient.Communicator.Write(taskFbInteractive2, 0); |
| | | plcClient.Communicator.Write<ushort>(taskFbInteractive2, 0); |
| | | // é¿å
使ç¨Thread.Sleepæ¥çå¾
ç¶æååï¼ä½¿ç¨æ´é«æççå¾
æºå¶ |
| | | for (int i = 0; i < 5; i++) |
| | | { |
| | | Task.Delay(300).Wait(); // 使ç¨Task.Delayæ¿ä»£Thread.Sleepï¼é¿å
é»å¡çº¿ç¨æ± ä¸ççº¿ç¨ |
| | | int agvNumber = plcClient.Communicator.Read<int>(taskFbInteractive2); |
| | | int agvNumber = plcClient.Communicator.Read<ushort>(taskFbInteractive2); |
| | | if (agvNumber != 0) |
| | | { |
| | | plcClient.Communicator.Write(taskFbInteractive2, 0); |
| | | plcClient.Communicator.Write<ushort>(taskFbInteractive2, 0); |
| | | } |
| | | else |
| | | { |
| | |
| | | // åªæå½taskFbInteractive为1ä¸taskFbInteractiveW为0æ¶æå¤çä»»å¡ç¶æ |
| | | if (taskFbInteractive == 1 && taskFbInteractiveW == 0) |
| | | { |
| | | string taskId = plcClient.Communicator.Read<int>(taskIDFb).ToString(); // ä»»å¡ID |
| | | int taskState = plcClient.Communicator.Read<int>(taskStatusFb); // ä»»å¡ç¶æ |
| | | string taskId = plcClient.Communicator.Read<string>(taskIDFb).ToString(); // ä»»å¡ID |
| | | int taskState = plcClient.Communicator.Read<ushort>(taskStatusFb); // ä»»å¡ç¶æ |
| | | |
| | | // 妿任å¡ç¶ææ æï¼åç´æ¥è¿å |
| | | if (taskState == 0) |
| | |
| | | } |
| | | |
| | | // æ ¹æ®ä»»å¡IDæ¥è¯¢æ°æ®åºä¸çä»»å¡ |
| | | var agvTask = taskRepository.QueryFirst(r => r.TaskNum.ToString() == taskId); |
| | | int tasknum = int.Parse(taskId.Split('-')[1]); |
| | | var agvTask = taskRepository.QueryFirst(r => r.TaskNum.ToString() == tasknum.ToString()); |
| | | if (agvTask == null) |
| | | { |
| | | plcClient.Communicator.Write(taskFbInteractive2, 1); |
| | | plcClient.Communicator.Write<ushort>(taskFbInteractive2, 1); |
| | | return; // 妿任å¡ä¸åå¨ï¼ç´æ¥è¿åï¼ä¸éè¦å次åå
¥ |
| | | } |
| | | |
| | |
| | | } |
| | | else if (taskState == 4) // ä»»å¡ç»ç¹å®æ |
| | | { |
| | | if (agvTask.TaskState != (int)TaskInStatusEnum.SC_InExecuting) |
| | | if (agvTask.TaskState != (int)TaskInStatusEnum.SC_InFinish) |
| | | { |
| | | // 妿任å¡ç¶æä¸æ¯ç»ç¹æ§è¡ä¸ï¼æåºå¼å¸¸ |
| | | throw new Exception($"ä»»å¡ç¶ææ´æ¹ä¸º4ç»ç¹å·²å®æå¤±è´¥,ä»»å¡ID:{taskId},å½åç¶æ:{agvTask.TaskState}"); |
| | | } |
| | | |
| | | if (agvTask.TargetAddress.Contains("HXWLX")) |
| | | { |
| | | if (agvTask.SourceAddress.Contains("KPHLX")) |
| | | { |
| | | // 空ç线è¿çç®± |
| | | // TODO: 任塿ªå宿´æ¡ç |
| | | var details = agvTask.ExceptionMessage; |
| | | string[] splitDetails = details.Split(','); |
| | | |
| | | var materials = splitDetails |
| | | .Select(part => new BakingClass |
| | | { |
| | | MaterialType = "", |
| | | BarCode = part |
| | | }) |
| | | .ToList(); |
| | | |
| | | MESback WMSbackresult = MESAPIInvoke.BakingFeedingBinding(agvTask.TargetAddress, materials); |
| | | if (WMSbackresult.Code > 0) { new Exception(WMSbackresult.Message); return; } |
| | | } |
| | | else |
| | | { |
| | | // æåæºè¿çç®± |
| | | // TODO: è°ç¨åæºæ¥å£è·å宿´æ¡ç |
| | | //var czTask = _taskCZRepository.QueryFirst(x => x.Id == agvTask.WMSId); |
| | | //CZTaskBarCodeDto barCodeDto = JsonConvert.DeserializeObject<CZTaskBarCodeDto>(czTask.DtCZTaskDetails); |
| | | //var materials = Enumerable.Range(0, 2) |
| | | // .Select(i => new BakingClass |
| | | // { |
| | | // MaterialType = czTask.TaskProductCode, |
| | | // BarCode = GetBarCodeByIndex(barCodeDto, i, hasDesc: !string.IsNullOrEmpty(czTask.TaskDesc)) |
| | | // }) |
| | | // .ToList(); |
| | | |
| | | var details = _detailsRepository.QueryData(x => x.TaskEndAddress == agvTask.TargetAddress).ToList(); |
| | | |
| | | if (details.Count >= 2) |
| | | { |
| | | details = details.Take(2).ToList(); |
| | | } |
| | | |
| | | var materials = details.Select(x => new BakingClass |
| | | { |
| | | MaterialType = x.MaterialType, |
| | | BarCode = x.MaterialBarCode, |
| | | }).ToList(); |
| | | |
| | | MESback WMSbackresult = MESAPIInvoke.BakingFeedingBinding(agvTask.TargetAddress, materials); |
| | | if (WMSbackresult.Code > 0) { new Exception(WMSbackresult.Message); return; } |
| | | else |
| | | { |
| | | // å é¤detailsæ°æ® |
| | | _detailsRepository.DeleteData(details); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // å é¤å·²å®æçä»»å¡ |
| | | taskRepository.DeleteData(agvTask); |
| | | plcClient.Communicator.Write(taskFbInteractive2, 1); |
| | | plcClient.Communicator.Write<ushort>(taskFbInteractive2, 1); |
| | | EnsureTaskFeedback(taskFbInteractive2, plcClient); |
| | | } |
| | | else if (taskState == 5) |
| | | { |
| | | plcClient.Communicator.Write(taskFbInteractive2, 1); |
| | | plcClient.Communicator.Write<ushort>(taskFbInteractive2, 1); |
| | | } |
| | | } |
| | | |
| | | // 妿taskFbInteractive为0ä¸taskFbInteractiveW为1ï¼åéç½®taskFbInteractiveW为0 |
| | | if (taskFbInteractive == 0 && taskFbInteractiveW == 1) |
| | | { |
| | | plcClient.Communicator.Write(taskFbInteractive2, 0); |
| | | plcClient.Communicator.Write<ushort>(taskFbInteractive2, 0); |
| | | EnsureTaskFeedback(taskFbInteractive2, plcClient); |
| | | } |
| | | } |
| | |
| | | // æ´æ°ä»»å¡ç¶æå¹¶åå
¥AGVåé¦å°å |
| | | private static void UpdateTaskStatus(AGV plcClient, Dt_Task agvTask, TaskInStatusEnum targetStatus, ITaskRepository taskRepository, string taskFbInteractive2) |
| | | { |
| | | if (agvTask.TaskState != (int)targetStatus) |
| | | { |
| | | plcClient.Communicator.Write(taskFbInteractive2, 1); // ç¶æä¸å¹é
ï¼åå
¥åé¦ |
| | | } |
| | | //if (agvTask.TaskState != (int)targetStatus) |
| | | //{ |
| | | // plcClient.Communicator.Write<ushort>(taskFbInteractive2, 1); // ç¶æä¸å¹é
ï¼åå
¥åé¦ |
| | | //} |
| | | |
| | | // æ´æ°ä»»å¡ç¶æä¸ºä¸ä¸ä¸ªæªå®æç¶æ |
| | | agvTask.TaskState = agvTask.TaskState.GetNextNotCompletedStatus<TaskInStatusEnum>(); |
| | | taskRepository.UpdateData(agvTask); |
| | | plcClient.Communicator.Write(taskFbInteractive2, 1); |
| | | plcClient.Communicator.Write<ushort>(taskFbInteractive2, 1); |
| | | EnsureTaskFeedback(taskFbInteractive2, plcClient); |
| | | } |
| | | |
| | |
| | | int agvNumber = plcClient.Communicator.Read<int>(taskFbInteractive2); |
| | | if (agvNumber != 1) |
| | | { |
| | | plcClient.Communicator.Write(taskFbInteractive2, 1); |
| | | plcClient.Communicator.Write<ushort>(taskFbInteractive2, 1); |
| | | } |
| | | else |
| | | { |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | // è¾
婿¹æ³ |
| | | private static string GetBarCodeByIndex(CZTaskBarCodeDto dto, int index, bool hasDesc) |
| | | { |
| | | return (index, hasDesc) switch |
| | | { |
| | | (0, false) => dto.BarCode1, |
| | | (1, false) => dto.BarCode2, |
| | | (0, true) => dto.BarCode3, |
| | | (1, true) => dto.BarCode4, |
| | | _ => throw new IndexOutOfRangeException() |
| | | }; |
| | | } |
| | | } |
| | | |
| | | public class BakingFeedingClass |
| | | { |
| | | public string Devid { get; set; } |
| | | |
| | | public List<BakingClass> Materials { get; set; } |
| | | } |
| | | |
| | | public class BakingClass |
| | | { |
| | | public string MaterialType { get; set; } |
| | | public string BarCode { get; set; } |
| | | } |
| | | } |