| | |
| | | using WIDESEA_Services.Services; |
| | | using WIDESEA_WCS.WCSClient; |
| | | |
| | | namespace WIDESEA_WCS.SchedulerExecute.AGV |
| | | namespace WIDESEA_WCS.JobsPart.AGV |
| | | { |
| | | public partial class AGVSchedulerExecute |
| | | public partial class AGVServer |
| | | { |
| | | private static int _readUpdateAGVTaskSignalsotask = 0; |
| | | public static void UpdateAgvTask(PLCClient plcClient) |
| | | private static int _readUpdateAGVTaskSignalso = 0; |
| | | public void UpdateAgvTask(PLCClient plcClient) |
| | | { |
| | | if (Interlocked.Exchange(ref _readUpdateAGVTaskSignalsotask, 1) == 0) |
| | | if (Interlocked.Exchange(ref _readUpdateAGVTaskSignalso, 1) == 0) |
| | | { |
| | | try |
| | | { |
| | | if (plcClient == null) |
| | | { |
| | | return; |
| | | } |
| | | VOLContext context = new VOLContext(); |
| | | Idt_task_numberRepository tasknumberRep = new dt_task_numberRepository(context); |
| | | Idt_agvtaskRepository agvtaskRepository = new dt_agvtaskRepository(context); |
| | |
| | | if (1 == taskFbInteractive && taskFbInteractiveW == 0) |
| | | { |
| | | string taskId = plcClient.ReadValue(TaskDBName.taskIDFb.ToString()).ToString();//任务ID |
| | | |
| | | if (taskId.Contains("\b")) { taskId = taskId.Remove(0, 1); } |
| | | int taskState = int.Parse(plcClient.ReadValue(TaskDBName.taskStatusFb.ToString()).ToString());//1起点执行中,2起点已完成,3终点执行中,4终点已完成 |
| | | WriteLog.GetLog().Write($"{plcClient.PLCName}开始:" + taskId + "任务状态:"+ taskState + "{DateTime.Now}", "AGV更新任务状态测试"); |
| | | if (0 == taskState)//无含义 |
| | | return; |
| | | WriteLog.GetLog().Write($"{plcClient.PLCName}任务号" + taskId + "任务状态" + taskState + $" {DateTime.Now}", "AGV更新任务状态"); |
| | |
| | | } |
| | | |
| | | #region 编写对应项目的业务逻辑 |
| | | |
| | | Task task = Task.Run(() => |
| | | { |
| | | if (null == agvTask) |
| | |
| | | //throw new Exception("起点执行失败未找到任务,ID:" + taskId); |
| | | } |
| | | agvTask.agv_taskstate = AGVTaskStateEnum.Executing.ToString(); |
| | | agvTask.agv_realesstime = DateTime.Now; |
| | | int isOk = agvtaskRepository.Update(agvTask, true); |
| | | if (isOk == 0) |
| | | { |
| | |
| | | { |
| | | if (agvTask != null) |
| | | { |
| | | |
| | | WriteLog.GetLog().Write($"任务号:{agvTask.agv_tasknum},起点地址:{agvTask.agv_fromaddress},终点地址:{agvTask.agv_toaddress} 时间: {DateTime.Now}", "AGV任务反馈2"); |
| | | if (agvTask.agv_taskstate == AGVTaskStateEnum.Complete.ToString()) |
| | | { |
| | | plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 1); |
| | | WriteLog.GetLog().Write("WCS再次写入AGV任务号" + taskId + "," + DateTime.Now + "任务起点完成状态确认1", "AGV更新任务状态"); |
| | | } |
| | | |
| | | #region 编写对应项目的业务逻辑 |
| | | Task.Run(() => |
| | | { |
| | | WriteLog.GetLog().Write($"任务号:{agvTask.agv_tasknum},起点地址:{agvTask.agv_fromaddress},终点地址:{agvTask.agv_toaddress} 时间: {DateTime.Now}", "AGV任务反馈2"); |
| | | if (agvTask.agv_taskstate == AGVTaskStateEnum.Complete.ToString()) |
| | | { |
| | | plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 1); |
| | | WriteLog.GetLog().Write("WCS再次写入AGV任务号" + taskId + "," + DateTime.Now + "任务起点完成状态确认1", "AGV更新任务状态"); |
| | | } |
| | | |
| | | #region 编写对应项目的业务逻辑 |
| | | if (null == agvTask) |
| | | { |
| | | plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 1); |
| | |
| | | agvTask.agv_taskstate = AGVTaskStateEnum.Abnormal.ToString(); |
| | | isOk = agvtaskRepository.Update(agvTask, true); |
| | | } |
| | | if (agvTask.agv_remark.Contains("PDA库房叫料任务") || agvTask.agv_remark.Contains("PDA产线叫料任务")) |
| | | if (agvTask.agv_remark.Contains("PDA库房叫料任务") || agvTask.agv_remark.Contains("PDA产线叫料任务")) |
| | | { |
| | | base_pda_location pda_Location = pdaloctionRepository.FindFirst(d => d.L_Code == agvTask.agv_fromaddress); |
| | | if (pda_Location == null) |
| | |
| | | return; |
| | | } |
| | | dt_container container = containerRepository.FindFirst(d => d.container_sn == agvTask.agv_barcode && d.container_barcode == pda_Location.L_Code); |
| | | if (container != null) |
| | | if (container!=null) |
| | | { |
| | | containerRepository.Delete(container, true); |
| | | pda_Location.L_Task = 2; |
| | | pda_Location.L_state = LoctionStateEnum.LocationState_Empty.ToString(); |
| | | pdaloctionRepository.Update(pda_Location, true); |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | | else if (agvTask.agv_remark.Contains("PDA回流任务")) |
| | |
| | | } |
| | | else if (3 == taskState)//任务终点执行中 |
| | | { |
| | | |
| | | if (agvTask != null) |
| | | { |
| | | WriteLog.GetLog().Write($"任务号:{agvTask.agv_tasknum},起点地址:{agvTask.agv_fromaddress},终点地址:{agvTask.agv_toaddress} 时间: {DateTime.Now}", "AGV任务反馈3"); |
| | | #region 编写对应项目的业务逻辑 |
| | | Task.Run(() => |
| | | { |
| | | WriteLog.GetLog().Write($"任务号:{agvTask.agv_tasknum},起点地址:{agvTask.agv_fromaddress},终点地址:{agvTask.agv_toaddress} 时间: {DateTime.Now}", "AGV任务反馈3"); |
| | | |
| | | if (agvTask.agv_taskstate == AGVTaskStateEnum.Executing1.ToString()) |
| | | { |
| | | plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 1); |
| | |
| | | location.task = 2; |
| | | location.logic_row = "0"; |
| | | |
| | | int a = locationRepository.Update(location, x => new { x.logic_col, x.task, x.logic_row, x.update_time, x.geartype }, true); |
| | | int a = locationRepository.Update(location, x => new { x.logic_col, x.task, x.logic_row, x.update_time,x.geartype }, true); |
| | | if (a == 0) |
| | | { |
| | | WriteLog.GetLog().Write($"任务号:{agvTask.agv_tasknum},内容:终点地址:{location.upper_code},货位修改失败", $"货位修改失败"); |
| | |
| | | } |
| | | } |
| | | }); |
| | | |
| | | |
| | | #endregion |
| | | |
| | | plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 1); |
| | |
| | | { |
| | | WriteLog.GetLog().Write($"任务号:{agvTask.agv_tasknum},起点地址:{agvTask.agv_fromaddress},终点地址:{agvTask.agv_toaddress} 时间: {DateTime.Now}", "AGV任务反馈4"); |
| | | #region 编写对应项目的业务逻辑 |
| | | |
| | | Task.Run(() => |
| | | { |
| | | |
| | | agvTask.agv_taskstate = AGVTaskStateEnum.Complete1.ToString(); |
| | | int isOk = agvtaskRepository.Update(agvTask, true); |
| | | if (isOk == 0) |
| | |
| | | } |
| | | else if (agvTask.agv_toaddress.Contains("HCJ")) |
| | | { |
| | | if (location.upper_code.Contains("FJ-BCHCJ37") || location.upper_code.Contains("FJ-BCHCJ36") || location.upper_code.Contains("ZJ-BCHCJ35") || location.upper_code.Contains("ZJ-BCHCJ34")) |
| | | if (location.upper_code.Contains("FJ-BCHCJ37") || location.upper_code.Contains("FJ-BCHCJ36") || location.upper_code.Contains("ZJ-BCHCJ35") || location.upper_code.Contains("ZJ-BCHCJ34")) |
| | | { |
| | | location.logic_row = "TSJXL-BCK"; |
| | | location.logic_col = 1; |
| | | } |
| | | else if (location.upper_code.Contains("FJ-BCHCJ35") || location.upper_code.Contains("FJ-BCHCJ34") || location.upper_code.Contains("ZJ-BCHCJ33") || location.upper_code.Contains("ZJ-BCHCJ32")) |
| | | else if (location.upper_code.Contains("FJ-BCHCJ35") || location.upper_code.Contains("FJ-BCHCJ34")|| location.upper_code.Contains("ZJ-BCHCJ33")|| location.upper_code.Contains("ZJ-BCHCJ32")) |
| | | { |
| | | location.logic_row = "TBXL-BCK"; |
| | | location.logic_col = 1; |
| | | } |
| | | else if (agvTask.agv_fromaddress.Contains("FJ-BCHCJ37") || agvTask.agv_fromaddress.Contains("ZJ-BCHCJ35")) |
| | | else if (agvTask.agv_fromaddress.Contains("FJ-BCHCJ37")|| agvTask.agv_fromaddress.Contains("ZJ-BCHCJ35")) |
| | | { |
| | | location.logic_row = "TSJXL-BCK"; |
| | | location.logic_col = 0; |
| | |
| | | else if (agvTask.agv_remark.Contains("PDA回流任务")) |
| | | { |
| | | base_pda_location pda_Location = pdaloctionRepository.FindFirst(d => d.L_Code == agvTask.agv_toaddress); |
| | | if (pda_Location == null) |
| | | if (pda_Location==null) |
| | | { |
| | | Console.WriteLine($"异常:PDA回流任务终点地址不不在:{agvTask.agv_toaddress}"); |
| | | return; |
| | |
| | | containerRepository.Add(dt_Container, true); |
| | | pda_Location.L_Task = 2; |
| | | pda_Location.L_state = LoctionStateEnum.LocationState_Stored.ToString(); |
| | | pdaloctionRepository.Update(pda_Location, d => new { d.L_state, d.L_Task }, true); |
| | | pdaloctionRepository.Update(pda_Location,d=>new {d.L_state,d.L_Task }, true); |
| | | |
| | | |
| | | } |
| | | else if (agvTask.agv_remark.Contains("铝壳缓存架任务")) |
| | | { |
| | | dt_stationinfo dt_Stationinfo = stationinfoRepository.FindFirst(d => d.stationCode == agvTask.agv_toaddress); |
| | | if (dt_Stationinfo == null) |
| | | if (dt_Stationinfo==null) |
| | | { |
| | | Console.WriteLine($"异常:铝壳缓存架任务终点地址不不在:{agvTask.agv_toaddress}"); |
| | | return; |
| | |
| | | WriteLog.GetLog().Write("WCS写入AGV任务号" + taskId + DateTime.Now + "任务异常状态确认1", "AGV更新任务状态"); |
| | | agvtaskRepository.Delete(agvTask, true); |
| | | } |
| | | WriteLog.GetLog().Write($"{plcClient.PLCName}结束:" + taskId + "{DateTime.Now}", "AGV更新任务状态测试"); |
| | | } |
| | | if (taskFbInteractive == 0 && taskFbInteractiveW == 1) |
| | | { |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | |
| | | } |
| | | finally |
| | | { |
| | | Interlocked.Exchange(ref _readUpdateAGVTaskSignalsotask, 0); |
| | | Interlocked.Exchange(ref _readUpdateAGVTaskSignalso, 0); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |