| | |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Reflection; |
| | | using System.Reflection.Emit; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using static HH.WCS.JuShi.device.S7Helper; |
| | |
| | | |
| | | // } |
| | | //} |
| | | |
| | | |
| | | //监测摄像头处货位(送检入库区)空满状态 满的就叉到立库 |
| | | public static void MonitorFullStatus() |
| | | { |
| | |
| | | |
| | | //找送检入库区内托盘满了的货位 |
| | | var locList = db.Queryable<Location>() |
| | | .Where(p => p.S_AREA_CODE == reservoirs.areaCode && p.N_LOCK_STATE == 0) |
| | | .Where(p => p.S_AREA_CODE == reservoirs.areaCode && p.N_LOCK_STATE == 0 && p.C_ENABLE == "Y") |
| | | .Where(s => locCntrs.Contains(s.S_CODE.Trim())) |
| | | .ToList(); |
| | | |
| | |
| | | var startLoc = locList.FirstOrDefault(); |
| | | var endLoc = TaskProcess.InWorkTransport(reservoirs2.areaCode); |
| | | LogHelper.Info($"任务摄像头监测找到终点货位:{JsonConvert.SerializeObject(endLoc)}"); |
| | | if (endLoc!=null) |
| | | if (endLoc != null) |
| | | { |
| | | var locCntrRel = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE == startLoc.S_CODE).First(); |
| | | LogHelper.Info($"任务摄像头监测找到托盘:{JsonConvert.SerializeObject(locCntrRel)}"); |
| | |
| | | var reservoirs2 = Settings.ReservoirAreas.Where(s => s.areaName == "6min空托区").FirstOrDefault(); |
| | | var linePlcInfo1 = Settings.linePlcInfos.Where(s => s.deviceNo == "1").FirstOrDefault(); |
| | | var linePlcInfo2 = Settings.linePlcInfos.Where(s => s.deviceNo == "2").FirstOrDefault(); |
| | | //找到空托缓存区的所有货位编号 |
| | | var locList = db.Queryable<Location>() |
| | | .Where(s => s.S_AREA_CODE == reservoirs1.areaCode || s.S_AREA_CODE == reservoirs2.areaCode) |
| | | .Where(s => s.N_LOCK_STATE == 0) |
| | | .OrderByDescending(s => s.N_ROW).OrderByDescending(s => s.N_COL).OrderBy(s => s.N_LAYER) |
| | | .Select(s => s.S_CODE) |
| | | .ToList(); |
| | | |
| | | //找到绑了托盘的货位号 |
| | | var locCntrs = db.Queryable<LocCntrRel>() |
| | | .Where(s => locList.Contains(s.S_LOC_CODE.Trim())) |
| | | .Select(s => s.S_LOC_CODE) |
| | | .ToList(); |
| | | if (locCntrs.Any()) |
| | | //查询每排最后一列有托盘的货位 根据行分区 再找每一行的最后一列有货的货位 |
| | | var list = db.Queryable<Location>(). |
| | | Where(a => a.N_CURRENT_NUM > 0).Where(a => a.S_AREA_CODE.Trim() == reservoirs1.areaCode || a.S_AREA_CODE.Trim() == reservoirs2.areaCode) |
| | | .PartitionBy(a => a.N_ROW) |
| | | .OrderByDescending(a => a.N_COL).Take(1).ToList(); |
| | | if (list.Count > 0) |
| | | { |
| | | //LogHelper.Info($"空托缓存区有绑定货位:{JsonConvert.SerializeObject(locCntrs)}"); |
| | | //var loccode = locCntrs.First(); |
| | | foreach (var loccode in locCntrs) |
| | | for (int i = 0; i < list.Count; i++) |
| | | { |
| | | var loc = db.Queryable<Location>().Where(s => s.S_CODE == loccode).First(); |
| | | //var loc = list[i]; |
| | | //判断送往3寸还是6寸拆托机 |
| | | string endLoc = null; |
| | | string dev = null; |
| | | if (loc.S_AREA_CODE == reservoirs1.areaCode) |
| | | if (list[i].S_AREA_CODE == reservoirs1.areaCode) |
| | | { |
| | | endLoc = linePlcInfo1.inLoca; |
| | | dev = "1"; |
| | | } |
| | | else if (loc.S_AREA_CODE == reservoirs2.areaCode) |
| | | else if (list[i].S_AREA_CODE == reservoirs2.areaCode) |
| | | { |
| | | endLoc = linePlcInfo2.inLoca; |
| | | dev = "2"; |
| | | } |
| | | var endLocation = db.Queryable<Location>().Where(s => s.S_CODE == endLoc).First(); |
| | | if (endLocation == null || endLocation.N_LOCK_STATE != 0) |
| | | if (endLocation == null || endLocation.N_LOCK_STATE != 0 || endLocation.C_ENABLE != "Y") |
| | | { |
| | | //LogHelper.Info($"拆托机货位{endLoc}不存在或已被锁"); |
| | | return; |
| | |
| | | if ((plcDeviceTable.requestPut1 && dev == "1") || |
| | | (plcDeviceTable.requestPut2 && dev == "2")) |
| | | { |
| | | var locCntrRel = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE == loccode).First(); |
| | | var locCntrRel = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE == list[i].S_CODE).First(); |
| | | |
| | | LogHelper.Info($"创建任务 起点:{loccode}终点:{endLoc}"); |
| | | var res = TaskProcess.CreateTransport(loccode, endLoc, "送托", locCntrRel.S_CNTR_CODE, 1, 1); |
| | | LogHelper.Info($"创建任务 起点:{list[i].S_CODE}终点:{endLoc}"); |
| | | var res = TaskProcess.CreateTransport(list[i].S_CODE, endLoc, "送托", locCntrRel.S_CNTR_CODE, 1, 1); |
| | | if (res) |
| | | { |
| | | LogHelper.Info($"起点:{loccode}终点:{endLoc}任务创建成功"); |
| | | LogHelper.Info($"起点:{list[i].S_CODE}终点:{endLoc}任务创建成功"); |
| | | } |
| | | else |
| | | { |
| | | LogHelper.Info($"起点:{loccode}终点:{endLoc}任务创建失败"); |
| | | LogHelper.Info($"起点:{list[i].S_CODE}终点:{endLoc}任务创建失败"); |
| | | } |
| | | } |
| | | else |
| | |
| | | LogHelper.Info($"拆托机{endLoc}不允许放框"); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | |
| | | |
| | | |
| | | } |
| | | //产线自动补空托 |
| | | public static void AutoRepairEmptyTray() |
| | | { |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | try |
| | | { |
| | | //查自动补托表 |
| | | var autoLists = db.Queryable<AutoRepairEmptyTray>().ToList(); |
| | | foreach (var autolist in autoLists) |
| | | { |
| | | //找起点 |
| | | var priorityLoc = Settings.PriorityLocs.Where(s => s.Name == autolist.S_LOC_CODE).FirstOrDefault(); |
| | | var startLoc = db.Queryable<Location>() |
| | | .Where(s => s.S_CODE == priorityLoc.Location).First(); |
| | | if (startLoc != null && startLoc.N_LOCK_STATE == 0 && startLoc.C_ENABLE == "Y") |
| | | { |
| | | var plcDeviceTable = S7Helper.plcDeviceTables; |
| | | //找终点 |
| | | if (autolist.S_TYPE == "三寸") |
| | | { |
| | | var linePlcInfo = Settings.linePlcInfos.Where(s => s.deviceNo == "1").FirstOrDefault(); |
| | | //校验是否允许放货 |
| | | var endLoc = db.Queryable<Location>() |
| | | .Where(s => s.S_CODE == linePlcInfo.outLoca).First(); |
| | | if (endLoc != null && endLoc.N_LOCK_STATE == 0 && endLoc.C_ENABLE == "Y") |
| | | { |
| | | if (plcDeviceTable.requestTake1) |
| | | { |
| | | var locCntrRel = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE == startLoc.S_CODE).First(); |
| | | |
| | | LogHelper.Info($"创建任务 起点:{startLoc.S_CODE}终点:{endLoc.S_CODE}"); |
| | | var res = TaskProcess.CreateTransport(startLoc.S_CODE, endLoc.S_CODE, "送托", locCntrRel.S_CNTR_CODE, 1, 1); |
| | | if (res) |
| | | { |
| | | LogHelper.Info($"起点:{startLoc.S_CODE}终点:{endLoc.S_CODE}任务创建成功"); |
| | | } |
| | | else |
| | | { |
| | | LogHelper.Info($"起点:{startLoc.S_CODE}终点:{endLoc.S_CODE}任务创建失败"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | else if (autolist.S_TYPE == "六寸") |
| | | { |
| | | var linePlcInfo = Settings.linePlcInfos.Where(s => s.deviceNo == "2").FirstOrDefault(); |
| | | //校验是否允许放货 |
| | | var endLoc = db.Queryable<Location>() |
| | | .Where(s => s.S_CODE == linePlcInfo.outLoca).First(); |
| | | if (endLoc != null && endLoc.N_LOCK_STATE == 0 && endLoc.C_ENABLE == "Y") |
| | | { |
| | | if (plcDeviceTable.requestTake2) |
| | | { |
| | | var locCntrRel = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE == startLoc.S_CODE).First(); |
| | | |
| | | LogHelper.Info($"创建任务 起点:{startLoc.S_CODE}终点:{endLoc.S_CODE}"); |
| | | var res = TaskProcess.CreateTransport(startLoc.S_CODE, endLoc.S_CODE, "送托", locCntrRel.S_CNTR_CODE, 1, 1); |
| | | if (res) |
| | | { |
| | | LogHelper.Info($"起点:{startLoc.S_CODE}终点:{endLoc.S_CODE}任务创建成功"); |
| | | } |
| | | else |
| | | { |
| | | LogHelper.Info($"起点:{startLoc.S_CODE}终点:{endLoc.S_CODE}任务创建失败"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Console.WriteLine("AutoRepairEmptyTray:" + ex.Message + ex.StackTrace); |
| | | LogHelper.Error("AutoRepairEmptyTray:" + ex.Message, ex); |
| | | throw; |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | } |
| | | } |