Files
Samuele E. Locatelli 0753e7b952 fix elttura assi (INFO)
2021-03-02 12:57:45 +01:00

823 lines
27 KiB
C#

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
/// <summary>
/// Single AXIS Info Data
/// </summary>
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;
/// <summary>
/// Deserializzazione da byte ad oggetto AxisRT
/// </summary>
/// <param name="rawData"></param>
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
}
/// <summary>
/// Single AXIS RealTime (positions / movement) Data
/// </summary>
public class AxisRT
{
#region Public Constructors
/// <summary>
/// Deserializzazione da byte ad oggetto AxisRT
/// </summary>
/// <param name="rawData"></param>
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
/// <summary>
/// Converte un singolo item in un array di byte per scrittura su PLC S7
/// </summary>
/// <returns></returns>
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
}
/// <summary>
/// Represent IO Channel FORCED by UI
/// </summary>
public class ChanIOFor
{
#region Public Properties
public Dictionary<int, bool> AO { get; set; } = new Dictionary<int, bool>();
public Dictionary<int, bool> DO { get; set; } = new Dictionary<int, bool>();
#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
}
/// <summary>
/// Represent IO Channel Values
/// </summary>
public class ChanIOVal
{
#region Public Properties
public Dictionary<int, int> AI { get; set; } = new Dictionary<int, int>();
public Dictionary<int, int> AO { get; set; } = new Dictionary<int, int>();
public Dictionary<int, bool> DI { get; set; } = new Dictionary<int, bool>();
public Dictionary<int, bool> DO { get; set; } = new Dictionary<int, bool>();
#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
}
/// <summary>
/// Represent IO Channel FORCED values
/// </summary>
public class ChanIOValFor
{
#region Public Properties
public Dictionary<int, int> AO { get; set; } = new Dictionary<int, int>();
public Dictionary<int, bool> DO { get; set; } = new Dictionary<int, bool>();
#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
}
/// <summary>
/// Represent IO Channel visibility
/// </summary>
public class ChanIOVis
{
#region Public Properties
public Dictionary<int, bool> AI { get; set; } = new Dictionary<int, bool>();
public Dictionary<int, bool> AO { get; set; } = new Dictionary<int, bool>();
public Dictionary<int, bool> DI { get; set; } = new Dictionary<int, bool>();
public Dictionary<int, bool> DO { get; set; } = new Dictionary<int, bool>();
#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
}
/// <summary>
/// Represents thermo LIVE prod data (gauge, time adv...)
/// </summary>
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
/// <summary>
/// Deserializzazione da byte ad oggetto LogCycleData
/// </summary>
/// <param name="rawData"></param>
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<short> PrecedingId { get; set; } = new List<short>();
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
/// <summary>
/// Converte un singolo item in un array di byte per scrittura su PLC S7
/// </summary>
/// <returns></returns>
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
}
/// <summary>
/// Recipe Parameters
/// </summary>
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
}
/// <summary>
/// ThermoCam management data
/// </summary>
public class ThermoCam
{
#region Public Properties
/// <summary>
/// Modalità ThermoCamera (set by HMI)
/// </summary>
public bool ThermoCamMode { get; set; } = false;
/// <summary>
/// Funzionamento ThermoCamera (set by HMI)
/// </summary>
public bool ThermoCamOnOff { get; set; } = false;
/// <summary>
/// Opzione ThermoCamera (set by PLC)
/// </summary>
public bool ThermoOptionActive { get; set; } = false;
#endregion Public Properties
}
/// <summary>
/// Warmers channel data
/// </summary>
public class WarmerChannel
{
#region Public Properties
/// <summary>
/// Channel status
/// </summary>
public byte ChStatus { get; set; } = 0;
/// <summary>
/// Channel AMPERE actual value
/// </summary>
public double CurrAct { get; set; } = 0;
/// <summary>
/// Channel Unique ID (from risk2007)
/// </summary>
public int IdChannel { get; set; } = 0;
/// <summary>
/// Reflector ID
/// </summary>
public byte IdRefl { get; set; } = 0;
/// <summary>
/// Channel MaxPower
/// </summary>
public int MaxPower { get; set; } = 0;
/// <summary>
/// Channel actual value %
/// </summary>
public byte PercAct { get; set; } = 0;
/// <summary>
/// Setpoint from HMI (%)
/// </summary>
public byte SetpointHMI { get; set; } = 0;
/// <summary>
/// Setpoint from PLC (%)
/// </summary>
public byte SetpointPLC { get; set; } = 0;
/// <summary>
/// Define if camera is active for channel
/// </summary>
public bool TCamActive { get; set; } = false;
/// <summary>
/// Actual value from last ThermoCam image acquisition (1/10 ° Celsius)
/// </summary>
public short TCamTempActual { get; set; } = 0;
/// <summary>
/// Setpoint from HMI (1/10 ° Celsius)
/// </summary>
public short TCamTempSet { get; set; } = 0;
#endregion Public Properties
#region Public Methods
/// <summary>
/// Equality test for class object
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
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;
}
/// <summary>
/// Hash gen
/// </summary>
/// <returns></returns>
public override int GetHashCode()
{
return base.GetHashCode();
}
#endregion Public Methods
}
#endregion Public Classes
}
}