using HH.WCS.DaYang.device; using HH.WCS.DaYang.dispatch; using HH.WCS.DaYang.util; using HH.WCS.DaYang.wms; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Security.Policy; using System.Threading; using static HH.WCS.DaYang.api.ApiModel; using static HH.WCS.DaYang.util.Settings; namespace HH.WCS.DaYang.process { /// /// 设备信号处理,主要是tcp信号,我们做server被动接收信号来处理,根据项目定制的 /// internal class DeviceProcess { internal static void Analysis(string data, string ip) { if (data.Length >= 6) { //去掉消息头3F 00 data = data.Substring(4); //Console.WriteLine($"{ip}-{data}"); var plc = Settings.deviceInfos.Where(a => a.address == ip && a.enable == 1).FirstOrDefault(); if (plc != null) { if (plc.deviceType == 1) { } else if (plc.deviceType == 2) { //出库缓存位的光电信息 //如果有缓存位是空的状态,我们先判断有没有任务终点分配到这里,如果没有,就找一条出库任务,终点是虚拟点的任务,分配到这个空位 //修改任务终点 } } else { Console.WriteLine($"TCP信号处理:未查询到IP为{ip}的数据,请检查deviceInfo配置中心是否存在该IP的数据!"); } } } /// /// 自动门 /// /// /// /// private static Dictionary doorStatus = new Dictionary(); internal static void AnalysisDoor(string xh, string data, Settings.deviceInfo plc) { LogHelper.Info($"自动门状态:{xh},地址为:{plc.address},门号:{plc.deviceName}", "自动门"); if (data.Length / 2 == plc.deviceNo.Length)//2 2 { for (int i = 0; i < plc.deviceNo.Length; i++) { var state = data.Substring(i * 2 + 1, 1); //Console.WriteLine($"门{plc.DEVICENO[i]}的状态{state}"); if (doorStatus.Keys.Contains(plc.deviceNo[i])) { doorStatus[plc.deviceNo[i]].info = state; doorStatus[plc.deviceNo[i]].modify = DateTime.Now; } else { doorStatus.Add(plc.deviceNo[i], new signalInfo { info = state, modify = DateTime.Now }); } } } } public class signalInfo { public string info { get; set; } public DateTime modify { get; set; } } internal static void Traffic(string forkliftNo, string zone, bool occupy) { var plc = Settings.deviceInfos.Where(a => a.deviceNo.Contains(zone)).FirstOrDefault(); if (plc != null) { var index = 1; for (int i = 0; i < plc.deviceNo.Length; i++) { if (plc.deviceNo[i] == zone) { index = i + 1; break; } } LogHelper.Info($"安全门开门请求,门号:{zone},index:{index}"); if (occupy) { //开门请求 3F 00 11 20 0d 0a( 3F 00 10 21 0d 0a) var req = $"3f 00 {index}1 0d 0a"; PlcHelper.SendHex(plc.address, req); var msg = $"安全门开门请求,门号:{zone},index:{index},ip={plc.address}, data={req}"; LogHelper.Info(msg, "发送信号"); //车子请求一次就发一次开门请求 if (doorStatus.Keys.Contains(zone) && DateTime.Now.Subtract(doorStatus[zone].modify).TotalSeconds < 5) { if (doorStatus[zone].info == "1") { LogHelper.Info($"安全门已经打开:门号:{zone},index:{index}", "自动门"); NDCHelper.Traffic(zone, forkliftNo); } } } else { //关门信号 3F 00 10 20 0d 0a var req = $"3f 00 {index}0 0d 0a"; PlcHelper.SendHex(plc.address, req); var msg = $"安全门关门请求,门号:{zone},index:{index},ip={plc.address}, data={req}"; LogHelper.Info(msg, "发送信号"); } } } /// /// 叠盘机补空托 /// internal static void DijStatus() { var db = new SqlHelper().GetInstance(); HttpHelper httpHelper = new HttpHelper(); TableUrl tableUrl = Settings.tableUrls.Find(a => a.id == 3); string DiePanLoc = "CPDPJ-1-1"; Location startloc = null; if (tableUrl != null) { Result DeviceStatu = httpHelper.GetDeviceStatus(new string[] { DiePanLoc }, tableUrl.url); if (DeviceStatu.Data != null) { if (int.Parse(DeviceStatu.Data.CntrQty) > 0 && int.Parse(DeviceStatu.Data.CntrQty) < 4) { startloc = LocationHelper.GetLocByItemCodeOrderyTime("YCLLKQ", ""); } else { startloc = db.Queryable().Where(a => a.N_CURRENT_NUM == 4).OrderByDescending(a => a.N_POS).First(); } //根据托盘获取起点信息 var endloc = db.Queryable().Where(a => a.S_CODE == DiePanLoc).First(); if (endloc == null) { return; } #region 创建任务 if (startloc != null && endloc != null) { //获取托盘 var Cntr = db.Queryable().Where(a => a.S_LOC_CODE.Trim() == startloc.S_CODE).ToList(); if (Cntr == null) { return; } var wcsTask = new WMSTask { S_CODE = WMSHelper.GenerateTaskNo(), S_TYPE = "空托出库", N_TYPE = 3, S_START_LOC = startloc.S_CODE, S_END_LOC = endloc.S_CODE, S_START_WH = startloc.S_WH_CODE, S_START_AREA = startloc.S_AREA_CODE, S_END_WH = endloc.S_WH_CODE, S_END_AREA = endloc.S_AREA_CODE, S_CNTR_CODE = JsonConvert.SerializeObject(Cntr.Select(a => a.S_CNTR_CODE).ToList()) }; LogHelper.Info("创建入平库任务:" + JsonConvert.SerializeObject(wcsTask)); if (WMSHelper.CreateTask(wcsTask)) { LocationHelper.LockLoc(startloc.S_CODE, 2); LocationHelper.LockLoc(endloc.S_CODE, 1); LogHelper.Info("创建任务成功"); } #endregion } } } } } }