Added RT Module read method
This commit is contained in:
@@ -626,11 +626,11 @@ namespace CMS_CORE_Library.Models
|
||||
|
||||
public class ModuleBlock
|
||||
{
|
||||
public ushort Id { get; set; } = 0;
|
||||
public uint ActualDelay { get; set; } = 0;
|
||||
public uint ActualDuration { get; set; } = 0;
|
||||
public uint EstimatedDelay { get; set; } = 0;
|
||||
public uint EstimatedDuration { get; set; } = 0;
|
||||
public short Id { get; set; } = 0;
|
||||
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 List<ushort> PrecedingId { get; set; } = new List<ushort>();
|
||||
public bool Visible { get; set; } = false;
|
||||
public bool Running { get; set; } = false;
|
||||
|
||||
@@ -620,16 +620,6 @@ namespace CMS_CORE_Library
|
||||
|
||||
#region THERMO high level data
|
||||
|
||||
///
|
||||
/// <summary>
|
||||
/// Read power gauge data
|
||||
/// <para>
|
||||
/// Compatibility: S7Net
|
||||
/// </para>
|
||||
/// <returns cref="CmsError">Returns an error when an internal or a library error occours</returns>
|
||||
/// </summary>
|
||||
/// <param name="gaugeData">Reference to the value of the gauge data</param>
|
||||
public abstract CmsError PLC_RGaugeData(ref GaugeModel gaugeData);
|
||||
/// <summary>
|
||||
/// Get current recipe parameter list
|
||||
/// </summary>
|
||||
@@ -657,6 +647,15 @@ namespace CMS_CORE_Library
|
||||
/// <returns></returns>
|
||||
public abstract CmsError PLC_RWarmerChannelList(ref Dictionary<int, ModuleBlock> currWarmerChannelList);
|
||||
/// <summary>
|
||||
/// Read power gauge data
|
||||
/// <para>
|
||||
/// Compatibility: S7Net
|
||||
/// </para>
|
||||
/// <returns cref="CmsError">Returns an error when an internal or a library error occours</returns>
|
||||
/// </summary>
|
||||
/// <param name="gaugeData">Reference to the value of the gauge data</param>
|
||||
public abstract CmsError PLC_RGaugeData(ref GaugeModel gaugeData);
|
||||
/// <summary>
|
||||
/// Get current Production Info data
|
||||
/// </summary>
|
||||
/// <param name="currProdInfo"></param>
|
||||
|
||||
@@ -1805,29 +1805,6 @@ namespace CMS_CORE_Library.S7Net
|
||||
|
||||
#region THERMO high level data
|
||||
|
||||
/// <summary>
|
||||
/// Get gauge data
|
||||
/// </summary>
|
||||
/// <param name="gaugeData"></param>
|
||||
/// <returns></returns>
|
||||
public override CmsError PLC_RGaugeData(ref GaugeModel gaugeData)
|
||||
{
|
||||
List<int> Values = new List<int>();
|
||||
CmsError cmsError = MEM_RWIntegerList(R, 1, MACHINE_GAUGE_DATA.MemType, MACHINE_GAUGE_DATA.Address, MACHINE_GAUGE_DATA.SubAddress, MACHINE_GAUGE_DATA.Size / 4, ref Values);
|
||||
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
gaugeData = new GaugeModel()
|
||||
{
|
||||
TimeAdv = Convert.ToUInt32(Values[0]),
|
||||
Power = Values[1],
|
||||
Vacuum = Values[2],
|
||||
Air = Values[3],
|
||||
};
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
/// <summary>
|
||||
/// read current recipe parameter list
|
||||
/// </summary>
|
||||
@@ -1884,6 +1861,16 @@ namespace CMS_CORE_Library.S7Net
|
||||
/// <returns></returns>
|
||||
public override CmsError PLC_RModulesBlockList(bool onlyRT, ref Dictionary<int, ModuleBlock> currModulesBlockList)
|
||||
{
|
||||
// se richiesto NON SOLO RT faccio refresh anche dati "lenti"
|
||||
if (!onlyRT)
|
||||
{
|
||||
refreshMemModBlockParameter();
|
||||
}
|
||||
// refresh dati veloci / RT
|
||||
refreshMemModBlockParameterRT();
|
||||
|
||||
// copio lista act in output...
|
||||
currModulesBlockList = ThermoModuleList;
|
||||
return NO_ERROR;
|
||||
}
|
||||
/// <summary>
|
||||
@@ -1896,6 +1883,29 @@ namespace CMS_CORE_Library.S7Net
|
||||
return NO_ERROR;
|
||||
}
|
||||
/// <summary>
|
||||
/// Get gauge data
|
||||
/// </summary>
|
||||
/// <param name="gaugeData"></param>
|
||||
/// <returns></returns>
|
||||
public override CmsError PLC_RGaugeData(ref GaugeModel gaugeData)
|
||||
{
|
||||
List<int> Values = new List<int>();
|
||||
CmsError cmsError = MEM_RWIntegerList(R, 1, MACHINE_GAUGE_DATA.MemType, MACHINE_GAUGE_DATA.Address, MACHINE_GAUGE_DATA.SubAddress, MACHINE_GAUGE_DATA.Size / 4, ref Values);
|
||||
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
gaugeData = new GaugeModel()
|
||||
{
|
||||
TimeAdv = Convert.ToUInt32(Values[0]),
|
||||
Power = Values[1],
|
||||
Vacuum = Values[2],
|
||||
Air = Values[3],
|
||||
};
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
/// <summary>
|
||||
/// Get current Production Info data
|
||||
/// </summary>
|
||||
/// <param name="currProdInfo"></param>
|
||||
@@ -2072,6 +2082,177 @@ namespace CMS_CORE_Library.S7Net
|
||||
}
|
||||
}
|
||||
|
||||
protected void refreshMemModBlockParameterRT()
|
||||
{
|
||||
List<byte> currMem = new List<byte>();
|
||||
int packSize = 12;
|
||||
|
||||
// leggo da PLC a array di byte di appoggio...
|
||||
CmsError cmsError = MEM_RWByteList(R, 0, MODULE_RT_DATA.MemType, MODULE_RT_DATA.Address, MODULE_RT_DATA.SubAddress, 0, MODULE_RT_DATA.Size, ref currMem);
|
||||
|
||||
// controllo SE ho dati...
|
||||
if (currMem.Count > 0)
|
||||
{
|
||||
// converto a blocchi di 8 byte...
|
||||
byte[] memArray = currMem.ToArray();
|
||||
for (int i = 0; i < MODULE_RT_DATA.Size / packSize; i++)
|
||||
{
|
||||
PlcModBlockRT currModBlock = new PlcModBlockRT(memArray.Skip(i * packSize).Take(packSize).ToArray());
|
||||
// solo se ID > 0...
|
||||
if (currModBlock.Id > 0)
|
||||
{
|
||||
// update oggetto thermoParamList...
|
||||
if (ThermoModuleList.ContainsKey(currModBlock.Id))
|
||||
{
|
||||
ThermoModuleList[currModBlock.Id].Visible = currModBlock.Visible;
|
||||
ThermoModuleList[currModBlock.Id].Running = currModBlock.Running;
|
||||
ThermoModuleList[currModBlock.Id].HasError = currModBlock.HasError;
|
||||
ThermoModuleList[currModBlock.Id].ActualDuration = currModBlock.ActualDuration;
|
||||
ThermoModuleList[currModBlock.Id].ActualDelay = currModBlock.ActualDelay;
|
||||
}
|
||||
else
|
||||
{
|
||||
ThermoModuleList.Add(currModBlock.Id, new ModuleBlock() {
|
||||
Id = currModBlock.Id,
|
||||
ActualDuration = currModBlock.ActualDuration,
|
||||
ActualDelay = currModBlock.ActualDelay,
|
||||
Visible = currModBlock.Visible,
|
||||
Running = currModBlock.Running,
|
||||
HasError = currModBlock.HasError
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
protected void refreshMemModBlockParameter()
|
||||
{
|
||||
#if false
|
||||
List<byte> currMem = new List<byte>();
|
||||
int packSize = 20;
|
||||
|
||||
// leggo da PLC a array di byte di appoggio...
|
||||
CmsError cmsError = MEM_RWByteList(R, 0, PARAMETER_DATA.MemType, PARAMETER_DATA.Address, PARAMETER_DATA.SubAddress, 0, PARAMETER_DATA.Size, ref currMem);
|
||||
|
||||
|
||||
// controllo SE ho dati...
|
||||
if (currMem.Count > 0)
|
||||
{
|
||||
// converto a blocchi di 8 byte...
|
||||
byte[] memArray = currMem.ToArray();
|
||||
for (int i = 0; i < PARAMETER_DATA.Size / packSize; i++)
|
||||
{
|
||||
PlcParam currParam = new PlcParam(memArray.Skip(i * packSize).Take(packSize).ToArray());
|
||||
// solo se ID > 0...
|
||||
if (currParam.Id > 0)
|
||||
{
|
||||
// update oggetto thermoParamList...
|
||||
if (ThermoParamList.ContainsKey(currParam.Id))
|
||||
{
|
||||
ThermoParamList[currParam.Id].SetpointHMI = currParam.SetpointHMI;
|
||||
ThermoParamList[currParam.Id].SetpointPLC = currParam.SetpointPLC;
|
||||
ThermoParamList[currParam.Id].ValMax = currParam.ValMax;
|
||||
ThermoParamList[currParam.Id].ValMin = currParam.ValMin;
|
||||
ThermoParamList[currParam.Id].UnitMeasure = currParam.UnitMeasure;
|
||||
}
|
||||
else
|
||||
{
|
||||
ThermoParamList.Add(currParam.Id, new RecipeParam() { Id = currParam.Id, SetpointHMI = currParam.SetpointHMI, SetpointPLC = currParam.SetpointPLC, ValMax = currParam.ValMax, ValMin = currParam.ValMin, UnitMeasure = currParam.UnitMeasure });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
/// <summary>
|
||||
/// Oggetto Modulo Blocco RT da PLC
|
||||
/// </summary>
|
||||
protected class PlcModBlockRT
|
||||
{
|
||||
public short Id { get; set; } = 0;
|
||||
public int ActualDuration { get; set; } = 0;
|
||||
public int ActualDelay { get; set; } = 0;
|
||||
private ushort Stato { get; set; } = 0;
|
||||
public bool Visible { get; set; }
|
||||
public bool Running { get; set; }
|
||||
public bool HasError { get; set; }
|
||||
/// <summary>
|
||||
/// Deserializzazione da byte ad oggetto ParamRT
|
||||
/// </summary>
|
||||
/// <param name="rawData"></param>
|
||||
public PlcModBlockRT(byte[] rawData)
|
||||
{
|
||||
// converto i dati da byte grezzi ai 3 componenti...
|
||||
Id = S7.Net.Types.Int.FromByteArray(rawData.Skip(0).Take(2).ToArray());
|
||||
ActualDuration = S7.Net.Types.DInt.FromByteArray(rawData.Skip(2).Take(4).ToArray());
|
||||
ActualDelay = S7.Net.Types.DInt.FromByteArray(rawData.Skip(6).Take(4).ToArray());
|
||||
Stato = S7.Net.Types.Word.FromByteArray(rawData.Skip(10).Take(2).ToArray());
|
||||
// calcolo bit...
|
||||
Visible = (Stato & 1) == 1;
|
||||
Running = (Stato & 2) == 2;
|
||||
HasError = (Stato & 4) == 4;
|
||||
}
|
||||
/// <summary>
|
||||
/// Converte un singolo item in un array di byte per scrittura su PLC S7
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public byte[] convertToByte()
|
||||
{
|
||||
// convero stato dai bit...
|
||||
Stato = 0;
|
||||
Stato += (ushort)(Visible ? 1 : 0);
|
||||
Stato += (ushort)(Running ? 2 : 0);
|
||||
Stato += (ushort)(HasError ? 4 : 0);
|
||||
byte[] answ = new byte[8];
|
||||
Buffer.BlockCopy(S7.Net.Types.Int.ToByteArray(Id), 0, answ, 0, 2);
|
||||
Buffer.BlockCopy(S7.Net.Types.DInt.ToByteArray(ActualDuration), 0, answ, 2, 4);
|
||||
Buffer.BlockCopy(S7.Net.Types.DInt.ToByteArray(ActualDelay), 0, answ, 6, 4);
|
||||
Buffer.BlockCopy(S7.Net.Types.Word.ToByteArray(Stato), 0, answ, 10, 2);
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Oggetto Modulo Blocco da PLC
|
||||
/// </summary>
|
||||
protected class PlcModBlock
|
||||
{
|
||||
public short Id { get; set; } = 0;
|
||||
public int SetpointHMI { get; set; } = 0;
|
||||
public int SetpointPLC { get; set; } = 0;
|
||||
public int ValMax { get; set; } = 0;
|
||||
public int ValMin { get; set; } = 0;
|
||||
public ushort UnitMeasure { get; set; } = 0;
|
||||
/// <summary>
|
||||
/// Deserializzazione da byte ad oggetto Param
|
||||
/// </summary>
|
||||
/// <param name="rawData"></param>
|
||||
public PlcModBlock(byte[] rawData)
|
||||
{
|
||||
// converto i dati da byte grezzi ai 3 componenti...
|
||||
Id = S7.Net.Types.Int.FromByteArray(rawData.Skip(0).Take(2).ToArray());
|
||||
SetpointHMI = S7.Net.Types.DInt.FromByteArray(rawData.Skip(2).Take(4).ToArray());
|
||||
SetpointPLC = S7.Net.Types.DInt.FromByteArray(rawData.Skip(6).Take(4).ToArray());
|
||||
ValMax = S7.Net.Types.DInt.FromByteArray(rawData.Skip(10).Take(4).ToArray());
|
||||
ValMin = S7.Net.Types.DInt.FromByteArray(rawData.Skip(14).Take(4).ToArray());
|
||||
UnitMeasure = S7.Net.Types.Word.FromByteArray(rawData.Skip(18).Take(2).ToArray());
|
||||
}
|
||||
/// <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[20];
|
||||
Buffer.BlockCopy(S7.Net.Types.Int.ToByteArray(Id), 0, answ, 0, 2);
|
||||
Buffer.BlockCopy(S7.Net.Types.DInt.ToByteArray(SetpointHMI), 0, answ, 2, 4);
|
||||
Buffer.BlockCopy(S7.Net.Types.DInt.ToByteArray(SetpointPLC), 0, answ, 6, 4);
|
||||
Buffer.BlockCopy(S7.Net.Types.DInt.ToByteArray(ValMax), 0, answ, 10, 4);
|
||||
Buffer.BlockCopy(S7.Net.Types.DInt.ToByteArray(ValMin), 0, answ, 14, 4);
|
||||
Buffer.BlockCopy(S7.Net.Types.Word.ToByteArray(UnitMeasure), 0, answ, 18, 2);
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user