S7net: Draft methods for write warmers data

This commit is contained in:
Samuele Locatelli
2020-06-08 19:43:31 +02:00
parent fc2fffa248
commit fd24c5fd43
5 changed files with 126 additions and 4 deletions
@@ -171,6 +171,7 @@ namespace CMS_CORE_Library.Models
public static CmsError NO_ERROR = new CmsError(CMS_ERROR_CODES.OK, "");
public static CmsError NOT_CONNECTED_ERROR = new CmsError(CMS_ERROR_CODES.NOT_CONNECTED, "error_not_connected");
public static CmsError NOT_FOUND_ERROR = new CmsError(CMS_ERROR_CODES.INTERNAL_ERROR, "error_not_found");
public static CmsError PROC_NOT_FOUND_ERROR = new CmsError(CMS_ERROR_CODES.FUNCTION_NOT_ALLOWED, "error_process_not_found");
public static CmsError FUNCTION_NOT_ALLOWED_ERROR = new CmsError(CMS_ERROR_CODES.FUNCTION_NOT_ALLOWED, "error_function_not_allowed");
public static CmsError BIT_NOT_IN_RANGE_ERROR = new CmsError(CMS_ERROR_CODES.BIT_NOT_IN_RANGE, "error_bit_not_in_range");
+6
View File
@@ -147,9 +147,11 @@ namespace CMS_CORE_Library.Models
public class WarmerChannel
{
public int IdChannel { get; set; } = 0;
public double SetpointRecipe { get; set; } = 0;
public double SetpointThermoCam { get; set; } = 0;
public double SetpointPLC { get; set; } = 0;
public byte ChStatus { get; set; } = 0;
public double CurrAct { get; set; } = 0;
public byte PercAct { get; set; } = 0;
public override bool Equals(object obj)
@@ -160,12 +162,16 @@ namespace CMS_CORE_Library.Models
if (IdChannel != item.IdChannel)
return false;
if (SetpointRecipe != item.SetpointRecipe)
return false;
if (SetpointThermoCam != item.SetpointThermoCam)
return false;
if (SetpointPLC != item.SetpointPLC)
return false;
if (ChStatus != item.ChStatus)
return false;
if (CurrAct != item.CurrAct)
return false;
if (PercAct != item.PercAct)
return false;
+12
View File
@@ -653,6 +653,18 @@ namespace CMS_CORE_Library
/// <returns></returns>
public abstract CmsError PLC_RWarmerChannelList(ref Dictionary<int, ThermoModels.WarmerChannel> currWarmerChannelList);
/// <summary>
/// Set current Warmers Channels setpoints
/// </summary>
/// <param name="currWarmerChannelList"></param>
/// <returns></returns>
public abstract CmsError PLC_WWarmerChSetpoints(Dictionary<int, int> currWarmerChannelList);
/// <summary>
/// Set current Warmers Channels setup data
/// </summary>
/// <param name="currWarmerChannelList"></param>
/// <returns></returns>
public abstract CmsError PLC_WWarmerChData(Dictionary<int, ThermoModels.WarmerChannel> currWarmerChannelList);
/// <summary>
/// Read power gauge data
/// <para>
/// Compatibility: S7Net
+101 -3
View File
@@ -1912,6 +1912,8 @@ namespace CMS_CORE_Library.S7Net
// refresh % attuale
refreshRiscPerc();
// refresh setpoint PLC
refreshRiscActCurr();
// refresh setpoint PLC
refreshRiscSetpointPLC();
// refresh setpoint termocamera ???
refreshRiscSetpointTermoCam();
@@ -2005,7 +2007,7 @@ namespace CMS_CORE_Library.S7Net
}
/// <summary>
/// Refresh recip parameters RT
/// Refresh recipE parameters RT
/// </summary>
protected void refreshMemRecipeParameterRT()
{
@@ -2368,6 +2370,42 @@ namespace CMS_CORE_Library.S7Net
// leggo DB500 x area Ich
List<byte> currMem = new List<byte>();
// leggo da PLC a array di byte di appoggio...
CmsError cmsError = MEM_RWByteList(R, 0, RISC_CHP_DATA.MemType, RISC_CHP_DATA.Address, RISC_CHP_DATA.SubAddress, 0, RISC_CHP_DATA.Size, ref currMem);
// copio! controllo SE ho dati...
if (currMem.Count > 0)
{
// converto a blocchi di 8 byte...
byte[] memArray = currMem.ToArray();
double currVal = 0;
for (int i = 0; i < RISC_CHP_DATA.Size / 4; i++)
{
currVal = S7.Net.Types.Double.FromByteArray(memArray.Skip(4 * i).Take(4).ToArray());
// cerco id + 1 (su memoria è base 0)
if (ThermoWarmChannels.ContainsKey(i + 1))
{
ThermoWarmChannels[i + 1].SetpointPLC = currVal;
}
else
{
ThermoWarmChannels.Add(i + 1, new ThermoModels.WarmerChannel()
{
IdChannel = i + 1,
SetpointPLC = currVal
});
}
}
}
}
/// <summary>
/// Refresh Canali Riscaldi: actual current PLC
/// </summary>
private void refreshRiscActCurr()
{
// leggo DB500 x area Ich
List<byte> currMem = new List<byte>();
// leggo da PLC a array di byte di appoggio...
CmsError cmsError = MEM_RWByteList(R, 0, RISC_ICH_DATA.MemType, RISC_ICH_DATA.Address, RISC_ICH_DATA.SubAddress, 0, RISC_ICH_DATA.Size, ref currMem);
@@ -2383,14 +2421,14 @@ namespace CMS_CORE_Library.S7Net
// cerco id + 1 (su memoria è base 0)
if (ThermoWarmChannels.ContainsKey(i + 1))
{
ThermoWarmChannels[i + 1].SetpointPLC = currVal;
ThermoWarmChannels[i + 1].CurrAct = currVal;
}
else
{
ThermoWarmChannels.Add(i + 1, new ThermoModels.WarmerChannel()
{
IdChannel = i + 1,
SetpointPLC = currVal
CurrAct = currVal
});
}
}
@@ -2465,6 +2503,66 @@ namespace CMS_CORE_Library.S7Net
}
}
/// <summary>
/// Write Warmers channels load data
/// </summary>
/// <param name="updtCh"></param>
/// <returns></returns>
public override CmsError PLC_WWarmerChSetpoints(Dictionary<int, int> updtCh)
{
// memory area
List<byte> newMem = new List<byte>();
// per fare swapt faccio 2 alla volta e inverto ordine...
for (int i = 0; i < RISC_CHP_DATA.Size / 2; i++)
{
// aggiungo bit dispari
newMem.Add((byte)updtCh[i * 2 + 1]);
// aggiungo bit pari
newMem.Add((byte)updtCh[i * 2]);
}
// error in write WARM area...
#if false
// write!
CmsError cmsError = MEM_RWByteList(W, 0, RISC_CHP_DATA.MemType, RISC_CHP_DATA.Address, RISC_CHP_DATA.SubAddress, 0, RISC_CHP_DATA.Size, ref newMem);
if (cmsError.IsError())
return cmsError;
#endif
return NO_ERROR;
}
/// <summary>
/// Write Warmers channels setup parameters
/// </summary>
/// <param name="updtCh"></param>
/// <returns></returns>
public override CmsError PLC_WWarmerChData(Dictionary<int, ThermoModels.WarmerChannel> updtCh)
{
// FIXME TODO
#if false
// init variabili accessorie
List<byte> currMem = new List<byte>();
int packSize = 20;
int memIndex = PARAMETER_DATA.SubAddress + (updtCh.Id - 1) * packSize;
// leggo in primis il parametro che mi richiedono
CmsError cmsError = MEM_RWByteList(R, 0, PARAMETER_DATA.MemType, PARAMETER_DATA.Address, memIndex, 0, packSize, ref currMem);
if (cmsError.IsError())
return cmsError;
// converto in parametro...
PlcParam currParam = new PlcParam(currMem.ToArray());
// aggiorno SetpointHMI...
currParam.SetpointHMI = (int)updtCh.SetpointHMI;
// converto a NUOVA lista byte
List<byte> newMem = currParam.convertToByte().ToList();
cmsError = MEM_RWByteList(W, 0, PARAMETER_DATA.MemType, PARAMETER_DATA.Address, memIndex, 0, packSize, ref newMem);
if (cmsError.IsError())
return cmsError;
#endif
return NO_ERROR;
}
#endregion
+6 -1
View File
@@ -219,7 +219,12 @@ namespace Siemens_S7_Test
{
sw.Restart();
// eseguo test
memByteRead = currPLC.ReadBytes(DataType.DataBlock, memoria.DbNum, memoria.indiceMem, numByte);
try
{
memByteRead = currPLC.ReadBytes(DataType.DataBlock, memoria.DbNum, memoria.indiceMem, numByte);
}
catch
{ }
sw.Stop();
// salvo risultati
PerfStats.addValue((double)sw.ElapsedMilliseconds);