WebApi method 4 params update
This commit is contained in:
@@ -26,7 +26,7 @@ using Thermo.Active.Model.DTOModels.Recipe;
|
||||
|
||||
public static class ThreadsFunctions
|
||||
{
|
||||
public static int recipeRtCounter = 5;
|
||||
public static int recipeRtCounter = 0;
|
||||
public static bool reconnectionIsRunning = false;
|
||||
|
||||
private static ConcurrentDictionary<string, long> Timers = new ConcurrentDictionary<string, long>();
|
||||
@@ -692,7 +692,7 @@ public static class ThreadsFunctions
|
||||
catch (ThreadAbortException)
|
||||
{
|
||||
ncAdapter.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void ReadRecipeData()
|
||||
{
|
||||
@@ -721,7 +721,7 @@ public static class ThreadsFunctions
|
||||
if (ncAdapter.numericalControl.NC_IsConnected())
|
||||
{
|
||||
// Get new data from PLC
|
||||
libraryError = ncAdapter.ReadRecipeData(onlyRt, out Dictionary<string, DTORecipeParam> currRecipe);
|
||||
libraryError = ncAdapter.ReadRecipeData(onlyRt, false, out Dictionary<string, DTORecipeParam> currRecipe);
|
||||
if (libraryError.IsError())
|
||||
ManageLibraryError(libraryError);
|
||||
|
||||
|
||||
@@ -1072,10 +1072,11 @@ namespace Thermo.Active.NC
|
||||
/// <summary>
|
||||
/// Vero metodo lettura ricetta da 2 aree memoria PLC
|
||||
/// </summary>
|
||||
/// <param name="refreshOnlyRT"></param>
|
||||
/// <param name="refreshOnlyRT">Indica se aggiornare SOLO i dati RT</param>
|
||||
/// <param name="useLastRead">Indica se usare ultimi dati letti dal PLC senza effettiva lettura (via cache)</param>
|
||||
/// <param name="currentRecipe"></param>
|
||||
/// <returns></returns>
|
||||
public CmsError ReadRecipeData(bool refreshOnlyRT, out Dictionary<string, DTORecipeParam> currentRecipe)
|
||||
public CmsError ReadRecipeData(bool refreshOnlyRT, bool useLastRead, out Dictionary<string, DTORecipeParam> currentRecipe)
|
||||
{
|
||||
// init obj
|
||||
currentRecipe = new Dictionary<string, DTORecipeParam>();
|
||||
@@ -1085,7 +1086,15 @@ namespace Thermo.Active.NC
|
||||
if (NcConfig.NcVendor == NC_VENDOR.S7NET)
|
||||
{
|
||||
Dictionary<int, DataStructures.RecipeParam> currPlcRecipe = new Dictionary<int, DataStructures.RecipeParam>();
|
||||
CmsError cmsError = numericalControl.PLC_RRecipeParamList(refreshOnlyRT, ref currPlcRecipe);
|
||||
CmsError cmsError = NO_ERROR;
|
||||
if(useLastRead)
|
||||
{
|
||||
cmsError = numericalControl.PLC_RRecipeLastParamList(ref currPlcRecipe);
|
||||
}
|
||||
else
|
||||
{
|
||||
cmsError = numericalControl.PLC_RRecipeParamList(refreshOnlyRT, ref currPlcRecipe);
|
||||
}
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
DTORecipeParam currParam = new DTORecipeParam();
|
||||
@@ -1196,7 +1205,7 @@ namespace Thermo.Active.NC
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public CmsError ReadNcScada(ScadaSchemaModel scadaSchema, out DTOScadaModel scadaValue)
|
||||
{
|
||||
//ReadScadaDataSiemens(scadaSchema, out scadaValue);
|
||||
@@ -1560,7 +1569,14 @@ namespace Thermo.Active.NC
|
||||
RPRange currRange = new RPRange();
|
||||
RPStatus currStatus = new RPStatus();
|
||||
|
||||
if (simData)
|
||||
if (!simData)
|
||||
{
|
||||
// gestione errore
|
||||
cmsError = ReadRecipeData(false, true, out currRecipe);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
}
|
||||
else
|
||||
{
|
||||
// leggo l'intero array delle DB... QUI FAKE sulle DB configurate...
|
||||
List<DTORecipeConfigModel> recipeConfig = RecipeConfig.Select(x => new DTORecipeConfigModel()
|
||||
@@ -1604,17 +1620,11 @@ namespace Thermo.Active.NC
|
||||
currRecipe.Add(item.Label, currParam);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// gestione errore
|
||||
cmsError = ReadRecipeData(false, out currRecipe);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
}
|
||||
|
||||
// restituisco cod errore se trovato
|
||||
return cmsError;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Scrive tutti i parametri della ricetta indicati
|
||||
|
||||
@@ -24,6 +24,11 @@ namespace Thermo.Active.Controllers.WebApi
|
||||
{
|
||||
using (NcAdapter ncAdapter = new NcAdapter())
|
||||
{
|
||||
// Try connection
|
||||
CmsError libraryError = ncAdapter.Connect();
|
||||
if (libraryError.errorCode != 0)
|
||||
return NotFound();
|
||||
|
||||
CmsError cmsError = ncAdapter.GetRecipeOverview(out Dictionary<string, RecipeCatStatus> currOverview);
|
||||
if (cmsError.IsError())
|
||||
return BadRequest(cmsError.localizationKey);
|
||||
@@ -36,18 +41,69 @@ namespace Thermo.Active.Controllers.WebApi
|
||||
{
|
||||
using (NcAdapter ncAdapter = new NcAdapter())
|
||||
{
|
||||
CmsError cmsError = ncAdapter.ReadFullRecipe(out Dictionary<string, DTORecipeParam> currentRecipe);
|
||||
// Try connection
|
||||
CmsError libraryError = ncAdapter.Connect();
|
||||
if (libraryError.errorCode != 0)
|
||||
return NotFound();
|
||||
|
||||
CmsError cmsError = ncAdapter.ReadFullRecipe(out Dictionary<string, DTORecipeParam> currRecipe);
|
||||
if (cmsError.IsError())
|
||||
return BadRequest(cmsError.localizationKey);
|
||||
|
||||
return Ok(currentRecipe);
|
||||
return Ok(currRecipe);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Route("update"), HttpPut]
|
||||
public IHttpActionResult WriteParameters(Dictionary<string, double> parametersList)
|
||||
{
|
||||
using (NcAdapter ncAdapter = new NcAdapter())
|
||||
{
|
||||
// Try connection
|
||||
CmsError libraryError = ncAdapter.Connect();
|
||||
|
||||
CmsError cmsError = ncAdapter.ReadFullRecipe(out Dictionary<string, DTORecipeParam> prevRecipe);
|
||||
if (cmsError.IsError())
|
||||
return BadRequest(cmsError.localizationKey);
|
||||
|
||||
Dictionary<string, DTORecipeParam> updtRecipe = new Dictionary<string, DTORecipeParam>();
|
||||
|
||||
foreach (var item in parametersList)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// scrivo sul PLC
|
||||
ncAdapter.WriteRecipeParams(updtRecipe);
|
||||
|
||||
#if true
|
||||
// rileggo e restituisco...
|
||||
cmsError = ncAdapter.ReadFullRecipe(out Dictionary<string, DTORecipeParam> actRecipe);
|
||||
//cmsError = ncAdapter.ReadRecipeData(false, out Dictionary<string, DTORecipeParam> actRecipe);
|
||||
if (cmsError.IsError())
|
||||
return BadRequest(cmsError.localizationKey);
|
||||
#endif
|
||||
|
||||
return Ok(actRecipe);
|
||||
}
|
||||
}
|
||||
|
||||
#if false
|
||||
[Route("param/{paramName:string}/value/{SetpointHMI:double}"), HttpPut]
|
||||
//[WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.THERMO_MANAGER, Action = ACTIONS.WRITE)]
|
||||
public IHttpActionResult setParameter(string paramName, double SetpointHMI)
|
||||
//[Route("param/{paramName:string}/value/{SetpointHMI:double}"), HttpPut]
|
||||
////[WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.THERMO_MANAGER, Action = ACTIONS.WRITE)]
|
||||
//public IHttpActionResult setParameter(string paramName, double SetpointHMI)
|
||||
[Route("write"), HttpPost]
|
||||
public IHttpActionResult WriteParameter(string paramName, double SetpointHMI)
|
||||
|
||||
{
|
||||
//using (UsersController usersController = new UsersController())
|
||||
//{
|
||||
@@ -70,6 +126,9 @@ namespace Thermo.Active.Controllers.WebApi
|
||||
//}
|
||||
using (NcAdapter ncAdapter = new NcAdapter())
|
||||
{
|
||||
// Try connection
|
||||
CmsError libraryError = ncAdapter.Connect();
|
||||
|
||||
CmsError cmsError = ncAdapter.ReadFullRecipe(out Dictionary<string, DTORecipeParam> prevRecipe);
|
||||
if (cmsError.IsError())
|
||||
return BadRequest(cmsError.localizationKey);
|
||||
@@ -89,12 +148,13 @@ namespace Thermo.Active.Controllers.WebApi
|
||||
|
||||
// rileggo e restituisco...
|
||||
cmsError = ncAdapter.ReadFullRecipe(out Dictionary<string, DTORecipeParam> actRecipe);
|
||||
//cmsError = ncAdapter.ReadRecipeData(false, out Dictionary<string, DTORecipeParam> actRecipe);
|
||||
if (cmsError.IsError())
|
||||
return BadRequest(cmsError.localizationKey);
|
||||
|
||||
return Ok(actRecipe);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user