| | |
| | | using HslCommunication; |
| | | using SqlSugar; |
| | | using WIDESEA_Core.Extensions; |
| | | using static System.Collections.Specialized.BitVector32; |
| | | using WIDESEA_WCS.WCSClient.Modbus; |
| | | using static FreeSql.Internal.GlobalFilter; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; |
| | | using System.Reflection.Metadata; |
| | | using Dm; |
| | | |
| | | namespace WIDESEA_WCS |
| | | { |
| | |
| | | { |
| | | FreeDB freeDB = new FreeDB(); |
| | | static List<HCJCenterEqDB> centerEqDBList; |
| | | static List<HCJCenterEqDB> centerJRDBList; |
| | | private static object createTaskObj = new object(); |
| | | public Task Execute(IJobExecutionContext context) |
| | | { |
| | |
| | | client.Connect(); |
| | | return; |
| | | } |
| | | //铝壳缓存架业务作业 |
| | | LKHCJdispatch(); |
| | | if (client.PLCName.Contains("铝壳")) |
| | | { |
| | | //铝壳缓存架业务作业 |
| | | LKHCJdispatch(); |
| | | } |
| | | else |
| | | { |
| | | //卷绕缓存架业务作业 |
| | | JRHCJdispatch(); |
| | | } |
| | | |
| | | } |
| | | /// <summary> |
| | | /// 卷绕缓存架业务作业 |
| | | /// </summary> |
| | | private void JRHCJdispatch() |
| | | { |
| | | |
| | | //铝壳缓存架搬运 |
| | | PLCClient pLCClientJR = WCSService.Clients.Find(V => V.PLCName==PLCConst.PLCNameJR); |
| | | if (pLCClientJR != null) |
| | | { |
| | | string tsjJson = File.ReadAllText(AppContext.BaseDirectory + "/Config/卷绕缓存架.json", Encoding.UTF8); |
| | | centerJRDBList = JsonConvert.DeserializeObject<List<HCJCenterEqDB>>(tsjJson); |
| | | if (centerJRDBList == null) |
| | | { |
| | | return; |
| | | } |
| | | PLCClient agvzzplc = WCSService.Clients.Find(v => v.PLCName == "组装AGV调度"); |
| | | UpdateJRHCJ(pLCClientJR); |
| | | #region 卷绕叫料 |
| | | List<base_ware_location> locations = freeDB.Select<base_ware_location>() |
| | | .Where(x => (x.tpgd == 0 && x.gd1 == 0 && x.gd2 == 0 && x.gd3 == 0 && x.gd4 == 0 && x.status == 1 && x.task == 2 && x.logic_layer == "1" && x.location_state == "LocationState_Empty") && (x.upper_code.Contains("QJHCJ10") || x.upper_code.Contains("QJHCJ11"))) |
| | | .ToList(); |
| | | foreach (var item in locations) |
| | | { |
| | | if (item.geartype == "暂无") |
| | | { |
| | | WriteLog.GetLog().Write($"{item.upper_code}{item.geartype}---{DateTime.Now}", $"卷绕上料请求失败"); |
| | | continue; |
| | | } |
| | | List<base_routing_table> routing_table = freeDB.Select<base_routing_table>() |
| | | .Where(v => v.route_end == item.upper_code).ToList(); |
| | | if (routing_table.Count > 0)//无料才能生成任务&& location_QJ.tpgd==0 |
| | | { |
| | | List<string> route_begans = routing_table.Select(x => x.route_began).ToList(); |
| | | base_ware_location ware_Location = freeDB.Select<base_ware_location>() |
| | | .Where(d => route_begans.Contains(d.upper_code) && d.location_state == "LocationState_Stored" && d.logic_col == 1 && d.tpgd == 1 && d.status == 1 && d.task == 2 && d.geartype == item.geartype).OrderBy(d => d.update_time).First(); |
| | | if (ware_Location != null) |
| | | { |
| | | base_ware_location jkloction = ware_Location; |
| | | #region 记录上料请求信号 |
| | | WriteLog.GetLog().Write($"{item.upper_code}上料请求---{DateTime.Now}", $"卷绕上料请求"); |
| | | #endregion |
| | | //再次判断是否有任务存在 |
| | | dt_agvtask agvtaskOld = freeDB.Select<dt_agvtask>().Where(x => x.agv_toaddress == item.upper_code).First(); |
| | | if (agvtaskOld != null && item.task == 2) |
| | | { |
| | | item.logic_col = 1;//设置良品物料 |
| | | item.task = 1;//设置任务生成1 |
| | | var locationOffOld1 = freeDB.Update(item).UpdateColumns(t => new |
| | | { |
| | | t.logic_col, |
| | | t.task |
| | | }).ExecuteAffrows(); |
| | | continue; |
| | | } |
| | | dt_agvtask agvtask = new dt_agvtask() |
| | | { |
| | | agv_id = Guid.NewGuid(), |
| | | agv_tasknum = "KH-" + IdenxManager.GetTaskNo(), |
| | | agv_fromaddress = jkloction.upper_code, |
| | | agv_toaddress = item.upper_code, |
| | | 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 = "" |
| | | }; |
| | | item.logic_col = 1;//设置良品物料 |
| | | item.task = 1;//设置任务生成1 |
| | | var locationOff1 = freeDB.Update(item).UpdateColumns(t => new |
| | | { |
| | | t.logic_col, |
| | | t.task |
| | | }).ExecuteAffrows(); |
| | | jkloction.logic_col = 1;//设置良品物料 |
| | | jkloction.task = 1;//设置任务生成1 |
| | | var locationOff2 = freeDB.Update(jkloction).UpdateColumns(t => new |
| | | { |
| | | t.logic_col, |
| | | t.task |
| | | }).ExecuteAffrows(); |
| | | freeDB.Add(agvtask); |
| | | } |
| | | else |
| | | { |
| | | WriteLog.GetLog().Write($"{item.upper_code}未找到满足送往切卷的极库料---{DateTime.Now}", $"卷绕上料请求失败"); |
| | | } |
| | | } |
| | | } |
| | | #endregion |
| | | } |
| | | } |
| | | private void UpdateJRHCJ(PLCClient client) |
| | | { |
| | | ModbusTcpNet ModbusPLCClient = client.ModbusPLCClient.ModbusTcpNetClient; |
| | | var stationList = centerJRDBList.FirstOrDefault(t => client.PLCName.Contains(t.HCJCenterName)); |
| | | foreach (var item in stationList.stationInfos) |
| | | { |
| | | base_ware_location location = freeDB.Select<base_ware_location>() |
| | | .Where(x => x.upper_code == item.HCJCode) |
| | | .First(); |
| | | ////Console.WriteLine($"{station.stationCode}------{DateTime.Now}"); |
| | | if (location == null) |
| | | { |
| | | continue; |
| | | } |
| | | string wlgd1DB = item.RPLCDB[0];//物料光电1状态信号点位 |
| | | string wlgd2DB = item.RPLCDB[1];//物料光电2状态信号点位 |
| | | string wlgd3DB = item.RPLCDB[2];//物料光电3状态信号点位 |
| | | string wlgd4DB = item.RPLCDB[3];//物料光电4状态信号点位 |
| | | string tpgdDB = item.RPLCDB[4];//托盘光电状态信号点位 |
| | | string buttonDB = item.RPLCDB[5];//按钮状态信号点位 |
| | | |
| | | ////确认按钮(绿色) |
| | | OperateResult<bool> R_TBR_XT1 = ModbusPLCClient.ReadBool(buttonDB); |
| | | OperateResult<bool> R_TBR_XT2 = ModbusPLCClient.ReadBool(buttonDB); |
| | | WriteLog.GetLog().Write($"{item.HCJName}缓存架,连接{R_TBR_XT1.IsSuccess}{R_TBR_XT2.IsSuccess}", "卷绕缓存架"); |
| | | if (!R_TBR_XT1.IsSuccess && !R_TBR_XT2.IsSuccess) |
| | | { |
| | | //Console.WriteLine($"-{ModbusPLCClient.IpAddress}---{station.stationCode}----{ButtonEnsureDB}--------false--{R_TBR_XT.Message}----------------"); |
| | | location.location_state = LocationStateEnum.LocationState_Close.ToString(); |
| | | location.tpgd = -1; |
| | | location.update_time = DateTime.Now; |
| | | location.wireless_time = DateTime.Now; |
| | | var locationOff = freeDB.Update(location).UpdateColumns(t => new |
| | | { |
| | | t.location_state, |
| | | t.tpgd, |
| | | t.update_time, |
| | | t.wireless_time |
| | | }).ExecuteAffrows(); |
| | | continue; |
| | | } |
| | | OperateResult<bool> ButtonEnsure1 = ModbusPLCClient.ReadBool(buttonDB); |
| | | OperateResult<bool> ButtonEnsure2 = ModbusPLCClient.ReadBool(buttonDB); |
| | | //托盘光电状态 |
| | | OperateResult<bool> tpgdstate1 = ModbusPLCClient.ReadBool(tpgdDB); |
| | | OperateResult<bool> tpgdstate2 = ModbusPLCClient.ReadBool(tpgdDB); |
| | | //物料光电1状态 |
| | | OperateResult<bool> wlgd1state1 = ModbusPLCClient.ReadBool(wlgd1DB); |
| | | OperateResult<bool> wlgd1state2 = ModbusPLCClient.ReadBool(wlgd1DB); |
| | | //物料光电2状态 |
| | | OperateResult<bool> wlgd2state1 = ModbusPLCClient.ReadBool(wlgd2DB); |
| | | OperateResult<bool> wlgd2state2 = ModbusPLCClient.ReadBool(wlgd2DB); |
| | | //物料光电3状态 |
| | | OperateResult<bool> wlgd3state1 = ModbusPLCClient.ReadBool(wlgd3DB); |
| | | OperateResult<bool> wlgd3state2 = ModbusPLCClient.ReadBool(wlgd3DB); |
| | | //物料光电4状态 |
| | | OperateResult<bool> wlgd4state1 = ModbusPLCClient.ReadBool(wlgd4DB); |
| | | OperateResult<bool> wlgd4state2 = ModbusPLCClient.ReadBool(wlgd4DB); |
| | | //根据读到的PLC信息,轮询更新数据库信息 |
| | | location.update_time = DateTime.Now; |
| | | location.wireless_time = DateTime.Now; |
| | | if (ButtonEnsure1.IsSuccess) |
| | | { |
| | | location.logic_layer = ButtonEnsure1.Content ? "1" : "0"; |
| | | } |
| | | if (ButtonEnsure2.IsSuccess) |
| | | { |
| | | location.logic_layer = ButtonEnsure2.Content ? "1" : "0"; |
| | | } |
| | | if (tpgdstate1.IsSuccess) |
| | | { |
| | | location.tpgd = !tpgdstate1.Content ? 1 : 0; |
| | | } |
| | | if (tpgdstate2.IsSuccess) |
| | | { |
| | | location.tpgd = !tpgdstate2.Content ? 1 : 0; |
| | | } |
| | | #region 物料光电1 |
| | | if (wlgd1state1.IsSuccess) |
| | | { |
| | | location.gd1 = !wlgd1state1.Content ? 1 : 0; ; |
| | | } |
| | | if (wlgd1state2.IsSuccess) |
| | | { |
| | | location.gd1 = !wlgd1state2.Content ? 1 : 0; ; |
| | | } |
| | | #endregion |
| | | #region 物料光电2 |
| | | if (wlgd2state1.IsSuccess) |
| | | { |
| | | location.gd2 = !wlgd2state1.Content ? 1 : 0; ; |
| | | } |
| | | if (wlgd2state2.IsSuccess) |
| | | { |
| | | location.gd2 = !wlgd2state2.Content ? 1 : 0; ; |
| | | } |
| | | #endregion |
| | | #region 物料光电3 |
| | | if (wlgd3state1.IsSuccess) |
| | | { |
| | | location.gd3 = !wlgd3state1.Content ? 1 : 0; ; |
| | | } |
| | | if (wlgd3state2.IsSuccess) |
| | | { |
| | | location.gd3 = !wlgd3state2.Content ? 1 : 0; ; |
| | | } |
| | | #endregion |
| | | #region 物料光电4 |
| | | if (wlgd4state1.IsSuccess) |
| | | { |
| | | location.gd4 = !wlgd4state1.Content ? 1 : 0; ; |
| | | } |
| | | if (wlgd4state2.IsSuccess) |
| | | { |
| | | location.gd4 = !wlgd4state2.Content ? 1 : 0; ; |
| | | } |
| | | #endregion |
| | | string LampYellowDB = item.WPLCDB[0];//黄灯信号点位 |
| | | string LampGreenDB = item.WPLCDB[1];//绿灯信号点位 |
| | | string LampRedDB = item.WPLCDB[2];//红灯信号点位 |
| | | |
| | | //货架存在任务任务时 |
| | | if (location.tpgd == 1) |
| | | { |
| | | location.location_state = LocationStateEnum.LocationState_Stored.ToString(); |
| | | OperateResult<bool> Yellow1 = ModbusPLCClient.ReadBool(LampYellowDB); |
| | | OperateResult<bool> Yellow2 = ModbusPLCClient.ReadBool(LampYellowDB); |
| | | if (location.logic_col == 2) |
| | | { |
| | | ModbusPLCClient.Write(LampRedDB, true); //红灯 |
| | | ModbusPLCClient.Write(LampRedDB, true); //红灯 |
| | | } |
| | | if (location.task == 1 && (Yellow1.Content || Yellow2.Content)) |
| | | { |
| | | //ModbusPLCClient.Write(LampGreenDB, true); //绿灯 |
| | | //ModbusPLCClient.Write(LampGreenDB, true); //绿灯 |
| | | ModbusPLCClient.Write(LampYellowDB, false); //黄灯 |
| | | ModbusPLCClient.Write(LampYellowDB, false); //黄灯 |
| | | } |
| | | else if(location.task == 1 && (!Yellow1.Content || !Yellow2.Content)) |
| | | { |
| | | //ModbusPLCClient.Write(LampGreenDB, true); //绿灯 |
| | | //ModbusPLCClient.Write(LampGreenDB, true); //绿灯 |
| | | ModbusPLCClient.Write(LampYellowDB, true); //黄灯 |
| | | ModbusPLCClient.Write(LampYellowDB, true); //黄灯 |
| | | } |
| | | else |
| | | { |
| | | ModbusPLCClient.Write(LampYellowDB, true); //黄灯 |
| | | ModbusPLCClient.Write(LampYellowDB, true); //黄灯 |
| | | ModbusPLCClient.Write(LampGreenDB, false); //绿灯 |
| | | ModbusPLCClient.Write(LampGreenDB, false); //绿灯 |
| | | ModbusPLCClient.Write(LampRedDB, false); //红灯 |
| | | ModbusPLCClient.Write(LampRedDB, false); //红灯 |
| | | } |
| | | } |
| | | else |
| | | { |
| | | location.location_state = LocationStateEnum.LocationState_Empty.ToString(); |
| | | OperateResult<bool> Yellow1 = ModbusPLCClient.ReadBool(LampYellowDB); |
| | | OperateResult<bool> Yellow2 = ModbusPLCClient.ReadBool(LampYellowDB); |
| | | if (location.logic_col == 2) |
| | | { |
| | | ModbusPLCClient.Write(LampRedDB, true); //红灯 |
| | | ModbusPLCClient.Write(LampRedDB, true); //红灯 |
| | | } |
| | | |
| | | if (location.task == 1 && (Yellow1.Content || Yellow2.Content)) |
| | | { |
| | | ModbusPLCClient.Write(LampGreenDB, true); //绿灯 |
| | | ModbusPLCClient.Write(LampGreenDB, true); //绿灯 |
| | | ModbusPLCClient.Write(LampYellowDB, false); //黄灯 |
| | | ModbusPLCClient.Write(LampYellowDB, false); //黄灯 |
| | | } |
| | | else if (location.task == 1 && (!Yellow1.Content || !Yellow2.Content)) |
| | | { |
| | | ModbusPLCClient.Write(LampGreenDB, true); //绿灯 |
| | | ModbusPLCClient.Write(LampGreenDB, true); //绿灯 |
| | | ModbusPLCClient.Write(LampYellowDB, true); //黄灯 |
| | | ModbusPLCClient.Write(LampYellowDB, true); //黄灯 |
| | | } |
| | | else |
| | | { |
| | | ModbusPLCClient.Write(LampYellowDB, false); //黄灯 |
| | | ModbusPLCClient.Write(LampYellowDB, false); //黄灯 |
| | | ModbusPLCClient.Write(LampGreenDB, false); //绿灯 |
| | | ModbusPLCClient.Write(LampGreenDB, false); //绿灯 |
| | | ModbusPLCClient.Write(LampRedDB, false); //红灯 |
| | | ModbusPLCClient.Write(LampRedDB, false); //红灯 |
| | | } |
| | | } |
| | | |
| | | var executeAffrows = freeDB.Update(location).UpdateColumns(t => new |
| | | { |
| | | t.location_state, |
| | | t.logic_layer, |
| | | t.update_time, |
| | | t.wireless_time, |
| | | t.tpgd, |
| | | t.gd1, |
| | | t.gd2, |
| | | t.gd3, |
| | | t.gd4 |
| | | }).ExecuteAffrows(); |
| | | } |
| | | } |
| | | private void LKHCJdispatch() |
| | | { |