First readout new IO S7 area
This commit is contained in:
@@ -3831,68 +3831,52 @@ namespace CMS_CORE_Library.S7Net
|
||||
protected CmsError refreshChIOVisib()
|
||||
{
|
||||
CmsError libraryError = NO_ERROR;
|
||||
#if false
|
||||
List<byte> currMem = new List<byte>();
|
||||
int packSize = 20;
|
||||
Byte[] byteArray = null;
|
||||
List<ushort> readValuesDI = new List<ushort>();
|
||||
List<ushort> readValuesDO = new List<ushort>();
|
||||
List<ushort> readValuesAI = 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à DI...
|
||||
libraryError = MEM_RWWordList(R, 0, IO_DI_VISIB.MemType, IO_DI_VISIB.Address, IO_DI_VISIB.SubAddress, IO_DI_VISIB.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_VISIB.MemType, IO_DO_VISIB.Address, IO_DO_VISIB.SubAddress, IO_DO_VISIB.Size, ref readValuesDO);
|
||||
if (libraryError.IsError())
|
||||
return libraryError;
|
||||
// leggo da PLC a array di byte di appoggio x visibilità AI...
|
||||
libraryError = MEM_RWWordList(R, 0, IO_AI_VISIB.MemType, IO_AI_VISIB.Address, IO_AI_VISIB.SubAddress, IO_AI_VISIB.Size, ref readValuesAI);
|
||||
if (libraryError.IsError())
|
||||
return libraryError;
|
||||
// leggo da PLC a array di byte di appoggio x visibilità AO...
|
||||
libraryError = MEM_RWWordList(R, 0, IO_AO_VISIB.MemType, IO_AO_VISIB.Address, IO_AO_VISIB.SubAddress, IO_AO_VISIB.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
|
||||
|
||||
ThermoIOVis.DI = convShortToDict(readValuesDI);
|
||||
ThermoIOVis.DO = convShortToDict(readValuesDO);
|
||||
ThermoIOVis.AI = convShortToDict(readValuesAI);
|
||||
ThermoIOVis.AO = convShortToDict(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
|
||||
/// </summary>
|
||||
|
||||
@@ -203,7 +203,7 @@ namespace CMS_CORE_Library.Utils
|
||||
.Cast<bool>()
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
|
||||
// Convert a byte into an array of bools
|
||||
public static bool[] ByteToBits(byte val)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user