using BPA.Utility; using HBLConsole.Service; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using static HBLDevice.IceCream.MessageDefine; namespace HBLDevice.IceCream { public class MorkIStatus : Singleton { private DateTime lastRefreshTime = DateTime.MinValue; /// /// 是否在线 /// public bool OnLine { get { return DateTime.Now.Subtract(lastRefreshTime).TotalSeconds <= 3; } } /// /// 预冷温度 /// public short YLWD { get; set; } /// /// 回气温度 /// public short HQWD { get; set; } /// /// 环境温度 /// public short HJWD { get; set; } /// /// 电流 /// public short DL { get; set; } /// /// 电压 /// public short DY { get; set; } /// /// 当前模式 /// public MORKI_MODE CurrentMode { get; set; } /// /// 故障 /// public MORKI_FAULT Fault { get; set; } /// /// 成型比 /// public byte CXB { get; set; } /// /// 成型比(门限) /// public byte CXB_Threshold { get; set; } /// /// 打料完成(完成为true,正在打料为false) /// public bool DLCompleted { get; set; } public bool CanDo { get { if (!OnLine) return false; if (Fault != MORKI_FAULT.未发生故障) return false; if (CXB < CXB_Threshold) return false; return true; } } private void ProcessHeart(ICMSG_Heart_UP heartUpMsg) { CurrentMode = heartUpMsg.MS; YLWD = BitConverter.ToInt16(new byte[] { heartUpMsg.YLWD_L, heartUpMsg.YLWD_H }, 0); HQWD = BitConverter.ToInt16(new byte[] { heartUpMsg.HQWD_L, heartUpMsg.HQWD_H }, 0); HJWD = BitConverter.ToInt16(new byte[] { heartUpMsg.HJWD_L, heartUpMsg.HJWD_H }, 0); DL = BitConverter.ToInt16(new byte[] { heartUpMsg.DL_L, heartUpMsg.DL_H }, 0); Fault = (MORKI_FAULT)BitConverter.ToInt16(new byte[] { heartUpMsg.GZ_L, heartUpMsg.GZ_H }, 0); CXB = heartUpMsg.CXB; DLCompleted = (heartUpMsg.DLTJ >> 4 & 1) == 1; if (RTrig.GetInstance("打料完成检测").Start(DLCompleted)) { MessageLog.GetInstance.Show("打料完成"); } if(RTrig.GetInstance("打料中检测").Start(!DLCompleted)) { MessageLog.GetInstance.Show("打料中"); } //MessageLog.GetInstance.Show(string.Format("当前模式为:{0}", CurrentMode)); } private void ProcessModeUp(ICMSG_MODE_UP modeUpMsg) { MessageLog.GetInstance.Show(string.Format("模式返回为:{0}", modeUpMsg.Mode)); } public void ProcessMsg(byte[] data) { lastRefreshTime = DateTime.Now; try { if (data.Length < 5) return; switch (data[2]) { case (byte)IC_CMD.HEART: var msg = IcPack.ByteToStructure(data.ToArray()); ProcessHeart(msg); break; case (byte)IC_CMD.MODE: var modeUp = IcPack.ByteToStructure(data.ToArray()); ProcessModeUp(modeUp); break; } } catch (Exception ex) { } } } }