| | |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Threading; |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_Common; |
| | | using WIDESEA_Common.LoctionEnum; |
| | | using WIDESEA_Common.Tools; |
| | |
| | | { |
| | | if (Interlocked.Exchange(ref _readGFBUPSignalsoZ, 1) == 0) |
| | | { |
| | | |
| | | try |
| | | Task.Run(() => |
| | | { |
| | | 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 SBID = TBSB.Replace("辊分机正极", "");//设备号 |
| | | PLCClient plc = WCSService.Clients.Find(v => v.PLCName == TBSB); |
| | | if (plc == null) |
| | | { |
| | | //WriteLog.GetLog("GFZ上料呼叫").Write($"设备:{TBSB} 内容:未连接PLC 时间记录:{DateTime.Now}", "GFZ上料呼叫"); |
| | | continue; |
| | | } |
| | | //当前设备有没有上料请求 |
| | | //bool GYR_RFX = Convert.ToBoolean(plc.ReadValue("R_Feedingrequest".ToString(), plc.EquipType)); |
| | | //if (GYR_RFX) |
| | | 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" }; |
| | | |
| | | OperateResult<bool> GYR_RFX = plc.MelsecPLCClient.MelsecMcNetClient.ReadBool("D5493.0"); |
| | | Int16 tf = Convert.ToInt16(GYR_RFX.Content); |
| | | if (GYR_RFX.Content) |
| | | foreach (var TBSB in TBSBS) |
| | | { |
| | | //查看当前辊分机设备是否有AGV任务 |
| | | var SBtask = agvRepository.FindFirst(f => f.agv_toaddress == plc.EquipType); |
| | | //有结束本次循环 |
| | | if (SBtask != null) { continue; } |
| | | List<base_routing_table> Routing_Table = routingRepository.Find(d => d.route_end == plc.EquipType); |
| | | List<base_ware_location> loctionList = new List<base_ware_location>(); |
| | | foreach (var item in Routing_Table) |
| | | //string SBID = TBSB.Replace("辊分机正极", "");//设备号 |
| | | PLCClient plc = WCSService.Clients.Find(v => v.PLCName == TBSB); |
| | | if (plc == null) |
| | | { |
| | | base_ware_location ware_Locations = locRepository.FindFirst(d => d.upper_code == item.route_began && d.status == 1 && d.location_state == LoctionStateEnum.LocationState_Stored.ToString() && d.logic_col == 1 && d.task == 2); |
| | | if (ware_Locations == null) |
| | | //WriteLog.GetLog("GFZ上料呼叫").Write($"设备:{TBSB} 内容:未连接PLC 时间记录:{DateTime.Now}", "GFZ上料呼叫"); |
| | | continue; |
| | | } |
| | | //当前设备有没有上料请求 |
| | | //bool GYR_RFX = Convert.ToBoolean(plc.ReadValue("R_Feedingrequest".ToString(), plc.EquipType)); |
| | | //if (GYR_RFX) |
| | | |
| | | OperateResult<bool> GYR_RFX = plc.MelsecPLCClient.MelsecMcNetClient.ReadBool("D5493.0"); |
| | | Int16 tf = Convert.ToInt16(GYR_RFX.Content); |
| | | if (GYR_RFX.Content) |
| | | { |
| | | //查看当前辊分机设备是否有AGV任务 |
| | | var SBtask = agvRepository.FindFirst(f => f.agv_toaddress == plc.EquipType); |
| | | //有结束本次循环 |
| | | if (SBtask != null) { continue; } |
| | | #region 记录上料请求信号 |
| | | WriteLog.GetLog().Write($"{plc.PLCName}上料请求:{GYR_RFX.Content}---{DateTime.Now}", $"正极棍分上料请求"); |
| | | #endregion |
| | | List<base_routing_table> Routing_Table = routingRepository.Find(d => d.route_end == plc.EquipType); |
| | | List<base_ware_location> loctionList = new List<base_ware_location>(); |
| | | foreach (var item in Routing_Table) |
| | | { |
| | | continue; |
| | | base_ware_location ware_Locations = locRepository.FindFirst(d => d.upper_code == item.route_began && d.status == 1 && d.location_state == LoctionStateEnum.LocationState_Stored.ToString() && d.logic_col == 1 && d.task == 2); |
| | | if (ware_Locations == null) |
| | | { |
| | | continue; |
| | | } |
| | | loctionList.Add(ware_Locations); |
| | | } |
| | | loctionList.Add(ware_Locations); |
| | | |
| | | if (loctionList.Count != 0) |
| | | { |
| | | base_ware_location Location = loctionList.OrderBy(d => d.update_time).FirstOrDefault(); |
| | | |
| | | |
| | | //生成辊分机上料任务 |
| | | dt_agvtask agvtask = new dt_agvtask() |
| | | { |
| | | agv_id = Guid.NewGuid(), |
| | | agv_tasknum = "KH-" + IdenxManager.GetTaskNo(), |
| | | agv_fromaddress = Location.upper_code, |
| | | agv_toaddress = plc.EquipType, |
| | | 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 = "", |
| | | }; |
| | | |
| | | |
| | | //Location.update_time = DateTime.Now; |
| | | |
| | | Location.task = 1; |
| | | Location.logic_col = 1; |
| | | var entry = locRepository.DbContext.ChangeTracker.Entries<base_ware_location>().FirstOrDefault(); |
| | | if (entry != null) |
| | | { |
| | | entry.State = EntityState.Detached; |
| | | } |
| | | int a = locRepository.Update(Location, d => new { d.task, d.logic_col }, true); |
| | | if (a == 1) |
| | | { |
| | | agvRepository.Add(agvtask, true); |
| | | //WriteDBLog.Info($"【{TBSB}】上料任务生成").Write($"生成任务:{agvtask.agv_tasknum},起点货位状态:托盘光电检测:{Location.tpgd},状态:{Location.location_state},更新时间:{Location.wireless_time}", $"【{TBSB}】上料任务生成"); |
| | | //WriteDBLog.Info($"【{TBSB}】上料任务生成").Write($"----------------任务生成成功 {DateTime.Now} -------------- {Environment.NewLine}", $"【{TBSB}】上料任务生成"); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | if (loctionList.Count != 0) |
| | | { |
| | | base_ware_location Location = loctionList.OrderBy(d => d.update_time).FirstOrDefault(); |
| | | |
| | | |
| | | //生成辊分机上料任务 |
| | | dt_agvtask agvtask = new dt_agvtask() |
| | | { |
| | | agv_id = Guid.NewGuid(), |
| | | agv_tasknum = "KH-" + IdenxManager.GetTaskNo(), |
| | | agv_fromaddress = Location.upper_code, |
| | | agv_toaddress = plc.EquipType, |
| | | 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 = "", |
| | | }; |
| | | |
| | | |
| | | //Location.update_time = DateTime.Now; |
| | | |
| | | Location.task = 1; |
| | | Location.logic_col = 1; |
| | | var entry = locRepository.DbContext.ChangeTracker.Entries<base_ware_location>().FirstOrDefault(); |
| | | if (entry != null) |
| | | { |
| | | entry.State = EntityState.Detached; |
| | | } |
| | | int a= locRepository.Update(Location, d => new { d.task, d.logic_col }, true); |
| | | if (a==1) |
| | | { |
| | | agvRepository.Add(agvtask, true); |
| | | WriteDBLog.Info($"【{TBSB}】上料任务生成").Write($"生成任务:{agvtask.agv_tasknum},起点货位状态:托盘光电检测:{Location.tpgd},状态:{Location.location_state},更新时间:{Location.wireless_time}", $"【{TBSB}】上料任务生成"); |
| | | WriteDBLog.Info($"【{TBSB}】上料任务生成").Write($"----------------任务生成成功 {DateTime.Now} -------------- {Environment.NewLine}", $"【{TBSB}】上料任务生成"); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | } |
| | | } |
| | | catch (Exception) |
| | | { |
| | | |
| | | throw; |
| | | } |
| | | finally |
| | | { |
| | | Interlocked.Exchange(ref _readGFBUPSignalsoZ, 0); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | WriteLog.GetLog().Write($"正极棍分上料:{DateTime.Now} --------------{ex}", $"正极棍分上料"); |
| | | } |
| | | finally |
| | | { |
| | | Interlocked.Exchange(ref _readGFBUPSignalsoZ, 0); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | } |
| | | |