| | |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using HslCommunication.WebSocket; |
| | | using Quartz; |
| | | using WIDESEAWCS_Common; |
| | | using WIDESEAWCS_Core.Helper; |
| | |
| | | private readonly ITaskRepository _taskRepository; |
| | | private readonly ITaskService _taskService; |
| | | private readonly IContainerItemRepository _containerItemRepository; |
| | | public GantryJob(ITaskRepository taskRepository, ITaskService taskService, IContainerItemRepository containerItemRepository) |
| | | private readonly WebSocketServer _webSocketServer; |
| | | public GantryJob(ITaskRepository taskRepository, ITaskService taskService, IContainerItemRepository containerItemRepository, WebSocketServer webSocketServer) |
| | | { |
| | | _taskRepository = taskRepository; |
| | | _taskService = taskService; |
| | | _containerItemRepository = containerItemRepository; |
| | | _webSocketServer = webSocketServer; |
| | | } |
| | | |
| | | public Task Execute(IJobExecutionContext context) |
| | | { |
| | | try |
| | | bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value); |
| | | if (flag && value != null && value is OtherDevice) |
| | | { |
| | | bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value); |
| | | if (flag && value != null && value is OtherDevice) |
| | | OtherDevice otherDevice = (OtherDevice)value; |
| | | try |
| | | { |
| | | OtherDevice otherDevice = (OtherDevice)value; |
| | | |
| | | byte gantryStatus = otherDevice.GetValue<GantryDBName, byte>(GantryDBName.GantryStatus); |
| | | byte gantryAutoStatus = otherDevice.GetValue<GantryDBName, byte>(GantryDBName.GantryAutoStatus); |
| | | byte gantryWorkStatus = otherDevice.GetValue<GantryDBName, byte>(GantryDBName.GantryWorkStatus); |
| | | |
| | | if(gantryStatus == 1 && gantryAutoStatus == 3 && gantryWorkStatus == 0) |
| | | if (gantryStatus == 1 && gantryAutoStatus == 3 && gantryWorkStatus == 0) |
| | | { |
| | | // é»è¾å¤ç |
| | | // 1. 读åä»»å¡ |
| | | // 2. 任塿§è¡ |
| | | // 3. ä»»å¡å®æ |
| | | Dt_Task? task = _taskService.QueryAGantryUnExecuteTask(otherDevice.DeviceCode); |
| | | if(task != null) |
| | | if (task != null) |
| | | { |
| | | string[] takePositions = task.CurrentAddress.Split("*"); |
| | | if(takePositions.Length != 5) |
| | | if (takePositions.Length != 5) |
| | | { |
| | | //WriteError |
| | | return Task.CompletedTask; |
| | |
| | | //WriteError |
| | | return Task.CompletedTask; |
| | | } |
| | | if (LightStatusStorage.LightStatusDic.TryGetValue(putPositions[0], out LightStatusEnum lightStatusDic)) |
| | | { |
| | | if (lightStatusDic != LightStatusEnum.LightWorking) |
| | | { |
| | | LightStatusStorage.LightStatusDic[putPositions[0]] = LightStatusEnum.LightWorking; |
| | | } |
| | | } |
| | | |
| | | otherDevice.SetValue(GantryDBName.TwoHand, true); |
| | | |
| | | otherDevice.SetValue(GantryDBName.TaskNum, task.TaskNum); |
| | | //otherDevice.SetValue(GantryDBName.TakePosition, Convert.ToInt32(takePositions[0])); |
| | | otherDevice.SetValue(GantryDBName.TakePositionX, Convert.ToInt32(takePositions[1])); |
| | | otherDevice.SetValue(GantryDBName.TakePositionY, Convert.ToInt32(takePositions[2])); |
| | | otherDevice.SetValue(GantryDBName.TakePositionZ, Convert.ToInt32(takePositions[3])); |
| | | otherDevice.SetValue(GantryDBName.TakePositionR, Convert.ToInt32(takePositions[4])); |
| | | //otherDevice.SetValue(GantryDBName.PutPosition, Convert.ToInt32(putPositions[0])); |
| | | otherDevice.SetValue(GantryDBName.PutPositionX, Convert.ToInt32(putPositions[1])); |
| | | otherDevice.SetValue(GantryDBName.PutPositionY, Convert.ToInt32(putPositions[2])); |
| | | otherDevice.SetValue(GantryDBName.PutPositionZ, Convert.ToInt32(putPositions[3])); |
| | | otherDevice.SetValue(GantryDBName.PutPositionR, Convert.ToInt32(putPositions[4])); |
| | | int takePoX = Convert.ToInt32(takePositions[1]); |
| | | int takePoY = Convert.ToInt32(takePositions[2]); |
| | | int takePoZ = OPositions.HPositions[takePositions[0]].PositionZ + 30 * 1000 - Convert.ToInt32(takePositions[3]) * 1000; |
| | | |
| | | if(OPositions.HPositions[takePositions[0]].PositionZ == 0) |
| | | { |
| | | WriteError($"{otherDevice.DeviceCode}-{otherDevice.DeviceName}", "åè´§Zåæ è¯»å为0"); |
| | | return Task.CompletedTask; |
| | | } |
| | | |
| | | int takePoR = 0; |
| | | |
| | | int putPoX = Convert.ToInt32(putPositions[1]); |
| | | int putPoY = Convert.ToInt32(putPositions[2]); |
| | | int putPoZ = OPositions.HPositions[putPositions[0]].PositionZ - Convert.ToInt32(putPositions[3]) * 1000; |
| | | |
| | | if (OPositions.HPositions[takePositions[0]].PositionZ == 0) |
| | | { |
| | | WriteError($"{otherDevice.DeviceCode}-{otherDevice.DeviceName}", "æ¾è´§Zåæ è¯»å为0"); |
| | | return Task.CompletedTask; |
| | | } |
| | | int putPoR = 0; |
| | | |
| | | if (Convert.ToInt32(takePositions[4]) == 1) |
| | | { |
| | | takePoX = takePoX * 1000 + OPositions.HPositions[takePositions[0]].PositionX; |
| | | takePoY = takePoY * 1000 + OPositions.HPositions[takePositions[0]].PositionY; |
| | | putPoX = putPoX * 1000 + OPositions.HPositions[putPositions[0]].PositionX; |
| | | putPoY = putPoY * 1000 + OPositions.HPositions[putPositions[0]].PositionY; |
| | | takePoR = OPositions.HPositions[takePositions[0]].PositionR; |
| | | putPoR = OPositions.HPositions[putPositions[0]].PositionR; |
| | | |
| | | WriteDebug($"{otherDevice.DeviceCode}-{otherDevice.DeviceName}-åæ ", $"åè´§ä½ï¼{takePositions[0]},æ¾è´§ä½ï¼{putPositions[0]}{Environment.NewLine}åè´§åæ ï¼X:{takePoX} Y:{takePoY} Z:{takePoZ} R:{takePoR}{Environment.NewLine}æ¾è´§åæ ï¼X:{putPoX} Y:{putPoY} Z:{putPoZ} R:{putPoR}{Environment.NewLine}读åPLCåè´§åæ ï¼X:{OPositions.HPositions[takePositions[0]].PositionX} Y:{OPositions.HPositions[takePositions[0]].PositionY} Z:{OPositions.HPositions[takePositions[0]].PositionZ} R:{OPositions.HPositions[takePositions[0]].PositionR}{Environment.NewLine}读åPLCæ¾è´§åæ ï¼X:{OPositions.HPositions[putPositions[0]].PositionX} Y:{OPositions.HPositions[putPositions[0]].PositionY} Z:{OPositions.HPositions[putPositions[0]].PositionZ} R:{OPositions.HPositions[putPositions[0]].PositionR}"); |
| | | } |
| | | else |
| | | { |
| | | takePoX = takePoX * 1000 + OPositions.ZPositions[takePositions[0]].PositionX; |
| | | takePoY = takePoY * 1000 + OPositions.ZPositions[takePositions[0]].PositionY; |
| | | putPoX = putPoX * 1000 + OPositions.ZPositions[putPositions[0]].PositionX; |
| | | putPoY = putPoY * 1000 + OPositions.ZPositions[putPositions[0]].PositionY; |
| | | takePoR = OPositions.ZPositions[takePositions[0]].PositionR; |
| | | putPoR = OPositions.ZPositions[putPositions[0]].PositionR; |
| | | |
| | | WriteDebug($"{otherDevice.DeviceCode}-{otherDevice.DeviceName}-åæ ", $"åè´§ä½ï¼{takePositions[0]},æ¾è´§ä½ï¼{putPositions[0]}{Environment.NewLine}åè´§åæ ï¼X:{takePoX} Y:{takePoY} Z:{takePoZ} R:{takePoR}{Environment.NewLine}æ¾è´§åæ ï¼X:{putPoX} Y:{putPoY} Z:{putPoZ} R:{putPoR}{Environment.NewLine}读åPLCåè´§åæ ï¼X:{OPositions.ZPositions[takePositions[0]].PositionX} Y:{OPositions.ZPositions[takePositions[0]].PositionY} Z:{OPositions.ZPositions[takePositions[0]].PositionZ} R:{OPositions.ZPositions[takePositions[0]].PositionR}{Environment.NewLine}读åPLCæ¾è´§åæ ï¼X:{OPositions.ZPositions[putPositions[0]].PositionX} Y:{OPositions.ZPositions[putPositions[0]].PositionY} Z:{OPositions.ZPositions[putPositions[0]].PositionZ} R:{OPositions.ZPositions[putPositions[0]].PositionR}"); |
| | | } |
| | | |
| | | int maxX = otherDevice.GetValue<GantryDBName, int>(GantryDBName.MaxX); |
| | | int minX = otherDevice.GetValue<GantryDBName, int>(GantryDBName.MinX); |
| | | int maxY = otherDevice.GetValue<GantryDBName, int>(GantryDBName.MaxY); |
| | | int minY = otherDevice.GetValue<GantryDBName, int>(GantryDBName.MinY); |
| | | int maxZ = otherDevice.GetValue<GantryDBName, int>(GantryDBName.MaxZ); |
| | | int minZ = otherDevice.GetValue<GantryDBName, int>(GantryDBName.MinZ); |
| | | int maxR = otherDevice.GetValue<GantryDBName, int>(GantryDBName.MaxR); |
| | | int minR = otherDevice.GetValue<GantryDBName, int>(GantryDBName.MinR); |
| | | |
| | | if(takePoX < minX || takePoX > maxX) |
| | | { |
| | | WriteError($"{otherDevice.DeviceCode}-{otherDevice.DeviceName}-åæ ", $"Xåè´§åæ è¶
åºèå´,åè´§åæ ï¼{takePoX},æå¤§å¼ï¼{maxX},æå°å¼ï¼{minX}"); |
| | | return Task.CompletedTask; |
| | | } |
| | | |
| | | if(putPoX < minX || putPoX > maxX) |
| | | { |
| | | WriteError($"{otherDevice.DeviceCode}-{otherDevice.DeviceName}-åæ ", $"Xæ¾è´§åæ è¶
åºèå´,åè´§åæ ï¼{putPoX},æå¤§å¼ï¼{maxX},æå°å¼ï¼{minX}"); |
| | | return Task.CompletedTask; |
| | | } |
| | | |
| | | if (takePoY < minY || takePoY > maxY) |
| | | { |
| | | WriteError($"{otherDevice.DeviceCode}-{otherDevice.DeviceName}-åæ ", $"Yåè´§åæ è¶
åºèå´,åè´§åæ ï¼{takePoY},æå¤§å¼ï¼{maxY},æå°å¼ï¼{minY}"); |
| | | return Task.CompletedTask; |
| | | } |
| | | |
| | | if (putPoY < minY || putPoY > maxY) |
| | | { |
| | | WriteError($"{otherDevice.DeviceCode}-{otherDevice.DeviceName}-åæ ", $"Yæ¾è´§åæ è¶
åºèå´,åè´§åæ ï¼{putPoY},æå¤§å¼ï¼{maxY},æå°å¼ï¼{minY}"); |
| | | return Task.CompletedTask; |
| | | } |
| | | |
| | | if (takePoZ < minZ || takePoZ > maxZ) |
| | | { |
| | | WriteError($"{otherDevice.DeviceCode}-{otherDevice.DeviceName}-åæ ", $"Zåè´§åæ è¶
åºèå´,åè´§åæ ï¼{takePoZ},æå¤§å¼ï¼{maxZ},æå°å¼ï¼{minZ}"); |
| | | return Task.CompletedTask; |
| | | } |
| | | |
| | | if (putPoZ < minZ || putPoZ > maxZ) |
| | | { |
| | | WriteError($"{otherDevice.DeviceCode}-{otherDevice.DeviceName}-åæ ", $"Zæ¾è´§åæ è¶
åºèå´,åè´§åæ ï¼{putPoZ},æå¤§å¼ï¼{maxZ},æå°å¼ï¼{minZ}"); |
| | | return Task.CompletedTask; |
| | | } |
| | | |
| | | if (takePoR < minR || takePoR > maxR) |
| | | { |
| | | WriteError($"{otherDevice.DeviceCode}-{otherDevice.DeviceName}-åæ ", $"Råè´§åæ è¶
åºèå´,åè´§åæ ï¼{takePoR},æå¤§å¼ï¼{maxR},æå°å¼ï¼{minR}"); |
| | | return Task.CompletedTask; |
| | | } |
| | | |
| | | if (putPoR < minR || putPoR > maxR) |
| | | { |
| | | WriteError($"{otherDevice.DeviceCode}-{otherDevice.DeviceName}-åæ ", $"Ræ¾è´§åæ è¶
åºèå´,åè´§åæ ï¼{putPoR},æå¤§å¼ï¼{maxR},æå°å¼ï¼{minR}"); |
| | | return Task.CompletedTask; |
| | | } |
| | | |
| | | otherDevice.SetValue(GantryDBName.TakePositionX, takePoX); |
| | | otherDevice.SetValue(GantryDBName.TakePositionY, takePoY); |
| | | otherDevice.SetValue(GantryDBName.TakePositionZ, takePoZ); |
| | | otherDevice.SetValue(GantryDBName.TakePositionR, takePoR); |
| | | otherDevice.SetValue(GantryDBName.PutPositionX, putPoX); |
| | | otherDevice.SetValue(GantryDBName.PutPositionY, putPoY); |
| | | otherDevice.SetValue(GantryDBName.PutPositionZ, putPoZ); |
| | | otherDevice.SetValue(GantryDBName.PutPositionR, putPoR); |
| | | otherDevice.SetValue(GantryDBName.Length, containerItem.ItemLength); |
| | | otherDevice.SetValue(GantryDBName.Width, containerItem.ItemWidth); |
| | | otherDevice.SetValue(GantryDBName.Height, containerItem.ItemHeight); |
| | |
| | | _taskRepository.UpdateData(task); |
| | | } |
| | | } |
| | | else if(gantryWorkStatus == 5) |
| | | else if (gantryWorkStatus == 5) |
| | | { |
| | | |
| | | int currentTaskNum = otherDevice.GetValue<GantryDBName, int>(GantryDBName.CurrentTaskNum); |
| | | if (currentTaskNum > 0) |
| | | { |
| | | Dt_Task task = _taskRepository.QueryFirst(x => x.TaskNum == currentTaskNum); |
| | | if (task != null) |
| | | { |
| | | _taskService.TaskComplete(task); |
| | | |
| | | string[] putPositions = task.NextAddress.Split("*"); |
| | | if (putPositions.Length != 5) |
| | | { |
| | | //WriteError |
| | | return Task.CompletedTask; |
| | | } |
| | | if (LightStatusStorage.LightStatusDic.TryGetValue(putPositions[0], out LightStatusEnum lightStatusDic)) |
| | | { |
| | | if (lightStatusDic != LightStatusEnum.Ready) |
| | | { |
| | | LightStatusStorage.LightStatusDic[putPositions[0]] = LightStatusEnum.Ready; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | otherDevice.SetValue(GantryDBName.WorkType, 5); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | WriteError($"{otherDevice.DeviceCode}-{otherDevice.DeviceName}", ex.Message, ex); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | else |
| | | { |
| | | |
| | | WriteError(nameof(GantryJob), "åæ°é误,æªä¼ é设å¤åæ°æè®¾å¤ç±»åé误"); |
| | | } |
| | | return Task.CompletedTask; |
| | | } |