update letture IO
This commit is contained in:
@@ -797,14 +797,17 @@ namespace CMS_CORE_Library
|
||||
/// <returns></returns>
|
||||
public abstract CmsError PLC_WModeSel(int mode);
|
||||
/// <summary>
|
||||
/// Read PLC current IO hannels data
|
||||
/// Read PLC current IO Channels visibility (conf)
|
||||
/// </summary>
|
||||
/// <param name="onlyVal">updates only VALUE readout</param>
|
||||
/// <param name="currThermoIOVis">Visibility status for all channels</param>
|
||||
public abstract CmsError PLC_RIOChannelsConf(ref ThermoModels.ChanIOVis currThermoIOVis);
|
||||
/// <summary>
|
||||
/// Read PLC current IO Channels VALUES (actual + forced)
|
||||
/// </summary>
|
||||
/// <param name="currThermoIOVal">Values for channels</param>
|
||||
/// <param name="currThermoIOFor">Indicates if values are forced by UI</param>
|
||||
/// <param name="currThermoIOValFor">Values forced by UI</param>
|
||||
public abstract CmsError PLC_RIOChannels(bool onlyVal, ref ThermoModels.ChanIOVis currThermoIOVis, ref ThermoModels.ChanIOVal currThermoIOVal, ref ThermoModels.ChanIOFor currThermoIOFor, ref ThermoModels.ChanIOValFor currThermoIOValFor);
|
||||
public abstract CmsError PLC_RIOChannelsVal(ref ThermoModels.ChanIOVal currThermoIOVal, ref ThermoModels.ChanIOFor currThermoIOFor, ref ThermoModels.ChanIOValFor currThermoIOValFor);
|
||||
|
||||
#endregion THERMO high level data
|
||||
|
||||
|
||||
@@ -2601,7 +2601,7 @@ namespace CMS_CORE_Library.S7Net
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Refresh recipE parameters RT
|
||||
@@ -3736,30 +3736,39 @@ namespace CMS_CORE_Library.S7Net
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read PLC current IO hannels data
|
||||
/// <summary>
|
||||
/// Read PLC current IO Channels visibility (conf)
|
||||
/// </summary>
|
||||
/// <param name="onlyVal">updates only RT parameters (false = update all)</param>
|
||||
/// <param name="currThermoIOVis">Visibility status for all channels</param>
|
||||
/// <returns></returns>
|
||||
public override CmsError PLC_RIOChannelsConf(ref ThermoModels.ChanIOVis currThermoIOVis)
|
||||
{
|
||||
CmsError currError = NO_ERROR;
|
||||
// refresh dati
|
||||
refreshChIOVisib();
|
||||
|
||||
// copio liste in output...
|
||||
currThermoIOVis = ThermoIOVis;
|
||||
|
||||
// esco
|
||||
return currError;
|
||||
}
|
||||
/// <summary>
|
||||
/// Read PLC current IO Channels VALUES (actual + forced)
|
||||
/// </summary>
|
||||
/// <param name="currThermoIOVal">Values for channels</param>
|
||||
/// <param name="currThermoIOFor">Indicates if values are forced by UI</param>
|
||||
/// <param name="currThermoIOValFor">Values forced by UI</param>
|
||||
/// <returns></returns>
|
||||
public override CmsError PLC_RIOChannels(bool onlyVal, ref ThermoModels.ChanIOVis currThermoIOVis, ref ThermoModels.ChanIOVal currThermoIOVal, ref ThermoModels.ChanIOFor currThermoIOFor, ref ThermoModels.ChanIOValFor currThermoIOValFor)
|
||||
public override CmsError PLC_RIOChannelsVal(ref ThermoModels.ChanIOVal currThermoIOVal, ref ThermoModels.ChanIOFor currThermoIOFor, ref ThermoModels.ChanIOValFor currThermoIOValFor)
|
||||
{
|
||||
CmsError currError = NO_ERROR;
|
||||
// refresh dati veloci (valori)
|
||||
refreshChIOVal();
|
||||
// se richiesto NON SOLO RT faccio refresh anche dati "lenti"
|
||||
if (!onlyVal)
|
||||
{
|
||||
refreshChIOVisib();
|
||||
refreshChIOForced();
|
||||
refreshChIOForcedVal();
|
||||
}
|
||||
refreshChIOForced();
|
||||
refreshChIOForcedVal();
|
||||
|
||||
// copio liste in output...
|
||||
currThermoIOVis = ThermoIOVis;
|
||||
currThermoIOVal = ThermoIOVal;
|
||||
currThermoIOFor = ThermoIOFor;
|
||||
currThermoIOValFor = ThermoIOValFor;
|
||||
@@ -3775,52 +3784,32 @@ namespace CMS_CORE_Library.S7Net
|
||||
protected CmsError refreshChIOVal()
|
||||
{
|
||||
CmsError libraryError = NO_ERROR;
|
||||
#if false
|
||||
List<byte> currMem = new List<byte>();
|
||||
int packSize = 8;
|
||||
List<ushort> readValuesDI = new List<ushort>();
|
||||
List<ushort> readValuesDO = new List<ushort>();
|
||||
List<short> readValuesAI = new List<short>();
|
||||
List<short> readValuesAO = new List<short>();
|
||||
|
||||
// leggo da PLC a array di byte di appoggio...
|
||||
libraryError = MEM_RWByteList(R, 0, PARAMETER_RT_DATA.MemType, PARAMETER_RT_DATA.Address, PARAMETER_RT_DATA.SubAddress, 0, PARAMETER_RT_DATA.Size, ref currMem);
|
||||
// leggo da PLC a array di byte di appoggio x visibilità DI...
|
||||
libraryError = MEM_RWWordList(R, 0, IO_DI_VAL_ACT.MemType, IO_DI_VAL_ACT.Address, IO_DI_VAL_ACT.SubAddress, IO_DI_VAL_ACT.Size, ref readValuesDI);
|
||||
if (libraryError.IsError())
|
||||
return libraryError;
|
||||
// leggo da PLC a array di byte di appoggio x visibilità DO...
|
||||
libraryError = MEM_RWWordList(R, 0, IO_DO_VAL_ACT.MemType, IO_DO_VAL_ACT.Address, IO_DO_VAL_ACT.SubAddress, IO_DO_VAL_ACT.Size, ref readValuesDO);
|
||||
if (libraryError.IsError())
|
||||
return libraryError;
|
||||
// leggo da PLC a array di byte di appoggio x visibilità AI...
|
||||
libraryError = MEM_RWShortList(R, 0, IO_AI_VAL_ACT.MemType, IO_AI_VAL_ACT.Address, IO_AI_VAL_ACT.SubAddress, IO_AI_VAL_ACT.Size, ref readValuesAI);
|
||||
if (libraryError.IsError())
|
||||
return libraryError;
|
||||
// leggo da PLC a array di byte di appoggio x visibilità AO...
|
||||
libraryError = MEM_RWShortList(R, 0, IO_AO_VAL_ACT.MemType, IO_AO_VAL_ACT.Address, IO_AO_VAL_ACT.SubAddress, IO_AO_VAL_ACT.Size, ref readValuesAO);
|
||||
if (libraryError.IsError())
|
||||
return libraryError;
|
||||
|
||||
// controllo SE ho dati...
|
||||
if (currMem.Count > 0)
|
||||
{
|
||||
// converto a blocchi di 8 byte...
|
||||
byte[] memArray = currMem.ToArray();
|
||||
for (int i = 0; i < PARAMETER_RT_DATA.Size / packSize; i++)
|
||||
{
|
||||
PlcParamRT currParam = new PlcParamRT(memArray.Skip(i * packSize).Take(packSize).ToArray());
|
||||
// solo se ID > 0...
|
||||
if (currParam.Id > 0)
|
||||
{
|
||||
// update oggetto thermoParamList...
|
||||
if (ThermoParamList.ContainsKey(currParam.Id))
|
||||
{
|
||||
try
|
||||
{
|
||||
ThermoParamList[currParam.Id].Enabled = currParam.Enabled;
|
||||
ThermoParamList[currParam.Id].HasError = currParam.HasError;
|
||||
ThermoParamList[currParam.Id].Visible = currParam.Visible;
|
||||
ThermoParamList[currParam.Id].ValueAct = currParam.ValueAct;
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
ThermoParamList.Add(currParam.Id, new ThermoModels.RecipeParam() { Id = currParam.Id, Enabled = currParam.Enabled, HasError = currParam.HasError, Visible = currParam.Visible, ValueAct = currParam.ValueAct });
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
ThermoIOVal.DI = convToDictIntBol(readValuesDI);
|
||||
ThermoIOVal.DO = convToDictIntBol(readValuesDO);
|
||||
ThermoIOVal.AI = convToDictIntInt(readValuesAI);
|
||||
ThermoIOVal.AO = convToDictIntInt(readValuesAO);
|
||||
|
||||
return libraryError;
|
||||
}
|
||||
@@ -3831,7 +3820,6 @@ namespace CMS_CORE_Library.S7Net
|
||||
protected CmsError refreshChIOVisib()
|
||||
{
|
||||
CmsError libraryError = NO_ERROR;
|
||||
Byte[] byteArray = null;
|
||||
List<ushort> readValuesDI = new List<ushort>();
|
||||
List<ushort> readValuesDO = new List<ushort>();
|
||||
List<ushort> readValuesAI = new List<ushort>();
|
||||
@@ -3854,28 +3842,15 @@ namespace CMS_CORE_Library.S7Net
|
||||
if (libraryError.IsError())
|
||||
return libraryError;
|
||||
|
||||
ThermoIOVis.DI = convShortToDict(readValuesDI);
|
||||
ThermoIOVis.DO = convShortToDict(readValuesDO);
|
||||
ThermoIOVis.AI = convShortToDict(readValuesAI);
|
||||
ThermoIOVis.AO = convShortToDict(readValuesAO);
|
||||
ThermoIOVis.DI = convToDictIntBol(readValuesDI);
|
||||
ThermoIOVis.DO = convToDictIntBol(readValuesDO);
|
||||
ThermoIOVis.AI = convToDictIntBol(readValuesAI);
|
||||
ThermoIOVis.AO = convToDictIntBol(readValuesAO);
|
||||
|
||||
return libraryError;
|
||||
}
|
||||
|
||||
internal static Dictionary<int, bool> convShortToDict(List<ushort> origVal)
|
||||
{
|
||||
Byte[] byteArray = null;
|
||||
// Convert List<int16> into Byte Array
|
||||
byteArray = origVal.SelectMany(j => BitConverter.GetBytes(j)).ToArray();
|
||||
// converto a bit
|
||||
BitArray bitArr = new BitArray(byteArray);
|
||||
Dictionary<int, bool> answ = new Dictionary<int, bool>();
|
||||
for (int i = 0; i < bitArr.Count; i++)
|
||||
{
|
||||
answ.Add(i, bitArr[i]);
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Refresh recipe parameters
|
||||
@@ -3883,65 +3858,20 @@ namespace CMS_CORE_Library.S7Net
|
||||
protected CmsError refreshChIOForcedVal()
|
||||
{
|
||||
CmsError libraryError = NO_ERROR;
|
||||
#if false
|
||||
List<byte> currMem = new List<byte>();
|
||||
int packSize = 20;
|
||||
List<ushort> readValuesDO = new List<ushort>();
|
||||
List<short> readValuesAO = new List<short>();
|
||||
|
||||
// leggo da PLC a array di byte di appoggio...
|
||||
libraryError = MEM_RWByteList(R, 0, PARAMETER_DATA.MemType, PARAMETER_DATA.Address, PARAMETER_DATA.SubAddress, 0, PARAMETER_DATA.Size, ref currMem);
|
||||
// leggo da PLC a array di byte di appoggio x visibilità DO...
|
||||
libraryError = MEM_RWWordList(R, 0, IO_DO_VAL_FOR.MemType, IO_DO_VAL_FOR.Address, IO_DO_VAL_FOR.SubAddress, IO_DO_VAL_FOR.Size, ref readValuesDO);
|
||||
if (libraryError.IsError())
|
||||
return libraryError;
|
||||
// leggo da PLC a array di byte di appoggio x visibilità AO...
|
||||
libraryError = MEM_RWShortList(R, 0, IO_AO_VAL_FOR.MemType, IO_AO_VAL_FOR.Address, IO_AO_VAL_FOR.SubAddress, IO_AO_VAL_FOR.Size, ref readValuesAO);
|
||||
if (libraryError.IsError())
|
||||
return libraryError;
|
||||
|
||||
|
||||
|
||||
// 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))
|
||||
{
|
||||
try
|
||||
{
|
||||
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;
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
ThermoParamList.Add(currParam.Id, new ThermoModels.RecipeParam() { Id = currParam.Id, SetpointHMI = currParam.SetpointHMI, SetpointPLC = currParam.SetpointPLC, ValMax = currParam.ValMax, ValMin = currParam.ValMin, UnitMeasure = currParam.UnitMeasure });
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
libraryError = S7_PLC_WRONG_DATA;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
libraryError = S7_PLC_EMPTY_READ;
|
||||
}
|
||||
#endif
|
||||
|
||||
ThermoIOValFor.DO = convToDictIntBol(readValuesDO);
|
||||
ThermoIOValFor.AO = convToDictIntInt(readValuesAO);
|
||||
|
||||
return libraryError;
|
||||
}
|
||||
@@ -3951,65 +3881,20 @@ namespace CMS_CORE_Library.S7Net
|
||||
protected CmsError refreshChIOForced()
|
||||
{
|
||||
CmsError libraryError = NO_ERROR;
|
||||
#if false
|
||||
List<byte> currMem = new List<byte>();
|
||||
int packSize = 20;
|
||||
List<ushort> readValuesDO = new List<ushort>();
|
||||
List<ushort> readValuesAO = new List<ushort>();
|
||||
|
||||
// leggo da PLC a array di byte di appoggio...
|
||||
libraryError = MEM_RWByteList(R, 0, PARAMETER_DATA.MemType, PARAMETER_DATA.Address, PARAMETER_DATA.SubAddress, 0, PARAMETER_DATA.Size, ref currMem);
|
||||
// leggo da PLC a array di byte di appoggio x visibilità DO...
|
||||
libraryError = MEM_RWWordList(R, 0, IO_DO_FORCE.MemType, IO_DO_FORCE.Address, IO_DO_FORCE.SubAddress, IO_DO_FORCE.Size, ref readValuesDO);
|
||||
if (libraryError.IsError())
|
||||
return libraryError;
|
||||
// leggo da PLC a array di byte di appoggio x visibilità AO...
|
||||
libraryError = MEM_RWWordList(R, 0, IO_AO_FORCE.MemType, IO_AO_FORCE.Address, IO_AO_FORCE.SubAddress, IO_AO_FORCE.Size, ref readValuesAO);
|
||||
if (libraryError.IsError())
|
||||
return libraryError;
|
||||
|
||||
|
||||
|
||||
// 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))
|
||||
{
|
||||
try
|
||||
{
|
||||
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;
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
ThermoParamList.Add(currParam.Id, new ThermoModels.RecipeParam() { Id = currParam.Id, SetpointHMI = currParam.SetpointHMI, SetpointPLC = currParam.SetpointPLC, ValMax = currParam.ValMax, ValMin = currParam.ValMin, UnitMeasure = currParam.UnitMeasure });
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
libraryError = S7_PLC_WRONG_DATA;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
libraryError = S7_PLC_EMPTY_READ;
|
||||
}
|
||||
#endif
|
||||
|
||||
ThermoIOFor.DO = convToDictIntBol(readValuesDO);
|
||||
ThermoIOFor.AO = convToDictIntBol(readValuesAO);
|
||||
|
||||
return libraryError;
|
||||
}
|
||||
|
||||
@@ -166,6 +166,30 @@ namespace CMS_CORE_Library.Utils
|
||||
return String.Empty;
|
||||
}
|
||||
|
||||
internal static Dictionary<int, bool> convToDictIntBol(List<ushort> origVal)
|
||||
{
|
||||
Byte[] byteArray = null;
|
||||
// Convert List<int16> into Byte Array
|
||||
byteArray = origVal.SelectMany(j => BitConverter.GetBytes(j)).ToArray();
|
||||
// converto a bit
|
||||
BitArray bitArr = new BitArray(byteArray);
|
||||
Dictionary<int, bool> answ = new Dictionary<int, bool>();
|
||||
for (int i = 0; i < bitArr.Count; i++)
|
||||
{
|
||||
answ.Add(i, bitArr[i]);
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
internal static Dictionary<int, int> convToDictIntInt(List<short> origVal)
|
||||
{
|
||||
Dictionary<int, int> answ = new Dictionary<int, int>();
|
||||
for (int i = 0; i < origVal.Count; i++)
|
||||
{
|
||||
answ.Add(i, origVal[i]);
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
// Convert one integer in array of bools
|
||||
internal static bool[] IntToBits(int val)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user