Merge branch 'feature/add/risk' into develop
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
|
||||
|
||||
@@ -794,8 +794,9 @@ namespace Thermo.Active.Config
|
||||
/// <summary>
|
||||
/// Try to load live data from json persistence file
|
||||
/// </summary>
|
||||
public static void ReadLiveData()
|
||||
public static bool ReadLiveData()
|
||||
{
|
||||
bool answ = false;
|
||||
if (File.Exists(LIVE_RECIPE_PATH))
|
||||
{
|
||||
// load all text data
|
||||
@@ -807,46 +808,48 @@ namespace Thermo.Active.Config
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
answ = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// setup new object
|
||||
RecipeLiveData = new LiveData()
|
||||
// reload from template...
|
||||
var rawData = File.ReadAllText(RECIPE_TEMPLATE_PATH);
|
||||
try
|
||||
{
|
||||
RecipeName = "current.json",
|
||||
ChannelSetpoints = new Dictionary<int, double>(),
|
||||
RecipeParameters = new Dictionary<string, double>()
|
||||
};
|
||||
// deserialize to object
|
||||
RecipeLiveData = JsonConvert.DeserializeObject<LiveData>(rawData);
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
answ = true;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Try to write live data to json persistence file
|
||||
/// </summary>
|
||||
public static void WriteLiveData()
|
||||
{
|
||||
try
|
||||
{
|
||||
// serialize
|
||||
string rawData = JsonConvert.SerializeObject(RecipeLiveData);
|
||||
// save live!
|
||||
File.WriteAllText(LIVE_RECIPE_PATH, rawData);
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
// rendo se fatto
|
||||
return answ;
|
||||
}
|
||||
/// <summary>
|
||||
/// Try to load selected recipe to live data (memory and json persistence file)
|
||||
/// </summary>
|
||||
public static void LoadRecipe(string filePath)
|
||||
public static bool LoadRecipe(string filePath)
|
||||
{
|
||||
bool answ = false;
|
||||
|
||||
// check file extension
|
||||
string fileName = Path.GetFileName(filePath);
|
||||
if (!fileName.EndsWith(".json"))
|
||||
{
|
||||
fileName += ".json";
|
||||
filePath += ".json";
|
||||
}
|
||||
|
||||
// check filePath...
|
||||
if (!filePath.Contains(RECIPE_DIRECTORY) && filePath != RECIPE_TEMPLATE_PATH)
|
||||
{
|
||||
// aggiungo base path!
|
||||
filePath = RECIPE_DIRECTORY + filePath;
|
||||
}
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
// check filePath...
|
||||
if (!filePath.Contains(RECIPE_DIRECTORY))
|
||||
{
|
||||
// aggiungo base path!
|
||||
filePath = RECIPE_DIRECTORY + filePath;
|
||||
}
|
||||
answ = true;
|
||||
|
||||
// load all text data
|
||||
var rawData = File.ReadAllText(filePath);
|
||||
@@ -858,22 +861,95 @@ namespace Thermo.Active.Config
|
||||
catch
|
||||
{ }
|
||||
// update current live data!
|
||||
WriteLiveData();
|
||||
SaveRecipeCurrent();
|
||||
}
|
||||
// rendo se fatto
|
||||
return answ;
|
||||
}
|
||||
/// <summary>
|
||||
/// Try to load template recipe
|
||||
/// </summary>
|
||||
public static bool LoadTemplate()
|
||||
{
|
||||
bool answ = false;
|
||||
// check filePath...
|
||||
if (File.Exists(RECIPE_TEMPLATE_PATH))
|
||||
{
|
||||
answ = true;
|
||||
|
||||
// load all text data
|
||||
var rawData = File.ReadAllText(RECIPE_TEMPLATE_PATH);
|
||||
try
|
||||
{
|
||||
// deserialize to object
|
||||
RecipeLiveData = JsonConvert.DeserializeObject<LiveData>(rawData);
|
||||
// update NAME
|
||||
RecipeLiveData.RecipeName = $"{DateTime.Now:yyyyMMss_HHmmss}.json";
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
// update current live data!
|
||||
SaveRecipeCurrent();
|
||||
}
|
||||
// rendo se fatto
|
||||
return answ;
|
||||
}
|
||||
/// <summary>
|
||||
/// Try to write live data to json persistence file
|
||||
/// </summary>
|
||||
public static bool SaveRecipeCurrent()
|
||||
{
|
||||
bool answ = false;
|
||||
try
|
||||
{
|
||||
answ = true;
|
||||
// serialize
|
||||
string rawData = JsonConvert.SerializeObject(RecipeLiveData);
|
||||
// save live!
|
||||
var dir = Path.GetDirectoryName(LIVE_RECIPE_PATH);
|
||||
if(!Directory.Exists(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
File.WriteAllText(LIVE_RECIPE_PATH, rawData);
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
// rendo se fatto
|
||||
return answ;
|
||||
}
|
||||
/// <summary>
|
||||
/// Try to save live recipe as NEW template
|
||||
/// </summary>
|
||||
public static bool SaveRecipeTemplate()
|
||||
{
|
||||
|
||||
RecipeLiveData.RecipeName = "template.json";
|
||||
return SaveRecipe(RECIPE_TEMPLATE_PATH);
|
||||
}
|
||||
/// <summary>
|
||||
/// Try to save live recipe to selected filePath
|
||||
/// </summary>
|
||||
public static void SaveRecipe(string filePath)
|
||||
public static bool SaveRecipe(string filePath)
|
||||
{
|
||||
bool answ = false;
|
||||
try
|
||||
{
|
||||
answ = true;
|
||||
string fileName = Path.GetFileName(filePath);
|
||||
if(!fileName.EndsWith(".json"))
|
||||
{
|
||||
fileName += ".json";
|
||||
filePath += ".json";
|
||||
}
|
||||
// fix name!
|
||||
RecipeLiveData.RecipeName=fileName;
|
||||
// serialize
|
||||
string rawData = JsonConvert.SerializeObject(RecipeLiveData);
|
||||
// save live!
|
||||
File.WriteAllText(LIVE_RECIPE_PATH, rawData);
|
||||
// check filePath...
|
||||
if (!filePath.Contains(RECIPE_DIRECTORY))
|
||||
if (!filePath.Contains(RECIPE_DIRECTORY) && filePath != RECIPE_TEMPLATE_PATH)
|
||||
{
|
||||
// aggiungo base path!
|
||||
filePath = RECIPE_DIRECTORY + filePath;
|
||||
@@ -883,6 +959,8 @@ namespace Thermo.Active.Config
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
// rendo se fatto
|
||||
return answ;
|
||||
}
|
||||
|
||||
#if false
|
||||
|
||||
@@ -59,6 +59,9 @@
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ServerConfig.cs" />
|
||||
<Compile Include="ServerConfigController.cs" />
|
||||
<Content Include="Recipes\.placeholder.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<EmbeddedResource Include="Report\Programs.xml">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</EmbeddedResource>
|
||||
@@ -179,10 +182,11 @@
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<ItemGroup>
|
||||
<Folder Include="Recipes\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Config\Recipes\template.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
|
||||
@@ -211,6 +211,8 @@ namespace Thermo.Active.Model
|
||||
#endif
|
||||
public const string CONFIG_DIRECTORY = "Config\\";
|
||||
public const string RECIPE_DIRECTORY = "Recipes\\";
|
||||
public const string RECIPE_TEMPLATE_PATH = CONFIG_DIRECTORY + RECIPE_DIRECTORY + "template.json";
|
||||
public const string LIVE_RECIPE_PATH = TEMP_FOLDER + RECIPE_DIRECTORY + "current.json";
|
||||
public const string RESOURCE_DIRECTORY = @"Thermo.Active.Config.Config.";
|
||||
public const string SERVER_CONFIG_SCHEMA_PATH = RESOURCE_DIRECTORY + @"serverConfigValidator.xsd";
|
||||
public const string SERVER_CONFIG_PATH = CONFIG_DIRECTORY + "serverConfig.xml";
|
||||
@@ -253,7 +255,6 @@ namespace Thermo.Active.Model
|
||||
|
||||
public const string MAIN_PROGRAM_CONFIG_PATH = CONFIG_DIRECTORY + "customMainProgram.txt";
|
||||
|
||||
public const string LIVE_RECIPE_PATH = RECIPE_DIRECTORY + "current.json";
|
||||
|
||||
public static string LANGUAGE_PACK_DIRECTORY = BASE_PATH + "\\languages\\";
|
||||
public static string LANGUAGE_SCHEMA_PATH = BASE_PATH + "\\LanguageValidator.xsd";
|
||||
|
||||
@@ -8,32 +8,39 @@ namespace Thermo.Active.Model.DTOModels.Recipe
|
||||
{
|
||||
public class DTOWarmers
|
||||
{
|
||||
public int Id { get; set; } = 0;
|
||||
public double SetpointHMI { get; set; } = 0;
|
||||
public double SetpointPLC { get; set; } = 0;
|
||||
//public RPRange Range { get; set; }
|
||||
//public RPStatus Status { get; set; }
|
||||
public string UnitMeasure { get; set; }
|
||||
public double ValueAct { get; set; }
|
||||
public int IdChannel { get; set; } = 0;
|
||||
public int IdReflector { get; set; } = 0;
|
||||
public int SetpointRecipe { get; set; } = 0;
|
||||
public int SetpointTermocam { get; set; } = 0;
|
||||
public int SetpointPLC { get; set; } = 0;
|
||||
public int ChannelStatus { get; set; } = 0;
|
||||
public double ActualCurrent { get; set; } = 0;
|
||||
public int ActualPerc { get; set; } = 0;
|
||||
public int MaxPower { get; set; } = 0;
|
||||
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (!(obj is DTOWarmers item))
|
||||
return false;
|
||||
|
||||
if (Id!= item.Id)
|
||||
if (IdChannel != item.IdChannel)
|
||||
return false;
|
||||
if (SetpointHMI != item.SetpointHMI)
|
||||
if (IdReflector != item.IdReflector)
|
||||
return false;
|
||||
if (SetpointRecipe != item.SetpointRecipe)
|
||||
return false;
|
||||
if (SetpointTermocam != item.SetpointTermocam)
|
||||
return false;
|
||||
if (SetpointPLC != item.SetpointPLC)
|
||||
return false;
|
||||
//if (!Range.Equals(item.Range))
|
||||
// return false;
|
||||
//if (!Status.Equals(item.Status))
|
||||
// return false;
|
||||
if (UnitMeasure != item.UnitMeasure)
|
||||
if (ChannelStatus != item.ChannelStatus)
|
||||
return false;
|
||||
if (ValueAct != item.ValueAct)
|
||||
if (ActualCurrent != item.ActualCurrent)
|
||||
return false;
|
||||
if (ActualPerc != item.ActualPerc)
|
||||
return false;
|
||||
if (MaxPower != item.MaxPower)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@@ -45,53 +52,4 @@ namespace Thermo.Active.Model.DTOModels.Recipe
|
||||
}
|
||||
}
|
||||
|
||||
#if false
|
||||
public struct RPRange
|
||||
{
|
||||
public double Min { get; set; }
|
||||
public double Max { get; set; }
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (!(obj is RPRange item))
|
||||
return false;
|
||||
|
||||
if (Min != item.Min)
|
||||
return false;
|
||||
if (Max != item.Max)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
||||
public struct RPStatus
|
||||
{
|
||||
public bool Visible { get; set; }
|
||||
public bool Enabled { get; set; }
|
||||
public bool HasError { get; set; }
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (!(obj is RPStatus item))
|
||||
return false;
|
||||
|
||||
if (Visible != item.Visible)
|
||||
return false;
|
||||
if (Enabled != item.Enabled)
|
||||
return false;
|
||||
if (HasError != item.HasError)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1170,11 +1170,11 @@ namespace Thermo.Active.NC
|
||||
return NO_ERROR;
|
||||
}
|
||||
/// <summary>
|
||||
/// Scrittura memoria (SOLO SetpointHMI invero)
|
||||
/// Recipe Parameters write to PLC (only SetpointHMI)
|
||||
/// </summary>
|
||||
/// <param name="updtRecipe"></param>
|
||||
/// <returns></returns>
|
||||
public CmsError WriteRecipeData(Dictionary<string, DTORecipeParam> updtRecipe)
|
||||
public CmsError WriteRecipeParametersToPLC(Dictionary<string, DTORecipeParam> updtRecipe)
|
||||
{
|
||||
// solo x S7...
|
||||
if (NcConfig.NcVendor == NC_VENDOR.S7NET)
|
||||
@@ -1225,6 +1225,43 @@ namespace Thermo.Active.NC
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
/// <summary>
|
||||
/// Recipe Parameters write to PLC (only SetpointHMI)
|
||||
/// </summary>
|
||||
/// <param name="updtRecipe"></param>
|
||||
/// <returns></returns>
|
||||
public CmsError WriteRecipeWarmersToPLC(Dictionary<string, DTORecipeParam> updtRecipe)
|
||||
{
|
||||
// solo x S7...
|
||||
if (NcConfig.NcVendor == NC_VENDOR.S7NET)
|
||||
{
|
||||
// FIXME TODO WRITE CH LOAD DATA
|
||||
#if false
|
||||
// ciclo x ogni valore della ricetta aggiornata ricevuto
|
||||
ThermoModels.RecipeParam currParam;
|
||||
foreach (var item in updtRecipe)
|
||||
{
|
||||
// salvo SOLO il setpoint HMI...
|
||||
currParam = new ThermoModels.RecipeParam()
|
||||
{
|
||||
Id = (short)item.Value.Id,
|
||||
SetpointHMI = item.Value.SetpointHMI
|
||||
};
|
||||
// scrivo!
|
||||
CmsError cmsError = numericalControl.PLC_WRecipeParam(currParam);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return FUNCTION_NOT_ALLOWED_ERROR;
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
|
||||
public CmsError ReadNcScada(ScadaSchemaModel scadaSchema, out DTOScadaModel scadaValue)
|
||||
@@ -1606,7 +1643,7 @@ namespace Thermo.Active.NC
|
||||
/// <returns></returns>
|
||||
public CmsError WriteRecipeParams(Dictionary<string, DTORecipeParam> updtRecipe)
|
||||
{
|
||||
CmsError cmsError = WriteRecipeData(updtRecipe);
|
||||
CmsError cmsError = WriteRecipeParametersToPLC(updtRecipe);
|
||||
|
||||
return cmsError;
|
||||
}
|
||||
@@ -1719,26 +1756,40 @@ namespace Thermo.Active.NC
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Legge tutti i parametri della ricetta
|
||||
/// GEt all warmers data by channel
|
||||
/// </summary>
|
||||
/// <param name="currWarmers">Oggetto elenco 1024 ch riscaldi</param>
|
||||
/// <param name="currWarmers">List of <= 1024 warmers channels</param>
|
||||
/// <returns></returns>
|
||||
public CmsError ReadWarmers(out Dictionary<int, DTOWarmers> currWarmers)
|
||||
{
|
||||
CmsError cmsError = NO_ERROR;
|
||||
currWarmers = new Dictionary<int, DTOWarmers>();
|
||||
DTOWarmers currVal = new DTOWarmers();
|
||||
|
||||
// FIXME TODO
|
||||
#if false
|
||||
DTORecipeParam currParam = new DTORecipeParam();
|
||||
RPRange currRange = new RPRange();
|
||||
RPStatus currStatus = new RPStatus();
|
||||
// read and return config
|
||||
if (NcConfig.NcVendor == NC_VENDOR.S7NET)
|
||||
{
|
||||
foreach (var item in RiskChannelConfig)
|
||||
{
|
||||
currVal = new DTOWarmers()
|
||||
{
|
||||
IdChannel = item.IdChannel,
|
||||
IdReflector = item.IdReflector,
|
||||
SetpointRecipe = 80, // leggere da NUOVA area PLC?
|
||||
SetpointTermocam = 0, // per ora a zero
|
||||
SetpointPLC = 0, // leggere da PLC!
|
||||
ChannelStatus = 0, // leggere da PLC
|
||||
ActualCurrent = 0, // leggere da PLC
|
||||
ActualPerc = 0, // leggere da PLC
|
||||
MaxPower = item.MaxPower
|
||||
};
|
||||
currWarmers.Add(item.IdChannel, currVal);
|
||||
}
|
||||
}
|
||||
|
||||
// gestione errore
|
||||
cmsError = ReadRecipeData(false, true, out currModules);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
#endif
|
||||
return cmsError;
|
||||
|
||||
// restituisco cod errore se trovato
|
||||
return cmsError;
|
||||
@@ -1767,6 +1818,18 @@ namespace Thermo.Active.NC
|
||||
return cmsError;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write all warmers load for recipe
|
||||
/// </summary>
|
||||
/// <param name="updtRecipe">Oggetto parametri da aggiornare (from HMI)</param>
|
||||
/// <returns></returns>
|
||||
public CmsError WriteRecipeWarmers(Dictionary<string, DTORecipeParam> updtRecipe)
|
||||
{
|
||||
CmsError cmsError = WriteRecipeWarmersToPLC(updtRecipe);
|
||||
|
||||
return cmsError;
|
||||
}
|
||||
|
||||
#endregion Read Data
|
||||
|
||||
#region Write data
|
||||
|
||||
@@ -127,10 +127,7 @@ namespace Thermo.Active.Controllers.WebApi
|
||||
currParams.Add(item.Key, item.Value.SetpointHMI);
|
||||
}
|
||||
|
||||
// ora salvo ANCHE i dati live...
|
||||
RecipeLiveData.RecipeParameters = currParams;
|
||||
// e salvo su disco
|
||||
ServerConfigController.WriteLiveData();
|
||||
saveCurrentRecipeParams(currParams);
|
||||
|
||||
// ritorno solo fatto!
|
||||
return Ok();
|
||||
@@ -168,9 +165,66 @@ namespace Thermo.Active.Controllers.WebApi
|
||||
}
|
||||
|
||||
// ora salvo ANCHE i dati live...
|
||||
RecipeLiveData.RecipeParameters = currParams;
|
||||
// e salvo su disco
|
||||
ServerConfigController.WriteLiveData();
|
||||
saveCurrentRecipeParams(currParams);
|
||||
|
||||
// ritorno solo fatto!
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// load recipe from file and send to PLC
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Route("load"), HttpPut]
|
||||
public IHttpActionResult Load(string newName)
|
||||
{
|
||||
using (NcFileAdapter ncAdapter = new NcFileAdapter())
|
||||
{
|
||||
// Try connection
|
||||
CmsError libraryError = ncAdapter.Connect();
|
||||
if (libraryError.errorCode != 0)
|
||||
return NotFound();
|
||||
|
||||
// chiamo metodo di lettura...
|
||||
//CmsError cmsError = ServerConfigController.LoadRecipe(newName);
|
||||
bool fatto = ServerConfigController.LoadRecipe(newName);
|
||||
if (!fatto)
|
||||
return NotFound();
|
||||
|
||||
|
||||
CmsError cmsError = writeCurrentRecipeToPlc();
|
||||
if (cmsError.IsError())
|
||||
return BadRequest(cmsError.localizationKey);
|
||||
|
||||
// ritorno solo fatto!
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Load tempalte recipe from file and save as new current...
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Route("new"), HttpPut]
|
||||
public IHttpActionResult NewRecipe()
|
||||
{
|
||||
using (NcFileAdapter ncAdapter = new NcFileAdapter())
|
||||
{
|
||||
// Try connection
|
||||
CmsError libraryError = ncAdapter.Connect();
|
||||
if (libraryError.errorCode != 0)
|
||||
return NotFound();
|
||||
|
||||
// chiamo metodo di lettura...
|
||||
bool fatto = ServerConfigController.LoadTemplate();
|
||||
|
||||
if (!fatto)
|
||||
return NotFound();
|
||||
|
||||
CmsError cmsError = writeCurrentRecipeToPlc();
|
||||
if (cmsError.IsError())
|
||||
return BadRequest(cmsError.localizationKey);
|
||||
|
||||
// ritorno solo fatto!
|
||||
return Ok();
|
||||
@@ -203,15 +257,12 @@ namespace Thermo.Active.Controllers.WebApi
|
||||
}
|
||||
|
||||
// ora salvo ANCHE i dati live...
|
||||
RecipeLiveData.RecipeParameters = currParams;
|
||||
// e salvo su disco
|
||||
ServerConfigController.WriteLiveData();
|
||||
saveCurrentRecipeParams(currParams);
|
||||
|
||||
// ritorno solo fatto!
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Save current recipe from PLC with new name
|
||||
/// </summary>
|
||||
@@ -247,11 +298,11 @@ namespace Thermo.Active.Controllers.WebApi
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// load recipe from file and send to PLC
|
||||
/// Save current recipe from PLC to Template
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Route("load"), HttpPut]
|
||||
public IHttpActionResult Load(string newName)
|
||||
[Route("saveTemplate"), HttpPut]
|
||||
public IHttpActionResult SaveTemplate()
|
||||
{
|
||||
using (NcFileAdapter ncAdapter = new NcFileAdapter())
|
||||
{
|
||||
@@ -260,13 +311,117 @@ namespace Thermo.Active.Controllers.WebApi
|
||||
if (libraryError.errorCode != 0)
|
||||
return NotFound();
|
||||
|
||||
// chiamo metodo di lettura...
|
||||
ServerConfigController.LoadRecipe(newName);
|
||||
// recupero i dati LIVE dei parametri HMI della ricetta...
|
||||
CmsError cmsError = ncAdapter.ReadFullRecipe(out Dictionary<string, DTORecipeParam> currRecipe);
|
||||
if (cmsError.IsError())
|
||||
return BadRequest(cmsError.localizationKey);
|
||||
|
||||
|
||||
// recupero i dati LIVE dei carichi load dei cahnnels di riscaldo...
|
||||
cmsError = ncAdapter.ReadWarmers(out Dictionary<int, DTOWarmers> currWarmers);
|
||||
if (cmsError.IsError())
|
||||
return BadRequest(cmsError.localizationKey);
|
||||
|
||||
// uso i valopri HMI...
|
||||
var currParams = new Dictionary<string, double>();
|
||||
foreach (var item in currRecipe)
|
||||
{
|
||||
currParams.Add(item.Key, item.Value.SetpointHMI);
|
||||
}
|
||||
|
||||
// ora salvo nei dati live...
|
||||
RecipeLiveData.RecipeParameters = currParams;
|
||||
|
||||
// carico i dati dei riscaldi...
|
||||
var currChSet = new Dictionary<int, double>();
|
||||
foreach (var item in currWarmers)
|
||||
{
|
||||
currChSet.Add(item.Key, item.Value.SetpointRecipe);
|
||||
}
|
||||
RecipeLiveData.ChannelSetpoints = currChSet;
|
||||
|
||||
|
||||
// e salvo su disco
|
||||
ServerConfigController.SaveRecipeTemplate();
|
||||
|
||||
// ritorno solo fatto!
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Do actual recipe parameters FileSave
|
||||
/// </summary>
|
||||
/// <param name="currParams"></param>
|
||||
private static void saveCurrentRecipeParams(Dictionary<string, double> currParams)
|
||||
{
|
||||
// ora salvo ANCHE i dati live...
|
||||
RecipeLiveData.RecipeParameters = currParams;
|
||||
// e salvo su disco
|
||||
ServerConfigController.SaveRecipeCurrent();
|
||||
}
|
||||
|
||||
protected static CmsError writeCurrentRecipeToPlc()
|
||||
{
|
||||
CmsError checkError = NO_ERROR;
|
||||
|
||||
using (NcAdapter ncAdapter = new NcAdapter())
|
||||
{
|
||||
// copy data to PLC
|
||||
checkError = ncAdapter.ReadFullRecipe(out Dictionary<string, DTORecipeParam> prevRecipe);
|
||||
if (checkError.IsError())
|
||||
return checkError;
|
||||
|
||||
// save parameters to PLC!!!
|
||||
Dictionary<string, DTORecipeParam> updtRecipe = new Dictionary<string, DTORecipeParam>();
|
||||
foreach (var item in RecipeLiveData.RecipeParameters)
|
||||
{
|
||||
if (prevRecipe.ContainsKey(item.Key))
|
||||
{
|
||||
// aggiorno il valore HMI nel parametro
|
||||
var currParam = prevRecipe[item.Key];
|
||||
currParam.SetpointHMI = item.Value;
|
||||
// salvo (1 parametro, potrei fare N...)
|
||||
updtRecipe.Add(item.Key, currParam);
|
||||
}
|
||||
else
|
||||
{
|
||||
return NOT_FOUND_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
// write to PLC
|
||||
checkError = ncAdapter.WriteRecipeParams(updtRecipe);
|
||||
|
||||
// FIXME TODO warmers to be completed!!!
|
||||
#if false
|
||||
// reading warmers data...
|
||||
cmsError = ncAdapter.ReadWarmers(out Dictionary<int, DTOWarmers> prevWarmers);
|
||||
if (cmsError.IsError())
|
||||
return BadRequest(cmsError.localizationKey);
|
||||
|
||||
// save warmers to PLC
|
||||
foreach (var item in RecipeLiveData.ChannelSetpoints)
|
||||
{
|
||||
//if (prevRecipe.ContainsKey(item.Key))
|
||||
//{
|
||||
// // aggiorno il valore HMI nel parametro
|
||||
// var currParam = prevRecipe[item.Key];
|
||||
// currParam.SetpointHMI = item.Value;
|
||||
// // salvo (1 parametro, potrei fare N...)
|
||||
// updtRecipe.Add(item.Key, currParam);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// return NotFound();
|
||||
//}
|
||||
}
|
||||
// write to PLC
|
||||
ncAdapter.WriteRecipeWarmers(updtRecipe);
|
||||
#endif
|
||||
}
|
||||
return checkError;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user