Added load save update methods
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -832,6 +832,15 @@ namespace Thermo.Active.Config
|
||||
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)
|
||||
{
|
||||
@@ -897,6 +906,11 @@ namespace Thermo.Active.Config
|
||||
// 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
|
||||
@@ -922,8 +936,14 @@ namespace Thermo.Active.Config
|
||||
try
|
||||
{
|
||||
answ = true;
|
||||
string fileName = Path.GetFileName(filePath);
|
||||
if(!fileName.EndsWith(".json"))
|
||||
{
|
||||
fileName += ".json";
|
||||
filePath += ".json";
|
||||
}
|
||||
// fix name!
|
||||
RecipeLiveData.RecipeName= Path.GetFileName(filePath);
|
||||
RecipeLiveData.RecipeName=fileName;
|
||||
// serialize
|
||||
string rawData = JsonConvert.SerializeObject(RecipeLiveData);
|
||||
// save live!
|
||||
|
||||
@@ -184,7 +184,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<ItemGroup>
|
||||
<Content Include="Config\Recipe\template.json">
|
||||
<Content Include="Config\Recipes\template.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<None Include="packages.config" />
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -1781,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
|
||||
|
||||
@@ -192,6 +192,11 @@ namespace Thermo.Active.Controllers.WebApi
|
||||
if (!fatto)
|
||||
return NotFound();
|
||||
|
||||
|
||||
CmsError cmsError = writeCurrentRecipeToPlc();
|
||||
if (cmsError.IsError())
|
||||
return BadRequest(cmsError.localizationKey);
|
||||
|
||||
// ritorno solo fatto!
|
||||
return Ok();
|
||||
}
|
||||
@@ -213,9 +218,14 @@ namespace Thermo.Active.Controllers.WebApi
|
||||
|
||||
// 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();
|
||||
}
|
||||
@@ -308,7 +318,7 @@ namespace Thermo.Active.Controllers.WebApi
|
||||
|
||||
|
||||
// recupero i dati LIVE dei carichi load dei cahnnels di riscaldo...
|
||||
cmsError = ncAdapter.ReadWarmers(out Dictionary<int, DTOWarmers> currWarmers);
|
||||
cmsError = ncAdapter.ReadWarmers(out Dictionary<int, DTOWarmers> currWarmers);
|
||||
if (cmsError.IsError())
|
||||
return BadRequest(cmsError.localizationKey);
|
||||
|
||||
@@ -341,7 +351,7 @@ namespace Thermo.Active.Controllers.WebApi
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Do actual recipe parameters save
|
||||
/// Do actual recipe parameters FileSave
|
||||
/// </summary>
|
||||
/// <param name="currParams"></param>
|
||||
private static void saveCurrentRecipeParams(Dictionary<string, double> currParams)
|
||||
@@ -352,5 +362,66 @@ namespace Thermo.Active.Controllers.WebApi
|
||||
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