From 5ad7b7990c58d1e859517b59ea0047ce4ae1f7be Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Wed, 3 Feb 2021 19:04:40 +0100 Subject: [PATCH] inizio lettura da PLC (da testare!!!) --- ...DTOChannelsIOModel.cs => DTOChannelsIO.cs} | 2 +- .../Thermo.Active.Model.csproj | 2 +- Thermo.Active.NC/NcAdapter.cs | 73 +++++++++++++++++-- .../WebApi/UnderTheHoodController.cs | 27 ++++++- 4 files changed, 95 insertions(+), 9 deletions(-) rename Thermo.Active.Model/DTOModels/ThIO/{DTOChannelsIOModel.cs => DTOChannelsIO.cs} (99%) diff --git a/Thermo.Active.Model/DTOModels/ThIO/DTOChannelsIOModel.cs b/Thermo.Active.Model/DTOModels/ThIO/DTOChannelsIO.cs similarity index 99% rename from Thermo.Active.Model/DTOModels/ThIO/DTOChannelsIOModel.cs rename to Thermo.Active.Model/DTOModels/ThIO/DTOChannelsIO.cs index 5e62404b..24571013 100644 --- a/Thermo.Active.Model/DTOModels/ThIO/DTOChannelsIOModel.cs +++ b/Thermo.Active.Model/DTOModels/ThIO/DTOChannelsIO.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Thermo.Active.Model.DTOModels.ThIO { - public class DTOChannelsIOModel + public class DTOChannelsIO { public List DI { get; set; } public List DO { get; set; } diff --git a/Thermo.Active.Model/Thermo.Active.Model.csproj b/Thermo.Active.Model/Thermo.Active.Model.csproj index 3e779827..24c9a727 100644 --- a/Thermo.Active.Model/Thermo.Active.Model.csproj +++ b/Thermo.Active.Model/Thermo.Active.Model.csproj @@ -113,7 +113,7 @@ - + diff --git a/Thermo.Active.NC/NcAdapter.cs b/Thermo.Active.NC/NcAdapter.cs index 109647a9..e7368c6b 100644 --- a/Thermo.Active.NC/NcAdapter.cs +++ b/Thermo.Active.NC/NcAdapter.cs @@ -14,6 +14,7 @@ using Thermo.Active.Model.DTOModels.AlarmModels; using Thermo.Active.Model.DTOModels.MaintenanceModels; using Thermo.Active.Model.DTOModels.Scada; using Thermo.Active.Model.DTOModels.ThAxes; +using Thermo.Active.Model.DTOModels.ThIO; using Thermo.Active.Model.DTOModels.ThModules; using Thermo.Active.Model.DTOModels.ThProd; using Thermo.Active.Model.DTOModels.ThRecipe; @@ -2168,18 +2169,79 @@ namespace Thermo.Active.NC } - public CmsError ReadIO(out Dictionary currModules) + public CmsError ReadIO(out DTOChannelsIO currChannelsIO) { CmsError libraryError = NO_ERROR; - currModules = new Dictionary(); - DTOModulesBlock currVal = new DTOModulesBlock(); + currChannelsIO = new DTOChannelsIO(); // read and return warmers data if (NcConfig.NcVendor == NC_VENDOR.S7NET) { + // lettura da PLC Dictionary currModBlock = new Dictionary(); - libraryError = numericalControl.PLC_RModulesBlockList(false, ref currModBlock); + ThermoModels.ChanIOVis currThermoIOVis = new ThermoModels.ChanIOVis(); + ThermoModels.ChanIOVal currThermoIOVal = new ThermoModels.ChanIOVal(); + ThermoModels.ChanIOFor currThermoIOFor = new ThermoModels.ChanIOFor(); + ThermoModels.ChanIOValFor currThermoIOValFor = new ThermoModels.ChanIOValFor(); + libraryError = numericalControl.PLC_RIOChannels(false, ref currThermoIOVis, ref currThermoIOVal, ref currThermoIOFor, ref currThermoIOValFor); + // setup da config + List listDI = IOConfig.Where(x => x.Category == Model.Constants.TACT_IO_TYPE.DI).Select(x => new DigitalIN() + { + Id = x.Id, + Bank = x.Bank, + Position = x.Position, + //Page = x.Category.ToString(), + Page = x.Page, + Wire = x.Wire, + Profinet = x.Profinet, + Label = x.Label.Replace("__", "_").Replace("__", "_").ToLower(), + Visible = currThermoIOVis.DI[x.Id] + }).ToList(); + List listDO = IOConfig.Where(x => x.Category == Model.Constants.TACT_IO_TYPE.DO).Select(x => new DigitalOUT() + { + Id = x.Id, + Bank = x.Bank, + Position = x.Position, + //Page = x.Category.ToString(), + Page = x.Page, + Wire = x.Wire, + Profinet = x.Profinet, + Label = x.Label.Replace("__", "_").Replace("__", "_").ToLower(), + Visible = currThermoIOVis.DO[x.Id] + }).ToList(); + List listAI = IOConfig.Where(x => x.Category == Model.Constants.TACT_IO_TYPE.AI).Select(x => new AnalogIN() + { + Id = x.Id, + Bank = x.Bank, + Position = x.Position, + //Page = x.Category.ToString(), + Page = x.Page, + Wire = x.Wire, + Profinet = x.Profinet, + Label = x.Label.Replace("__", "_").Replace("__", "_").ToLower(), + Visible = currThermoIOVis.AI[x.Id] + }).ToList(); + List listAO = IOConfig.Where(x => x.Category == Model.Constants.TACT_IO_TYPE.AO).Select(x => new AnalogOUT() + { + Id = x.Id, + Bank = x.Bank, + Position = x.Position, + //Page = x.Category.ToString(), + Page = x.Page, + Wire = x.Wire, + Profinet = x.Profinet, + Label = x.Label.Replace("__", "_").Replace("__", "_").ToLower(), + Visible = currThermoIOVis.AO[x.Id] + }).ToList(); + + // assegno! + currChannelsIO.DI = listDI; + currChannelsIO.DO = listDO; + currChannelsIO.AI = listAI; + currChannelsIO.AO = listAO; + +#if false foreach (var item in ModBlockConfig) { try @@ -2213,7 +2275,8 @@ namespace Thermo.Active.NC } catch { } - } + } +#endif } return libraryError; } diff --git a/Thermo.Active/Controllers/WebApi/UnderTheHoodController.cs b/Thermo.Active/Controllers/WebApi/UnderTheHoodController.cs index 07c7451f..bd664ba9 100644 --- a/Thermo.Active/Controllers/WebApi/UnderTheHoodController.cs +++ b/Thermo.Active/Controllers/WebApi/UnderTheHoodController.cs @@ -57,7 +57,29 @@ namespace Thermo.Active.Controllers.WebApi [Route("channels_io"), HttpGet] public IHttpActionResult GetChannelsIO() { - DTOChannelsIOModel ChannelsIO = new DTOChannelsIOModel(); + // Try connection + CmsError libraryError = ncAdapter.Connect(); + if (libraryError.IsError()) + { + ThermoActiveLogger.LogError($"NC Not connected! | GetChannelsIO | {libraryError.exception}"); + return BadRequest(libraryError.localizationKey); + } + + // leggo dati gauges + libraryError = ncAdapter.ReadIO(out DTOChannelsIO ChannelsIO); + if (libraryError.IsError()) + { + ThermoActiveLogger.LogError($"GetChannelsIO error | {libraryError.exception}"); + return BadRequest(libraryError.localizationKey); + } + + // ritorno solo fatto! + return Ok(ChannelsIO); +#if false + + + + DTOChannelsIO ChannelsIO = new DTOChannelsIO(); // leggo i 4 tipi di oggetti e popolo List listDI = IOConfig.Where(x => x.Category == Model.Constants.TACT_IO_TYPE.DI).Select(x => new DigitalIN() { @@ -111,7 +133,8 @@ namespace Thermo.Active.Controllers.WebApi ChannelsIO.AO = listAO; // restituisco - return Ok(ChannelsIO); + return Ok(ChannelsIO); +#endif } } } \ No newline at end of file