inizio lettura da PLC (da testare!!!)

This commit is contained in:
Samuele E. Locatelli
2021-02-03 19:04:40 +01:00
parent e77887153d
commit 5ad7b7990c
4 changed files with 95 additions and 9 deletions
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace Thermo.Active.Model.DTOModels.ThIO
{
public class DTOChannelsIOModel
public class DTOChannelsIO
{
public List<DigitalIN> DI { get; set; }
public List<DigitalOUT> DO { get; set; }
@@ -113,7 +113,7 @@
<Compile Include="DTOModels\DTOM156InputModel.cs" />
<Compile Include="DTOModels\DTOMessageModel.cs" />
<Compile Include="DTOModels\ThAxes\DTOAxisInfoModel.cs" />
<Compile Include="DTOModels\ThIO\DTOChannelsIOModel.cs" />
<Compile Include="DTOModels\ThIO\DTOChannelsIO.cs" />
<Compile Include="DTOModels\ThModules\DTOModulesBlock.cs" />
<Compile Include="DTOModels\ThProd\DTOProdInfo.cs" />
<Compile Include="DTOModels\ThProd\DTOThermoPanelProd.cs" />
+68 -5
View File
@@ -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<int, DTOModulesBlock> currModules)
public CmsError ReadIO(out DTOChannelsIO currChannelsIO)
{
CmsError libraryError = NO_ERROR;
currModules = new Dictionary<int, DTOModulesBlock>();
DTOModulesBlock currVal = new DTOModulesBlock();
currChannelsIO = new DTOChannelsIO();
// read and return warmers data
if (NcConfig.NcVendor == NC_VENDOR.S7NET)
{
// lettura da PLC
Dictionary<int, ThermoModels.ModuleBlock> currModBlock = new Dictionary<int, ThermoModels.ModuleBlock>();
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<DigitalIN> 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<DigitalOUT> 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<AnalogIN> 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<AnalogOUT> 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;
}
@@ -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<DigitalIN> 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
}
}
}