Merge branch 'feature/S7Net' into develop

This commit is contained in:
Samuele Locatelli
2020-05-29 15:58:42 +02:00
3 changed files with 92 additions and 18 deletions
+2 -2
View File
@@ -539,8 +539,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
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+86 -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)
@@ -2272,6 +2303,23 @@ namespace CMS_CORE_Library.S7Net
Enabled = (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)(Enabled ? 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.Word.ToByteArray(Stato), 0, answ, 2, 2);
Buffer.BlockCopy(S7.Net.Types.DInt.ToByteArray(ValueAct), 0, answ, 4, 4);
return answ;
}
}
/// <summary>
/// Oggetto Parametro da PLC
@@ -2298,6 +2346,21 @@ namespace CMS_CORE_Library.S7Net
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
@@ -2786,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
{