Updated methods for S7 write

This commit is contained in:
Samuele Locatelli
2020-05-29 15:58:05 +02:00
parent d9fe04f40f
commit 8608bad055
3 changed files with 60 additions and 18 deletions
+2 -2
View File
@@ -531,8 +531,8 @@ namespace CMS_CORE_Library.Models
public class RecipeParam
{
public short Id { get; set; } = 0;
public int SetpointHMI { get; set; } = 0;
public int SetpointPLC { get; set; } = 0;
public double SetpointHMI { get; set; } = 0;
public double SetpointPLC { get; set; } = 0;
public double ValMax { get; set; } = 0;
public double ValMin { get; set; } = 0;
public ushort UnitMeasure { get; set; } = 0;
+4 -1
View File
@@ -632,6 +632,9 @@ namespace CMS_CORE_Library
#region THERMO high level data
public abstract CmsError PLC_RRecipeParamList(bool onlyRT, ref Dictionary<int, RecipeParam> currParamList);
public abstract CmsError PLC_RRecipeLastParamList(ref Dictionary<int, RecipeParam> currParamList);
public abstract CmsError PLC_WRecipeParam(RecipeParam updtParam);
#endregion THERMO high level data
@@ -1774,7 +1777,7 @@ namespace CMS_CORE_Library
internal MEMORY_CELL PARAM_LING_FANUC = new MEMORY_CELL(MEMORY_TYPE.Null, 3281, 0, 1);
internal MEMORY_CELL PARAM_LING_FANUC_W = new MEMORY_CELL(MEMORY_TYPE.Fanuc_G, 581, 0, 1);
#endregion Fixed memory area
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+54 -15
View File
@@ -2132,15 +2132,6 @@ namespace CMS_CORE_Library.S7Net
public override CmsError PLC_RGaugeData(ref GaugeModel gaugeData)
{
List<int> Values = new List<int>();
//// TODO FIXME quando disponibile memoria...
//gaugeData = new GaugeModel()
//{
// TimeAdv = 1,
// Power = 2,
// Vacuum = 3,
// Air = 4,
//};
#if true
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())
@@ -2153,7 +2144,6 @@ namespace CMS_CORE_Library.S7Net
Vacuum = Values[2],
Air = Values[3],
};
#endif
return NO_ERROR;
}
@@ -2173,15 +2163,56 @@ namespace CMS_CORE_Library.S7Net
return NO_ERROR;
}
public override CmsError PLC_RRecipeLastParamList(ref Dictionary<int, RecipeParam> currParamList)
{
// copio lista act in output...
refreshMemRecipeParameter();
refreshMemRecipeParameterRT();
currParamList = thermoParamList;
return NO_ERROR;
}
public override CmsError PLC_WRecipeParam(RecipeParam updtParam)
{
// init variabili accessorie
List<byte> currMem = new List<byte>();
int packSize = 20;
int memIndex = PARAMETER_DATA.SubAddress + (updtParam.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)updtParam.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;
#if false
// rileggo x verifica... DELETE ME!
cmsError = MEM_RWByteList(R, 0, PARAMETER_DATA.MemType, PARAMETER_DATA.Address, memIndex, 0, packSize, ref currMem);
if (cmsError.IsError())
return cmsError;
#endif
return NO_ERROR;
}
protected void refreshMemRecipeParameterRT()
{
List<byte> currMem = new List<byte>();
int packSize = 8;
// leggo da PLC a array di byte di appoggio...
CmsError cmsError = MEM_RWByteList(R, 0, PARAMETER_RT_DATA.MemType, PARAMETER_RT_DATA.Address, PARAMETER_RT_DATA.SubAddress, 0, PARAMETER_RT_DATA.Size, ref currMem);
int packSize = 8;
// controllo SE ho dati...
if (currMem.Count > 0)
{
@@ -2212,11 +2243,11 @@ namespace CMS_CORE_Library.S7Net
protected void refreshMemRecipeParameter()
{
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);
int packSize = 20;
// controllo SE ho dati...
if (currMem.Count > 0)
@@ -2818,8 +2849,16 @@ namespace CMS_CORE_Library.S7Net
//Prevent some exceptions
if (Values.Count == 0)
return NO_ERROR;
currPLC.WriteBytes(DataType.DataBlock, MemTable, MemIndex, Values.ToArray());
// try/catch
try
{
currPLC.WriteBytes(DataType.DataBlock, MemTable, MemIndex, Values.ToArray());
}
catch
{
// FIXME TODO rivedere codice errore!!!
return PLC_MEM_CONF_ERROR;
}
}
else
{