From 655407a9a8d2af1fc77d9869a5d1b4306f59a445 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Tue, 27 Oct 2020 12:17:40 +0100 Subject: [PATCH] WebAPI x status TCam --- .../DTOModels/ThWarmers/DTOThermoCam.cs | 53 ++++++++++++++++++ .../Thermo.Active.Model.csproj | 1 + Thermo.Active.NC/NcAdapter.cs | 20 ++++++- .../Controllers/WebApi/WarmersController.cs | 55 ++++++++++++++++++- 4 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 Thermo.Active.Model/DTOModels/ThWarmers/DTOThermoCam.cs diff --git a/Thermo.Active.Model/DTOModels/ThWarmers/DTOThermoCam.cs b/Thermo.Active.Model/DTOModels/ThWarmers/DTOThermoCam.cs new file mode 100644 index 00000000..91c0ea01 --- /dev/null +++ b/Thermo.Active.Model/DTOModels/ThWarmers/DTOThermoCam.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Thermo.Active.Model.DTOModels.ThWarmers +{ + public class DTOThermoCam + { + /// + /// Opzione ThermoCamera (set by PLC) + /// + public bool ThermoOptionActive { get; set; } = false; + /// + /// Modalità ThermoCamera (set by HMI) + /// + public bool ThermoCamMode { get; set; } = false; + /// + /// Funzionamento ThermoCamera (set by HMI) + /// + public bool ThermoCamOnOff { get; set; } = false; + + /// + /// Equality test for class object + /// + /// + /// + public override bool Equals(object obj) + { + if (!(obj is DTOThermoCam item)) + return false; + + if (ThermoOptionActive != item.ThermoOptionActive) + return false; + if (ThermoCamMode != item.ThermoCamMode) + return false; + if (ThermoCamOnOff != item.ThermoCamOnOff) + return false; + + return true; + } + + /// + /// Hash gen + /// + /// + public override int GetHashCode() + { + return base.GetHashCode(); + } + } +} diff --git a/Thermo.Active.Model/Thermo.Active.Model.csproj b/Thermo.Active.Model/Thermo.Active.Model.csproj index 98c2a325..c79b1ab5 100644 --- a/Thermo.Active.Model/Thermo.Active.Model.csproj +++ b/Thermo.Active.Model/Thermo.Active.Model.csproj @@ -118,6 +118,7 @@ + diff --git a/Thermo.Active.NC/NcAdapter.cs b/Thermo.Active.NC/NcAdapter.cs index d08a139c..08bc0939 100644 --- a/Thermo.Active.NC/NcAdapter.cs +++ b/Thermo.Active.NC/NcAdapter.cs @@ -2699,6 +2699,24 @@ namespace Thermo.Active.NC return libraryError; } + public CmsError ReadTCamData(out DTOThermoCam currTCamData) + { + CmsError libraryError = NO_ERROR; + currTCamData = new DTOThermoCam(); + // solo x S7... + if (NcConfig.NcVendor == NC_VENDOR.S7NET) + { + numericalControl.PLC_RWarmerTCamData(out ThermoModels.ThermoCam currPlcTCamData); + currTCamData = new DTOThermoCam() + { + ThermoOptionActive = currPlcTCamData.ThermoOptionActive, + ThermoCamMode = currPlcTCamData.ThermoCamMode, + ThermoCamOnOff = currPlcTCamData.ThermoCamOnOff + }; + } + return libraryError; + } + /// /// Get all warmers data by channel /// @@ -2736,7 +2754,7 @@ namespace Thermo.Active.NC ActualPerc = currPlcWarmers[x.IdChannel].PercAct, MaxPower = x.MaxPower }).ToList(); - + // preparo output foreach (var item in warmersConfig) { diff --git a/Thermo.Active/Controllers/WebApi/WarmersController.cs b/Thermo.Active/Controllers/WebApi/WarmersController.cs index f8582613..99a605e7 100644 --- a/Thermo.Active/Controllers/WebApi/WarmersController.cs +++ b/Thermo.Active/Controllers/WebApi/WarmersController.cs @@ -190,13 +190,38 @@ namespace Thermo.Active.Controllers.WebApi libraryError = ncAdapter.ReadWarmers(false, out Dictionary currWarmers); if (libraryError.IsError()) { - ThermoActiveLogger.LogError($"GetRecipeOverview error | {libraryError.exception}"); + ThermoActiveLogger.LogError($"GetCurrentWarmersChannels error | {libraryError.exception}"); return BadRequest(libraryError.localizationKey); } return Ok(currWarmers); } + /// + /// Current status related to ThermoCamera + /// + /// + [Route("TCamData"), HttpGet] + public IHttpActionResult GetCurrentTCamData() + { + // Try connection + CmsError libraryError = ncAdapter.Connect(); + if (libraryError.IsError()) + { + ThermoActiveLogger.LogError($"NC Not connected! | GetCurrentTCamData | {libraryError.exception}"); + return BadRequest(libraryError.localizationKey); + } + + libraryError = ncAdapter.ReadTCamData(out DTOThermoCam currTCamData); + if (libraryError.IsError()) + { + ThermoActiveLogger.LogError($"GetCurrentTCamData error | {libraryError.exception}"); + return BadRequest(libraryError.localizationKey); + } + + return Ok(currTCamData); + } + /// /// Resistance setup info /// @@ -386,6 +411,34 @@ namespace Thermo.Active.Controllers.WebApi // ritorno solo fatto! return Ok(); } + /// + /// Set ThermoCam On/Off + /// + /// + /// + [Route("setTCamOn"), HttpPut] + [WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.RECIPE_MANAGER, Action = ACTIONS.READ)] + public IHttpActionResult SetTCamOn(bool setTCamOn) + { + // scrive su CommandWord attivazione funzione ThermoCam + // Try connection + CmsError libraryError = ncAdapter.Connect(); + if (libraryError.IsError()) + { + ThermoActiveLogger.LogError($"NC Not connected! | setTCamOn | {libraryError.exception}"); + return BadRequest(libraryError.localizationKey); + } + // scrivo sul PLC + libraryError = ncAdapter.SetTCamActiv(setTCamOn); + if (libraryError.IsError()) + { + ThermoActiveLogger.LogError($"setTCamOn error | {libraryError.exception}"); + return BadRequest(libraryError.localizationKey); + } + + // ritorno solo fatto! + return Ok(); + } /// /// Simulate Flir image req from PLC