83 lines
2.7 KiB
C#
83 lines
2.7 KiB
C#
using CMS_CORE_Library.Models;
|
|
using Thermo.Active.Model.DTOModels;
|
|
using Thermo.Active.NC;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Threading.Tasks;
|
|
using System.Web.Http;
|
|
using static CMS_CORE_Library.Models.DataStructures;
|
|
using static Thermo.Active.Config.ServerConfig;
|
|
using static Thermo.Active.Model.Constants;
|
|
using Thermo.Active.Model.DTOModels.Recipe;
|
|
|
|
namespace Thermo.Active.Controllers.WebApi
|
|
{
|
|
[RoutePrefix("api/warmers")]
|
|
public class WarmersController : ApiController
|
|
{
|
|
[Route("current"), HttpGet]
|
|
public IHttpActionResult GetCurrentWarmers()
|
|
{
|
|
using (NcAdapter ncAdapter = new NcAdapter())
|
|
{
|
|
// Try connection
|
|
CmsError libraryError = ncAdapter.Connect();
|
|
if (libraryError.errorCode != 0)
|
|
return NotFound();
|
|
|
|
CmsError cmsError = ncAdapter.ReadWarmers(out Dictionary<int, DTOWarmers> currWarmers);
|
|
if (cmsError.IsError())
|
|
return BadRequest(cmsError.localizationKey);
|
|
|
|
return Ok(currWarmers);
|
|
}
|
|
}
|
|
|
|
|
|
// FIXME TODO determinare IN PRIMIS nel modello COSA e come aggiornare...
|
|
#if false
|
|
[Route("update"), HttpPut]
|
|
public IHttpActionResult WriteWarmers(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);
|
|
}
|
|
else
|
|
{
|
|
return NotFound();
|
|
}
|
|
}
|
|
|
|
// scrivo sul PLC
|
|
ncAdapter.WriteRecipeParams(updtRecipe);
|
|
|
|
// ritorno solo fatto!
|
|
return Ok();
|
|
}
|
|
}
|
|
#endif
|
|
|
|
}
|
|
} |