Merge branch 'feature/S7Net' into develop
This commit is contained in:
@@ -172,6 +172,10 @@ 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 S7_PLC_EMPTY_READ = new CmsError(CMS_ERROR_CODES.INTERNAL_ERROR, "error_s7_empy_data");
|
||||
public static CmsError S7_PLC_WRONG_DATA = new CmsError(CMS_ERROR_CODES.INTERNAL_ERROR, "error_s7_wrong_data");
|
||||
public static CmsError S7_PLC_READ_ERROR = new CmsError(CMS_ERROR_CODES.INTERNAL_ERROR, "error_s7_read_error");
|
||||
public static CmsError S7_PLC_WRITE_ERROR = new CmsError(CMS_ERROR_CODES.INTERNAL_ERROR, "error_s7_write_error");
|
||||
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");
|
||||
|
||||
@@ -58,11 +58,11 @@ namespace CMS_CORE_Library.S7Net
|
||||
|
||||
|
||||
// Dizionario parametri specifici per THERMO
|
||||
private static Dictionary<int, ThermoModels.RecipeParam> ThermoParamList;
|
||||
private static Dictionary<int, ThermoModels.ModuleBlock> ThermoModuleList;
|
||||
private static Dictionary<int, ThermoModels.WarmerChannel> ThermoWarmChannels;
|
||||
private static ThermoModels.ProdInfoModel ThermoProdInfo;
|
||||
private static ThermoModels.ProdCycleModel ThermoProdCycle;
|
||||
private static Dictionary<int, ThermoModels.RecipeParam> ThermoParamList = new Dictionary<int, ThermoModels.RecipeParam>();
|
||||
private static Dictionary<int, ThermoModels.ModuleBlock> ThermoModuleList = new Dictionary<int, ThermoModels.ModuleBlock>();
|
||||
private static Dictionary<int, ThermoModels.WarmerChannel> ThermoWarmChannels = new Dictionary<int, ThermoModels.WarmerChannel>();
|
||||
private static ThermoModels.ProdInfoModel ThermoProdInfo = new ThermoModels.ProdInfoModel();
|
||||
private static ThermoModels.ProdCycleModel ThermoProdCycle = new ThermoModels.ProdCycleModel();
|
||||
|
||||
// connessione S7
|
||||
private CpuType tipoCpu = CpuType.S71500;
|
||||
@@ -132,12 +132,8 @@ namespace CMS_CORE_Library.S7Net
|
||||
Port = RemotePort;
|
||||
// mesasggi generici PLC
|
||||
PlcMessages = new Dictionary<int, string>();
|
||||
// Init dati specifici Themo
|
||||
ThermoParamList = new Dictionary<int, ThermoModels.RecipeParam>();
|
||||
ThermoModuleList = new Dictionary<int, ThermoModels.ModuleBlock>();
|
||||
ThermoWarmChannels = new Dictionary<int, ThermoModels.WarmerChannel>();
|
||||
ThermoProdCycle = new ThermoModels.ProdCycleModel();
|
||||
ThermoProdInfo = new ThermoModels.ProdInfoModel();
|
||||
// Init dati specifici Thermo
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Connessione al PLC
|
||||
@@ -2003,13 +1999,13 @@ namespace CMS_CORE_Library.S7Net
|
||||
public override CmsError PLC_RRecipeParamList(bool onlyRT, ref Dictionary<int, ThermoModels.RecipeParam> currParamList)
|
||||
{
|
||||
CmsError currError = NO_ERROR;
|
||||
// refresh dati veloci / RT
|
||||
refreshMemRecipeParameterRT();
|
||||
// se richiesto NON SOLO RT faccio refresh anche dati "lenti"
|
||||
if (!onlyRT)
|
||||
{
|
||||
refreshMemRecipeParameter();
|
||||
}
|
||||
// refresh dati veloci / RT
|
||||
refreshMemRecipeParameterRT();
|
||||
|
||||
// copio lista act in output...
|
||||
currParamList = ThermoParamList;
|
||||
@@ -2290,11 +2286,14 @@ namespace CMS_CORE_Library.S7Net
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
|
||||
|
||||
// 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());
|
||||
@@ -2325,8 +2324,17 @@ namespace CMS_CORE_Library.S7Net
|
||||
{ }
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cmsError = S7_PLC_WRONG_DATA;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cmsError = S7_PLC_EMPTY_READ;
|
||||
}
|
||||
|
||||
|
||||
return cmsError;
|
||||
}
|
||||
@@ -2470,8 +2478,16 @@ namespace CMS_CORE_Library.S7Net
|
||||
{ }
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cmsError = S7_PLC_WRONG_DATA;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cmsError = S7_PLC_EMPTY_READ;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Refresh ModuleBlock
|
||||
@@ -2519,8 +2535,16 @@ namespace CMS_CORE_Library.S7Net
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cmsError = S7_PLC_WRONG_DATA;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cmsError = S7_PLC_EMPTY_READ;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Oggetto Modulo Blocco RT da PLC
|
||||
@@ -2639,7 +2663,12 @@ namespace CMS_CORE_Library.S7Net
|
||||
// cerco id + 1 (su memoria è base 0)
|
||||
if (ThermoWarmChannels.ContainsKey(i + 1))
|
||||
{
|
||||
ThermoWarmChannels[i + 1].SetpointHMI = memArray[i];
|
||||
try
|
||||
{
|
||||
ThermoWarmChannels[i + 1].SetpointHMI = memArray[i];
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2651,6 +2680,10 @@ namespace CMS_CORE_Library.S7Net
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cmsError = S7_PLC_EMPTY_READ;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Refresh Canali Riscaldi: SetPoint PLC
|
||||
@@ -3545,7 +3578,7 @@ namespace CMS_CORE_Library.S7Net
|
||||
}
|
||||
catch
|
||||
{
|
||||
return PLC_MEM_CONF_ERROR;
|
||||
return S7_PLC_WRITE_ERROR;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -3561,7 +3594,7 @@ namespace CMS_CORE_Library.S7Net
|
||||
}
|
||||
catch
|
||||
{
|
||||
return PLC_MEM_CONF_ERROR;
|
||||
return S7_PLC_READ_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3598,8 +3631,14 @@ namespace CMS_CORE_Library.S7Net
|
||||
singleItem = S7.Net.Types.Word.ToByteArray(Item);
|
||||
memByteList.AddRange(singleItem);
|
||||
}
|
||||
|
||||
currPLC.WriteBytes(DataType.DataBlock, MemTable, MemIndex, memByteList.ToArray());
|
||||
try
|
||||
{
|
||||
currPLC.WriteBytes(DataType.DataBlock, MemTable, MemIndex, memByteList.ToArray());
|
||||
}
|
||||
catch
|
||||
{
|
||||
return S7_PLC_WRITE_ERROR;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -3608,14 +3647,21 @@ namespace CMS_CORE_Library.S7Net
|
||||
return NO_ERROR;
|
||||
|
||||
Values.Clear();
|
||||
|
||||
byte[] memByteRead = currPLC.ReadBytes(DataType.DataBlock, MemTable, MemIndex, Number);
|
||||
// converto a word!
|
||||
ushort shortVal = 0;
|
||||
for (int i = 0; i < memByteRead.Length / 2; i++)
|
||||
byte[] memByteRead;
|
||||
try
|
||||
{
|
||||
shortVal = S7.Net.Types.Word.FromByteArray(memByteRead.Skip(2 * i).Take(2).ToArray());
|
||||
Values.Add(shortVal);
|
||||
memByteRead = currPLC.ReadBytes(DataType.DataBlock, MemTable, MemIndex, Number);
|
||||
// converto a word!
|
||||
ushort shortVal = 0;
|
||||
for (int i = 0; i < memByteRead.Length / 2; i++)
|
||||
{
|
||||
shortVal = S7.Net.Types.Word.FromByteArray(memByteRead.Skip(2 * i).Take(2).ToArray());
|
||||
Values.Add(shortVal);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return S7_PLC_READ_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3651,8 +3697,14 @@ namespace CMS_CORE_Library.S7Net
|
||||
singleItem = S7.Net.Types.Int.ToByteArray(Item);
|
||||
memByteList.AddRange(singleItem);
|
||||
}
|
||||
|
||||
currPLC.WriteBytes(DataType.DataBlock, MemTable, MemIndex, memByteList.ToArray());
|
||||
try
|
||||
{
|
||||
currPLC.WriteBytes(DataType.DataBlock, MemTable, MemIndex, memByteList.ToArray());
|
||||
}
|
||||
catch
|
||||
{
|
||||
return S7_PLC_WRITE_ERROR;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -3661,14 +3713,20 @@ namespace CMS_CORE_Library.S7Net
|
||||
return NO_ERROR;
|
||||
|
||||
Values.Clear();
|
||||
|
||||
byte[] memByteRead = currPLC.ReadBytes(DataType.DataBlock, MemTable, MemIndex, Number);
|
||||
// converto a word!
|
||||
short shortVal = 0;
|
||||
for (int i = 0; i < memByteRead.Length / 2; i++)
|
||||
try
|
||||
{
|
||||
shortVal = S7.Net.Types.Int.FromByteArray(memByteRead.Skip(2 * i).Take(2).ToArray());
|
||||
Values.Add(shortVal);
|
||||
byte[] memByteRead = currPLC.ReadBytes(DataType.DataBlock, MemTable, MemIndex, Number);
|
||||
// converto a word!
|
||||
short shortVal = 0;
|
||||
for (int i = 0; i < memByteRead.Length / 2; i++)
|
||||
{
|
||||
shortVal = S7.Net.Types.Int.FromByteArray(memByteRead.Skip(2 * i).Take(2).ToArray());
|
||||
Values.Add(shortVal);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return S7_PLC_READ_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3704,7 +3762,14 @@ namespace CMS_CORE_Library.S7Net
|
||||
memByteList.AddRange(singleItem);
|
||||
}
|
||||
|
||||
currPLC.WriteBytes(DataType.DataBlock, MemTable, MemIndex, memByteList.ToArray());
|
||||
try
|
||||
{
|
||||
currPLC.WriteBytes(DataType.DataBlock, MemTable, MemIndex, memByteList.ToArray());
|
||||
}
|
||||
catch
|
||||
{
|
||||
return S7_PLC_WRITE_ERROR;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -3714,13 +3779,20 @@ namespace CMS_CORE_Library.S7Net
|
||||
|
||||
Values.Clear();
|
||||
|
||||
byte[] memByteRead = currPLC.ReadBytes(DataType.DataBlock, MemTable, MemIndex, Number);
|
||||
// converto a word!
|
||||
uint shortVal = 0;
|
||||
for (int i = 0; i < memByteRead.Length / 4; i++)
|
||||
try
|
||||
{
|
||||
shortVal = S7.Net.Types.DWord.FromByteArray(memByteRead.Skip(4 * i).Take(4).ToArray());
|
||||
Values.Add(shortVal);
|
||||
byte[] memByteRead = currPLC.ReadBytes(DataType.DataBlock, MemTable, MemIndex, Number);
|
||||
// converto a word!
|
||||
uint shortVal = 0;
|
||||
for (int i = 0; i < memByteRead.Length / 4; i++)
|
||||
{
|
||||
shortVal = S7.Net.Types.DWord.FromByteArray(memByteRead.Skip(4 * i).Take(4).ToArray());
|
||||
Values.Add(shortVal);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return S7_PLC_READ_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3767,8 +3839,14 @@ namespace CMS_CORE_Library.S7Net
|
||||
singleItem = S7.Net.Types.DInt.ToByteArray(Item);
|
||||
memByteList.AddRange(singleItem);
|
||||
}
|
||||
|
||||
currPLC.WriteBytes(DataType.DataBlock, MemTable, MemIndex, memByteList.ToArray());
|
||||
try
|
||||
{
|
||||
currPLC.WriteBytes(DataType.DataBlock, MemTable, MemIndex, memByteList.ToArray());
|
||||
}
|
||||
catch
|
||||
{
|
||||
return S7_PLC_WRITE_ERROR;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -3781,17 +3859,17 @@ namespace CMS_CORE_Library.S7Net
|
||||
try
|
||||
{
|
||||
memByteRead = currPLC.ReadBytes(DataType.DataBlock, MemTable, MemIndex, Number * 4);
|
||||
// converto a word!
|
||||
int intVal = 0;
|
||||
for (int i = 0; i < memByteRead.Length / 4; i++)
|
||||
{
|
||||
intVal = S7.Net.Types.DInt.FromByteArray(memByteRead.Skip(4 * i).Take(4).ToArray());
|
||||
Values.Add(intVal);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return PLC_MEM_CONF_ERROR;
|
||||
}
|
||||
// converto a word!
|
||||
int intVal = 0;
|
||||
for (int i = 0; i < memByteRead.Length / 4; i++)
|
||||
{
|
||||
intVal = S7.Net.Types.DInt.FromByteArray(memByteRead.Skip(4 * i).Take(4).ToArray());
|
||||
Values.Add(intVal);
|
||||
return S7_PLC_READ_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3832,7 +3910,14 @@ namespace CMS_CORE_Library.S7Net
|
||||
memByteList.AddRange(singleItem);
|
||||
}
|
||||
|
||||
currPLC.WriteBytes(DataType.DataBlock, MemTable, MemIndex, memByteList.ToArray());
|
||||
try
|
||||
{
|
||||
currPLC.WriteBytes(DataType.DataBlock, MemTable, MemIndex, memByteList.ToArray());
|
||||
}
|
||||
catch
|
||||
{
|
||||
return S7_PLC_WRITE_ERROR;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -3842,13 +3927,20 @@ namespace CMS_CORE_Library.S7Net
|
||||
|
||||
Values.Clear();
|
||||
|
||||
byte[] memByteRead = currPLC.ReadBytes(DataType.DataBlock, MemTable, MemIndex, Number);
|
||||
// converto a word!
|
||||
double shortVal = 0;
|
||||
for (int i = 0; i < memByteRead.Length / 4; i++)
|
||||
try
|
||||
{
|
||||
shortVal = S7.Net.Types.Double.FromByteArray(memByteRead.Skip(4 * i).Take(4).ToArray());
|
||||
Values.Add(shortVal);
|
||||
byte[] memByteRead = currPLC.ReadBytes(DataType.DataBlock, MemTable, MemIndex, Number);
|
||||
// converto a word!
|
||||
double shortVal = 0;
|
||||
for (int i = 0; i < memByteRead.Length / 4; i++)
|
||||
{
|
||||
shortVal = S7.Net.Types.Double.FromByteArray(memByteRead.Skip(4 * i).Take(4).ToArray());
|
||||
Values.Add(shortVal);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return S7_PLC_WRITE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user