using System; using System.Collections.Generic; using System.Linq; namespace CMS_CORE_Library.Models { public class ThermoModels { #region Protected Fields protected const double EPSILON = 0.1; #endregion Protected Fields #region Public Classes /// /// Single AXIS Info Data /// public class AxisInfo { #region Public Properties //public int ControlWord { get; set; } = 0; public int ErrorCode { get; set; } = 0; public int Id { get; set; } = 0; public int MovPhase { get; set; } = 0; public int StatusWord { get; set; } = 0; //public double TargetPos { get; set; } = 0; /// /// Deserializzazione da byte ad oggetto AxisRT /// /// public AxisInfo(int currId, byte[] rawData) { // converto i dati da byte grezzi ai componenti... Id = currId; ErrorCode = S7.Net.Types.DInt.FromByteArray(rawData.Skip(0).Take(4).ToArray()); MovPhase = S7.Net.Types.Word.FromByteArray(rawData.Skip(4).Take(2).ToArray()); StatusWord = S7.Net.Types.Word.FromByteArray(rawData.Skip(6).Take(2).ToArray()); } #endregion Public Properties #region Public Methods public override bool Equals(object obj) { // Object is not a GaugeModel instance if (!(obj is AxisInfo item)) return false; if (Id != item.Id) return false; if (ErrorCode != item.ErrorCode) return false; if (MovPhase != item.MovPhase) return false; if (StatusWord != item.StatusWord) return false; //if (ControlWord != item.ControlWord) // return false; //if (TargetPos != item.TargetPos) // return false; return true; } public override int GetHashCode() { return base.GetHashCode(); } #endregion Public Methods } /// /// Single AXIS RealTime (positions / movement) Data /// public class AxisRT { #region Public Constructors /// /// Deserializzazione da byte ad oggetto AxisRT /// /// public AxisRT(int currId, byte[] rawData) { // converto i dati da byte grezzi ai 3 componenti... Id = currId; Position = S7.Net.Types.Double.FromByteArray(rawData.Skip(0).Take(4).ToArray()); Speed = S7.Net.Types.Double.FromByteArray(rawData.Skip(4).Take(4).ToArray()); Load = S7.Net.Types.Double.FromByteArray(rawData.Skip(8).Take(4).ToArray()); } #endregion Public Constructors #region Public Properties public int Id { get; set; } = 0; public double Load { get; set; } = 0; public double Position { get; set; } = 0; public double Speed { get; set; } = 0; #endregion Public Properties #region Public Methods /// /// Converte un singolo item in un array di byte per scrittura su PLC S7 /// /// public byte[] convertToByte() { byte[] answ = new byte[12]; Buffer.BlockCopy(S7.Net.Types.Double.ToByteArray(Position), 0, answ, 0, 4); Buffer.BlockCopy(S7.Net.Types.Double.ToByteArray(Speed), 0, answ, 4, 4); Buffer.BlockCopy(S7.Net.Types.Double.ToByteArray(Load), 0, answ, 8, 4); return answ; } public override bool Equals(object obj) { // Object is not a GaugeModel instance if (!(obj is AxisRT item)) return false; if (Id != item.Id) return false; if (Position != item.Position) return false; if (Speed != item.Speed) return false; if (Load != item.Load) return false; return true; } public override int GetHashCode() { return base.GetHashCode(); } #endregion Public Methods } /// /// Represent IO Channel FORCED by UI /// public class ChanIOFor { #region Public Properties public Dictionary AO { get; set; } = new Dictionary(); public Dictionary DO { get; set; } = new Dictionary(); #endregion Public Properties #region Public Methods public override bool Equals(object obj) { if (!(obj is ChanIOVis item)) return false; if (!DO.Equals(item.DO)) return false; if (!AO.Equals(item.AO)) return false; return true; } public override int GetHashCode() { return base.GetHashCode(); } #endregion Public Methods } /// /// Represent IO Channel Values /// public class ChanIOVal { #region Public Properties public Dictionary AI { get; set; } = new Dictionary(); public Dictionary AO { get; set; } = new Dictionary(); public Dictionary DI { get; set; } = new Dictionary(); public Dictionary DO { get; set; } = new Dictionary(); #endregion Public Properties #region Public Methods public override bool Equals(object obj) { if (!(obj is ChanIOVal item)) return false; if (!DI.Equals(item.DI)) return false; if (!DO.Equals(item.DO)) return false; if (!AI.Equals(item.AI)) return false; if (!AO.Equals(item.AO)) return false; return true; } public override int GetHashCode() { return base.GetHashCode(); } #endregion Public Methods } /// /// Represent IO Channel FORCED values /// public class ChanIOValFor { #region Public Properties public Dictionary AO { get; set; } = new Dictionary(); public Dictionary DO { get; set; } = new Dictionary(); #endregion Public Properties #region Public Methods public override bool Equals(object obj) { if (!(obj is ChanIOVal item)) return false; if (!DO.Equals(item.DO)) return false; if (!AO.Equals(item.AO)) return false; return true; } public override int GetHashCode() { return base.GetHashCode(); } #endregion Public Methods } /// /// Represent IO Channel visibility /// public class ChanIOVis { #region Public Properties public Dictionary AI { get; set; } = new Dictionary(); public Dictionary AO { get; set; } = new Dictionary(); public Dictionary DI { get; set; } = new Dictionary(); public Dictionary DO { get; set; } = new Dictionary(); #endregion Public Properties #region Public Methods public override bool Equals(object obj) { if (!(obj is ChanIOVis item)) return false; if (!DI.Equals(item.DI)) return false; if (!DO.Equals(item.DO)) return false; if (!AI.Equals(item.AI)) return false; if (!AO.Equals(item.AO)) return false; return true; } public override int GetHashCode() { return base.GetHashCode(); } #endregion Public Methods } /// /// Represents thermo LIVE prod data (gauge, time adv...) /// public class LiveProdDataModel { #region Public Properties public double Air { get; set; } = 0; public double Power { get; set; } = 0; public double TimeAdv { get; set; } = 0; public double Vacuum { get; set; } = 0; #endregion Public Properties #region Public Methods public override bool Equals(object obj) { // Object is not a GaugeModel instance if (!(obj is LiveProdDataModel item)) return false; if (TimeAdv != item.TimeAdv) return false; if (Power != item.Power) return false; if (Vacuum != item.Vacuum) return false; if (Air != item.Air) return false; return true; } public override int GetHashCode() { return base.GetHashCode(); } #endregion Public Methods } public class LogCycleData { #region Public Constructors /// /// Deserializzazione da byte ad oggetto LogCycleData /// /// public LogCycleData(byte[] rawData) { // converto i dati da byte grezzi ai 3 componenti... year = S7.Net.Types.Word.FromByteArray(rawData.Skip(0).Take(2).ToArray()); month = S7.Net.Types.Byte.FromByteArray(rawData.Skip(2).Take(1).ToArray()); day = S7.Net.Types.Byte.FromByteArray(rawData.Skip(3).Take(1).ToArray()); hour = S7.Net.Types.Byte.FromByteArray(rawData.Skip(4).Take(1).ToArray()); min = S7.Net.Types.Byte.FromByteArray(rawData.Skip(5).Take(1).ToArray()); msec = S7.Net.Types.Word.FromByteArray(rawData.Skip(6).Take(2).ToArray()); Code = S7.Net.Types.Word.FromByteArray(rawData.Skip(8).Take(2).ToArray()); } #endregion Public Constructors #region Public Properties protected int year { get; set; } = 0; protected int month { get; set; } = 0; protected int day { get; set; } = 0; protected int hour { get; set; } = 0; protected int min { get; set; } = 0; protected int msec { get; set; } = 0; public DateTime DtEvent { get { DateTime answ = DateTime.Now; try { new DateTime(year, month, day); answ = answ.AddHours(hour).AddMinutes(min).AddMilliseconds(msec); } catch { } return answ; } } public int Code { get; set; } = 0; #endregion Public Properties #region Public Methods public override bool Equals(object obj) { // Object is not a GaugeModel instance if (!(obj is LogCycleData item)) return false; if (DtEvent != item.DtEvent) return false; if (Code != item.Code) return false; return true; } public override int GetHashCode() { return base.GetHashCode(); } #endregion Public Methods } public class ModuleBlock { #region Public Properties public int ActualDelay { get; set; } = 0; public int ActualDuration { get; set; } = 0; public int EstimatedDelay { get; set; } = 0; public int EstimatedDuration { get; set; } = 0; public bool HasError { get; set; } = false; public short Id { get; set; } = 0; public List PrecedingId { get; set; } = new List(); public bool Running { get; set; } = false; public bool Terminated { get; set; } = false; public bool Visible { get; set; } = false; #endregion Public Properties #region Public Methods public override bool Equals(object obj) { // Object is not a GaugeModel instance if (!(obj is ModuleBlock item)) return false; if (Id != item.Id) return false; if (ActualDelay != item.ActualDelay) return false; if (ActualDuration != item.ActualDuration) return false; if (EstimatedDelay != item.EstimatedDelay) return false; if (EstimatedDuration != item.EstimatedDuration) return false; if (!PrecedingId.Equals(PrecedingId)) return false; if (Visible != item.Visible) return false; if (Running != item.Running) return false; if (HasError != item.HasError) return false; if (Terminated != item.Terminated) return false; return true; } public override int GetHashCode() { return base.GetHashCode(); } #endregion Public Methods } public class ProdCycleModel { #region Public Properties public ushort MessageId { get; set; } = 0; public ushort Mode { get; set; } = 0; public ushort Status { get; set; } = 0; public ushort Submode { get; set; } = 0; public uint TimeAdv { get; set; } = 0; #endregion Public Properties #region Public Methods public override bool Equals(object obj) { // Object is not a GaugeModel instance if (!(obj is ProdCycleModel item)) return false; if (Status != item.Status) return false; if (MessageId != item.MessageId) return false; if (Mode != item.Mode) return false; if (Submode != item.Submode) return false; if (TimeAdv != item.TimeAdv) return false; return true; } public override int GetHashCode() { return base.GetHashCode(); } #endregion Public Methods } public class ProdInfoModel { #region Public Properties public DateTime DtEvent { get; set; } = DateTime.Now; public bool IsScrap { get; set; } = false; public float MaterialTempEndVent { get; set; } = 0; public float MaterialTempEndWarm { get; set; } = 0; public float MoldTemp { get; set; } = 0; public float MouldEnergyIN { get; set; } = 0; public float MouldEnergyOUT { get; set; } = 0; public short NumDone { get; set; } = 0; public short NumPreHot { get; set; } = 0; public short NumTarget { get; set; } = 0; public short PreWarmCycle { get; set; } = 0; public string ThermoImage { get; set; } = ""; public int TimeCycleGross { get; set; } = 0; public int TimeCycleNet { get; set; } = 0; public int TimeVacuum { get; set; } = 0; public int TimeVent { get; set; } = 0; public int TimeWarm { get; set; } = 0; public float VacuumReadVal { get; set; } = 0; #endregion Public Properties #region Public Methods /// /// Converte un singolo item in un array di byte per scrittura su PLC S7 /// /// public byte[] convertToByte() { byte[] answ = new byte[50]; Buffer.BlockCopy(S7.Net.Types.Int.ToByteArray(NumTarget), 0, answ, 0, 2); Buffer.BlockCopy(S7.Net.Types.Int.ToByteArray(NumDone), 0, answ, 2, 2); Buffer.BlockCopy(S7.Net.Types.Int.ToByteArray(PreWarmCycle), 0, answ, 4, 2); Buffer.BlockCopy(S7.Net.Types.DInt.ToByteArray(TimeWarm), 0, answ, 6, 4); Buffer.BlockCopy(S7.Net.Types.DInt.ToByteArray(TimeVent), 0, answ, 10, 4); Buffer.BlockCopy(S7.Net.Types.DInt.ToByteArray(TimeVacuum), 0, answ, 14, 4); Buffer.BlockCopy(S7.Net.Types.DInt.ToByteArray(TimeCycleGross), 0, answ, 18, 4); Buffer.BlockCopy(S7.Net.Types.DInt.ToByteArray(TimeCycleNet), 0, answ, 22, 4); Buffer.BlockCopy(S7.Net.Types.Real.ToByteArray(MaterialTempEndWarm), 0, answ, 26, 4); Buffer.BlockCopy(S7.Net.Types.Real.ToByteArray(MaterialTempEndVent), 0, answ, 30, 4); Buffer.BlockCopy(S7.Net.Types.Real.ToByteArray(MoldTemp), 0, answ, 34, 4); Buffer.BlockCopy(S7.Net.Types.Real.ToByteArray(VacuumReadVal), 0, answ, 38, 4); Buffer.BlockCopy(S7.Net.Types.Real.ToByteArray(MouldEnergyOUT), 0, answ, 42, 4); Buffer.BlockCopy(S7.Net.Types.Real.ToByteArray(MouldEnergyIN), 0, answ, 46, 4); return answ; } public override bool Equals(object obj) { // Object is not a GaugeModel instance if (!(obj is ProdInfoModel item)) return false; if (DtEvent != item.DtEvent) return false; if (NumTarget != item.NumTarget) return false; if (NumDone != item.NumDone) return false; if (PreWarmCycle != item.PreWarmCycle) return false; if (ThermoImage != item.ThermoImage) return false; if (TimeWarm != item.TimeWarm) return false; if (TimeVent != item.TimeVent) return false; if (TimeVacuum != item.TimeVacuum) return false; if (TimeCycleGross != item.TimeCycleGross) return false; if (TimeCycleNet != item.TimeCycleNet) return false; if (Math.Round(Math.Abs(MaterialTempEndWarm - item.MaterialTempEndWarm), 1) >= EPSILON) return false; if (Math.Round(Math.Abs(MaterialTempEndVent - item.MaterialTempEndVent), 1) >= EPSILON) return false; if (Math.Round(Math.Abs(MoldTemp - item.MoldTemp), 1) >= EPSILON) return false; if (Math.Round(Math.Abs(VacuumReadVal - item.VacuumReadVal), 1) >= EPSILON) return false; if (Math.Round(Math.Abs(MouldEnergyOUT - item.MouldEnergyOUT), 1) >= EPSILON) return false; if (Math.Round(Math.Abs(MouldEnergyIN - item.MouldEnergyIN), 1) >= EPSILON) return false; if (IsScrap != item.IsScrap) return false; if (NumPreHot != item.NumPreHot) return false; return true; } public override int GetHashCode() { return base.GetHashCode(); } #endregion Public Methods } /// /// Recipe Parameters /// public class RecipeParam { #region Public Properties public bool Enabled { get; set; } = false; public bool HasError { get; set; } = false; public short Id { get; set; } = 0; public int ScaleFactor { get; set; } = 1; public double SetpointHMI { get; set; } = 0; public double SetpointPLC { get; set; } = 0; public ushort UnitMeasure { get; set; } = 0; public double ValMax { get; set; } = 0; public double ValMin { get; set; } = 0; public double ValueAct { get; set; } = 0; public bool Visible { get; set; } = false; #endregion Public Properties #region Public Methods public override bool Equals(object obj) { // Object is not a GaugeModel instance if (!(obj is RecipeParam item)) return false; if (Id != item.Id) return false; if (SetpointHMI != item.SetpointHMI) return false; if (SetpointPLC != item.SetpointPLC) return false; if (ValMax != item.ValMax) return false; if (ValMin != item.ValMin) return false; if (UnitMeasure != item.UnitMeasure) return false; if (Visible != item.Visible) return false; if (Enabled != item.Enabled) return false; if (HasError != item.HasError) return false; if (ValueAct != item.ValueAct) return false; if (ScaleFactor != item.ScaleFactor) return false; return true; } public override int GetHashCode() { return base.GetHashCode(); } #endregion Public Methods } /// /// ThermoCam management data /// public class ThermoCam { #region Public Properties /// /// Modalità ThermoCamera (set by HMI) /// public bool ThermoCamMode { get; set; } = false; /// /// Funzionamento ThermoCamera (set by HMI) /// public bool ThermoCamOnOff { get; set; } = false; /// /// Opzione ThermoCamera (set by PLC) /// public bool ThermoOptionActive { get; set; } = false; #endregion Public Properties } /// /// Warmers channel data /// public class WarmerChannel { #region Public Properties /// /// Channel status /// public byte ChStatus { get; set; } = 0; /// /// Channel AMPERE actual value /// public double CurrAct { get; set; } = 0; /// /// Channel Unique ID (from risk2007) /// public int IdChannel { get; set; } = 0; /// /// Reflector ID /// public byte IdRefl { get; set; } = 0; /// /// Channel MaxPower /// public int MaxPower { get; set; } = 0; /// /// Channel actual value % /// public byte PercAct { get; set; } = 0; /// /// Setpoint from HMI (%) /// public byte SetpointHMI { get; set; } = 0; /// /// Setpoint from PLC (%) /// public byte SetpointPLC { get; set; } = 0; /// /// Define if camera is active for channel /// public bool TCamActive { get; set; } = false; /// /// Actual value from last ThermoCam image acquisition (1/10 ° Celsius) /// public short TCamTempActual { get; set; } = 0; /// /// Setpoint from HMI (1/10 ° Celsius) /// public short TCamTempSet { get; set; } = 0; #endregion Public Properties #region Public Methods /// /// Equality test for class object /// /// /// public override bool Equals(object obj) { // Object is not a GaugeModel instance if (!(obj is WarmerChannel item)) return false; if (ChStatus != item.ChStatus) return false; if (CurrAct != item.CurrAct) return false; if (IdChannel != item.IdChannel) return false; if (PercAct != item.PercAct) return false; if (SetpointHMI != item.SetpointHMI) return false; if (SetpointPLC != item.SetpointPLC) return false; if (TCamActive != item.TCamActive) return false; if (TCamTempActual != item.TCamTempActual) return false; if (TCamTempSet != item.TCamTempSet) return false; return true; } /// /// Hash gen /// /// public override int GetHashCode() { return base.GetHashCode(); } #endregion Public Methods } #endregion Public Classes } }