| | |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Threading; |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_Common; |
| | | using WIDESEA_Common.DBHelper; |
| | | using WIDESEA_Common.LoctionEnum; |
| | |
| | | { |
| | | if (Interlocked.Exchange(ref _readZTBSignalsoZ, 1) == 0) |
| | | { |
| | | try |
| | | Task.Run(() => |
| | | { |
| | | FreeDB freeDB = new FreeDB(); |
| | | VOLContext Context = new VOLContext(); |
| | | Ibase_ware_locationRepository locRepository = new base_ware_locationRepository(Context); |
| | | Ibase_routing_tableRepository routingRepository = new base_routing_tableRepository(Context); |
| | | Idt_agvtaskRepository agvRepository = new dt_agvtaskRepository(Context); |
| | | List<string> TBSBS = new List<string> { "涂布机正极1", "涂布机正极2", "涂布机正极3", "涂布机正极4" }; |
| | | |
| | | //循环处理涂布设备上料请求 |
| | | foreach (var TBSB in TBSBS) |
| | | try |
| | | { |
| | | string SB_Up_Location = "ZJSL-TBSB" + TBSB.Replace("涂布机正极", "");//拼接涂布上料口 |
| | | if (WCSService.Clients == null) |
| | | { |
| | | return; |
| | | } |
| | | PLCClient plc = WCSService.Clients.Find(v => v.PLCName == TBSB); |
| | | if (plc == null) |
| | | { |
| | | continue; |
| | | } |
| | | //当前设备有没有上料请求 |
| | | bool GYR_RFX = plc.OmronPLCClient.OmronFinsNetClient.ReadBool("D11093.00").Content; |
| | | //Convert.ToBoolean(plc.ReadValue("R_Feedingrequest".ToString(), SB_Up_Location)); |
| | | if (GYR_RFX) |
| | | { |
| | | //查看当前涂布机设备是否有AGV任务 |
| | | var SBtask = agvRepository.FindFirst(f => f.agv_fromaddress == SB_Up_Location || f.agv_toaddress == SB_Up_Location); |
| | | //有结束本次循环 if (SBtask != null) { continue; } |
| | | List<base_routing_table> Routing_Table = routingRepository.Find(d => d.route_end == SB_Up_Location); |
| | | FreeDB freeDB = new FreeDB(); |
| | | VOLContext Context = new VOLContext(); |
| | | Ibase_ware_locationRepository locRepository = new base_ware_locationRepository(Context); |
| | | Ibase_routing_tableRepository routingRepository = new base_routing_tableRepository(Context); |
| | | Idt_agvtaskRepository agvRepository = new dt_agvtaskRepository(Context); |
| | | List<string> TBSBS = new List<string> { "涂布机正极1", "涂布机正极2", "涂布机正极3", "涂布机正极4" }; |
| | | |
| | | //找到对应箔材库货位(36号位置),并确认有料 |
| | | base_ware_location location_36 = locRepository.FindFirst(t => t.upper_code == "ZJ-BCHCJ34" && t.location_state == LoctionStateEnum.LocationState_Stored.ToString() && t.status == 1 && t.logic_col == 1 && t.task == 2); |
| | | if (location_36 != null) |
| | | //循环处理涂布设备上料请求 |
| | | foreach (var TBSB in TBSBS) |
| | | { |
| | | string SB_Up_Location = "ZJSL-TBSB" + TBSB.Replace("涂布机正极", "");//拼接涂布上料口 |
| | | if (WCSService.Clients == null) |
| | | { |
| | | dt_agvtask agvtask_36 = agvRepository.Find(t => t.agv_fromaddress == location_36.upper_code).FirstOrDefault(); |
| | | if (agvtask_36 != null) |
| | | { |
| | | return; |
| | | } |
| | | //生成涂布机上料任务 |
| | | dt_agvtask agvtask = new dt_agvtask() |
| | | { |
| | | agv_id = Guid.NewGuid(), |
| | | agv_tasknum = "KH-" + IdenxManager.GetTaskNo(), |
| | | agv_fromaddress = location_36.upper_code, |
| | | agv_toaddress = SB_Up_Location, |
| | | agv_code = "正极AGV调度", |
| | | agv_remark = "涂布上料任务", |
| | | agv_taskstate = AGVTaskStateEnum.Create.ToString(), |
| | | agv_tasktype = AGVTaskTypeEnum.TaskType_Outbound.ToString(), |
| | | agv_worktype = 1,//工作类型 |
| | | agv_materielid = "", |
| | | agv_qty = 1, |
| | | agv_createtime = DateTime.Now, |
| | | agv_grade = 0,//任务优先级 |
| | | agv_userid = "WCS", |
| | | agv_barcode = "", |
| | | }; |
| | | //WriteLog.GetLog($"任务生成记录").Write($"任务号:{agvtask.agv_tasknum},起点{location_36.upper_code}光电:{location_36.created_user}=>终点:{SB_Up_Location},任务已生成", "任务生成记录"); |
| | | |
| | | return; |
| | | } |
| | | PLCClient plc = WCSService.Clients.Find(v => v.PLCName == TBSB); |
| | | if (plc == null) |
| | | { |
| | | continue; |
| | | } |
| | | //当前设备有没有上料请求 |
| | | bool GYR_RFX = plc.OmronPLCClient.OmronFinsNetClient.ReadBool("D11093.00").Content; |
| | | //Convert.ToBoolean(plc.ReadValue("R_Feedingrequest".ToString(), SB_Up_Location)); |
| | | if (GYR_RFX) |
| | | { |
| | | //查看当前涂布机设备是否有AGV任务 |
| | | var SBtask = agvRepository.FindFirst(f => f.agv_fromaddress == SB_Up_Location || f.agv_toaddress == SB_Up_Location); |
| | | //有结束本次循环 |
| | | if (SBtask != null) { continue; } |
| | | #region 记录上料请求信号 |
| | | WriteLog.GetLog().Write($"{plc.PLCName}上料请求:{GYR_RFX}---{DateTime.Now}", $"正极涂布上料请求"); |
| | | #endregion |
| | | List<base_routing_table> Routing_Table = routingRepository.Find(d => d.route_end == SB_Up_Location); |
| | | |
| | | location_36.task = 1; |
| | | location_36.update_time = DateTime.Now; |
| | | |
| | | int a= locRepository.Update(location_36, d => new { d.task, d.update_time }, true); |
| | | if (a==1) |
| | | //找到对应箔材库货位(36号位置),并确认有料 |
| | | base_ware_location location_36 = locRepository.FindFirst(t => t.upper_code == "ZJ-BCHCJ34" && t.location_state == LoctionStateEnum.LocationState_Stored.ToString() && t.status == 1 && t.logic_col == 1 && t.task == 2); |
| | | if (location_36 != null) |
| | | { |
| | | dt_agvtask agvtask_36 = agvRepository.Find(t => t.agv_fromaddress == location_36.upper_code).FirstOrDefault(); |
| | | if (agvtask_36 != null) |
| | | { |
| | | return; |
| | | } |
| | | //生成涂布机上料任务 |
| | | dt_agvtask agvtask = new dt_agvtask() |
| | | { |
| | | agv_id = Guid.NewGuid(), |
| | | agv_tasknum = "KH-" + IdenxManager.GetTaskNo(), |
| | | agv_fromaddress = location_36.upper_code, |
| | | agv_toaddress = SB_Up_Location, |
| | | agv_code = "正极AGV调度", |
| | | agv_remark = "涂布上料任务", |
| | | agv_taskstate = AGVTaskStateEnum.Create.ToString(), |
| | | agv_tasktype = AGVTaskTypeEnum.TaskType_Outbound.ToString(), |
| | | agv_worktype = 1,//工作类型 |
| | | agv_materielid = "", |
| | | agv_qty = 1, |
| | | agv_createtime = DateTime.Now, |
| | | agv_grade = 0,//任务优先级 |
| | | agv_userid = "WCS", |
| | | agv_barcode = "", |
| | | }; |
| | | //WriteLog.GetLog($"任务生成记录").Write($"任务号:{agvtask.agv_tasknum},起点{location_36.upper_code}光电:{location_36.created_user}=>终点:{SB_Up_Location},任务已生成", "任务生成记录"); |
| | | |
| | | |
| | | location_36.task = 1; |
| | | location_36.update_time = DateTime.Now; |
| | | |
| | | int a = locRepository.Update(location_36, d => new { d.task, d.update_time }, true); |
| | | if (a == 1) |
| | | { |
| | | agvRepository.Add(agvtask, true); |
| | | WriteDBLog.Info($"【{TBSB}】上料任务生成").Write($"生成任务:{agvtask.agv_tasknum},起点货位【{location_36.upper_code}】状态:托盘光电检测:{location_36.tpgd},状态:{location_36.location_state},更新时间:{location_36.wireless_time}", $"【{TBSB}】上料任务生成"); |
| | | WriteDBLog.Info($"【{TBSB}】上料任务生成").Write($"----------------任务生成成功 {DateTime.Now} -------------- {Environment.NewLine}", $"【{TBSB}】上料任务生成"); |
| | | |
| | | } |
| | | //WriteLog.GetLog("设备呼叫").Write($"设备 {TBSB} 呼叫成功,任务{agvtask.agv_tasknum}生成", "设备呼叫"); |
| | | break; |
| | | } |
| | | else |
| | | { |
| | | //WriteLog.GetLog("设备呼叫").Write($"设备 {TBSB} 上料呼叫,未找到满足搬运条件的货架,任务生成失败", "设备呼叫"); |
| | | } |
| | | //WriteDBLog.Info($"【{TBSB}】上料任务生成").Write($"生成任务:{agvtask.agv_tasknum},起点货位【{location_36.upper_code}】状态:托盘光电检测:{location_36.tpgd},状态:{location_36.location_state},更新时间:{location_36.wireless_time}", $"【{TBSB}】上料任务生成"); |
| | | //WriteDBLog.Info($"【{TBSB}】上料任务生成").Write($"----------------任务生成成功 {DateTime.Now} -------------- {Environment.NewLine}", $"【{TBSB}】上料任务生成"); |
| | | |
| | | } |
| | | //WriteLog.GetLog("设备呼叫").Write($"设备 {TBSB} 呼叫成功,任务{agvtask.agv_tasknum}生成", "设备呼叫"); |
| | | break; |
| | | } |
| | | else |
| | | { |
| | | //WriteLog.GetLog("设备呼叫").Write($"设备 {TBSB} 上料呼叫,未找到满足搬运条件的货架,任务生成失败", "设备呼叫"); |
| | | } |
| | | |
| | | } |
| | | //else |
| | | //{ |
| | | |
| | | // //WriteLog.GetLog("TBZ上料呼叫").Write($"设备:{TBSB} 内容:无呼叫请求 时间记录:{DateTime.Now}", "TBZ上料呼叫"); |
| | | //} |
| | | } |
| | | //else |
| | | //{ |
| | | |
| | | // //WriteLog.GetLog("TBZ上料呼叫").Write($"设备:{TBSB} 内容:无呼叫请求 时间记录:{DateTime.Now}", "TBZ上料呼叫"); |
| | | //} |
| | | } |
| | | } |
| | | catch (Exception) |
| | | { |
| | | |
| | | throw; |
| | | } |
| | | finally |
| | | { |
| | | Interlocked.Exchange(ref _readZTBSignalsoZ, 0); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | WriteLog.GetLog().Write($"正极涂布上料:{DateTime.Now} --------------{ex}", $"正极涂布上料"); |
| | | } |
| | | finally |
| | | { |
| | | Interlocked.Exchange(ref _readZTBSignalsoZ, 0); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | } |
| | | |