Proseguo configurazione livelli di accesso dati ThermoCam + refactor

This commit is contained in:
Samuele Locatelli
2020-10-23 19:51:07 +02:00
parent b7984023f9
commit fad3c82b46
5 changed files with 976 additions and 951 deletions
+7 -1
View File
@@ -803,6 +803,8 @@ public static class ThreadsFunctions
if (libraryError.errorCode != 0)
ManageLibraryError(libraryError);
int readCount = 0;
bool useCache = false;
while (true)
{
sw.Restart();
@@ -810,12 +812,16 @@ public static class ThreadsFunctions
// Check if client is connected
if (ncAdapter.numericalControl.NC_IsConnected())
{
// every 10 reads all data...
useCache = (readCount == 0);
// Get new data from PLC
libraryError = ncAdapter.ReadWarmers(out Dictionary<int, DTOWarmers> currWarmers);
libraryError = ncAdapter.ReadWarmers(useCache, out Dictionary<int, DTOWarmers> currWarmers);
if (libraryError.IsError())
ManageLibraryError(libraryError);
// pubblico
MessageServices.Current.Publish(SEND_THERMO_WARMERS_DATA, null, currWarmers);
readCount++;
readCount = readCount % 10;
}
else
RestoreConnection();
@@ -2,6 +2,20 @@
{
public class DTOWarmers
{
#region Properties
/// <summary>
/// Actual value of current on channel
/// </summary>
public double ActualCurrent { get; set; } = 0;
/// <summary>
/// Actual value of channel (%)
/// </summary>
public int ActualPerc { get; set; } = 0;
/// <summary>
/// Channel status
/// </summary>
public int ChannelStatus { get; set; } = 0;
/// <summary>
/// Channel Unique ID (from risk2007)
/// </summary>
@@ -11,48 +25,80 @@
/// </summary>
public int IdReflector { get; set; } = 0;
/// <summary>
/// Max power for channel (W)
/// </summary>
public int MaxPower { get; set; } = 0;
/// <summary>
/// Setpoint from HMI (%)
/// </summary>
public int SetpointHMI { get; set; } = 0;
public int SetpointTermocam { get; set; } = 0;
/// <summary>
/// Setpoint from PLC (%)
/// </summary>
public int SetpointPLC { get; set; } = 0;
public int ChannelStatus { get; set; } = 0;
public double ActualCurrent { get; set; } = 0;
public int ActualPerc { get; set; } = 0;
public int MaxPower { get; set; } = 0;
/// <summary>
/// Define if camera is active for channel
/// </summary>
public bool ThermocamActive { get; set; } = false;
/// <summary>
/// Actual value from last ThermoCam image acquisition (° Celsius)
/// </summary>
public double ThermocamActualTemp { get; set; } = 0;
/// <summary>
/// Setpoint from HMI (° Celsius)
/// </summary>
public double ThermocamSetpointTemp { get; set; } = 0;
#endregion Properties
#region Methods
/// <summary>
/// Equality test for class object
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public override bool Equals(object obj)
{
if (!(obj is DTOWarmers item))
return false;
if (IdChannel != item.IdChannel)
return false;
if (IdReflector != item.IdReflector)
return false;
if (SetpointHMI != item.SetpointHMI)
return false;
if (SetpointTermocam != item.SetpointTermocam)
return false;
if (SetpointPLC != item.SetpointPLC)
return false;
if (ChannelStatus != item.ChannelStatus)
return false;
if (ActualCurrent != item.ActualCurrent)
return false;
if (ActualPerc != item.ActualPerc)
return false;
if (ChannelStatus != item.ChannelStatus)
return false;
if (IdChannel != item.IdChannel)
return false;
if (IdReflector != item.IdReflector)
return false;
if (MaxPower != item.MaxPower)
return false;
if (SetpointHMI != item.SetpointHMI)
return false;
if (SetpointPLC != item.SetpointPLC)
return false;
if (ThermocamActive != item.ThermocamActive)
return false;
if (ThermocamActualTemp != item.ThermocamActualTemp)
return false;
if (ThermocamSetpointTemp != item.ThermocamSetpointTemp)
return false;
return true;
}
/// <summary>
/// Hash gen
/// </summary>
/// <returns></returns>
public override int GetHashCode()
{
return base.GetHashCode();
}
#endregion Methods
}
}
+46 -119
View File
@@ -739,50 +739,6 @@ namespace Thermo.Active.NC
}
}
#if false
// Read selected axes
libraryError = numericalControl.AXES_RSelectedAxis(ref processesData.SelectedAxis);
if (libraryError.IsError())
return libraryError;
QueueStatusModel queueStatus = new QueueStatusModel();
// Get queue data
libraryError = numericalControl.FILES_RQueueDataByProcess(ref queueStatus, processesData.SelectedProcess);
if (libraryError.IsError())
return libraryError;
// Get selectedProcessData
SelectedProcessData selectedData = new SelectedProcessData();
libraryError = numericalControl.PROC_RSelectedProcessData(processesData.SelectedProcess, ref selectedData);
if (libraryError.IsError())
return libraryError;
String UMeas = "mm";
// Get process status
libraryError = numericalControl.NC_RUnitOfMeasure(ref UMeas);
if (libraryError.IsError())
return libraryError;
// Set data
processesData.QueueStatus = queueStatus.Status;
processesData.StartStopQueueEnabled = queueStatus.StartStopQueueEnabled;
// Selected process data
processesData.ActiveOrigin = selectedData.Origin;
processesData.ActiveOffsetId = selectedData.ActiveOffsetId;
processesData.ProcessMessage = selectedData.ProcessMessage;
// Overrides
processesData.RapidOverride = selectedData.RapidOverride;
processesData.WorkOverride = selectedData.WorkOverride;
processesData.offsetData = selectedData.OffsetData;
// Measure
processesData.UnitMeasure = UMeas;
processesData.FeedOverride = selectedData.FeedOverride;
#endif
return libraryError;
}
@@ -2110,48 +2066,7 @@ namespace Thermo.Active.NC
return NO_ERROR;
}
/// <summary>
/// Vero metodo lettura Warmers data da memoria PLC
/// </summary>
/// <param name="currentWarmers"></param>
/// <returns></returns>
public CmsError ReadWarmersData(out Dictionary<int, DTOWarmers> currentWarmers)
{
// init obj
currentWarmers = new Dictionary<int, DTOWarmers>();
// solo x S7...
if (NcConfig.NcVendor == NC_VENDOR.S7NET)
{
CmsError libraryError = NO_ERROR;
// leggo stato ricetta da PLC
Dictionary<int, ThermoModels.WarmerChannel> currPlcWarmers = new Dictionary<int, ThermoModels.WarmerChannel>();
libraryError = numericalControl.PLC_RWarmerChannelList(ref currPlcWarmers);
if (libraryError.IsError())
return libraryError;
// compongo con il resto delle info da config... do x scontato di avere TUTIT i 1024 channels
List<DTOWarmers> warmersConfig = RiskChannelConfig.Select(x => new DTOWarmers()
{
IdChannel = x.IdChannel,
IdReflector = x.IdReflector,
SetpointHMI = x.SetpointRecipe,
SetpointTermocam = 0, // FIXME TODO x.SetpointTer,
SetpointPLC = currPlcWarmers[x.IdChannel].SetpointPLC,
ChannelStatus = currPlcWarmers[x.IdChannel].ChStatus,
ActualCurrent = currPlcWarmers[x.IdChannel].CurrAct,
ActualPerc = currPlcWarmers[x.IdChannel].PercAct,
MaxPower = x.MaxPower
}).ToList();
}
else
{
currentWarmers = new Dictionary<int, DTOWarmers>();
}
return NO_ERROR;
}
/// <summary>
/// Gestione strobe richiesta cambio modo
/// </summary>
@@ -2783,49 +2698,50 @@ namespace Thermo.Active.NC
}
/// <summary>
/// GEt all warmers data by channel
/// Get all warmers data by channel
/// </summary>
/// <param name="useCache">if true uises cached data, if false reads from PLC</param>
/// <param name="currWarmers">List of <= 1024 warmers channels</param>
/// <returns></returns>
public CmsError ReadWarmers(out Dictionary<int, DTOWarmers> currWarmers)
public CmsError ReadWarmers(bool useCache, out Dictionary<int, DTOWarmers> currWarmers)
{
CmsError libraryError = NO_ERROR;
currWarmers = new Dictionary<int, DTOWarmers>();
DTOWarmers currVal = new DTOWarmers();
// read and return warmers data
// solo x S7...
if (NcConfig.NcVendor == NC_VENDOR.S7NET)
{
Dictionary<int, ThermoModels.WarmerChannel> currPlcWarmChan = new Dictionary<int, ThermoModels.WarmerChannel>();
libraryError = numericalControl.PLC_RWarmerChannelList(ref currPlcWarmChan);
// leggo stato ricetta da PLC
Dictionary<int, ThermoModels.WarmerChannel> currPlcWarmers = new Dictionary<int, ThermoModels.WarmerChannel>();
libraryError = numericalControl.PLC_RWarmerChannelList(ref currPlcWarmers);
foreach (var item in RiskChannelConfig)
if (libraryError.IsError())
return libraryError;
try
{
try
// compongo con il resto delle info da config... do x scontato di avere TUTIT i 1024 channels
List<DTOWarmers> warmersConfig = RiskChannelConfig.Select(x => new DTOWarmers()
{
ThermoModels.WarmerChannel currWarm = currPlcWarmChan[item.IdChannel];
currVal = new DTOWarmers()
{
IdChannel = item.IdChannel,
IdReflector = item.IdReflector,
SetpointHMI = currWarm.SetpointHMI,
SetpointTermocam = currWarm.SetpointThermoCam,
SetpointPLC = currWarm.SetpointPLC,
ChannelStatus = currWarm.ChStatus,
ActualCurrent = currWarm.CurrAct,
ActualPerc = currWarm.PercAct,
MaxPower = item.MaxPower
};
currWarmers.Add(item.IdChannel, currVal);
}
catch
{ }
IdChannel = x.IdChannel,
IdReflector = x.IdReflector,
//SetpointHMI = x.SetpointRecipe,
SetpointHMI = currPlcWarmers[x.IdChannel].SetpointHMI,
ThermocamActive = currPlcWarmers[x.IdChannel].ThermocamActive,
ThermocamActualTemp = currPlcWarmers[x.IdChannel].ThermocamActualTemp,
ThermocamSetpointTemp = currPlcWarmers[x.IdChannel].ThermocamSetpoint,
SetpointPLC = currPlcWarmers[x.IdChannel].SetpointPLC,
ChannelStatus = currPlcWarmers[x.IdChannel].ChStatus,
ActualCurrent = currPlcWarmers[x.IdChannel].CurrAct,
ActualPerc = currPlcWarmers[x.IdChannel].PercAct,
MaxPower = x.MaxPower
}).ToList();
}
catch
{ }
}
else
{
currWarmers = new Dictionary<int, DTOWarmers>();
}
// gestione errore
if (libraryError.IsError())
return libraryError;
// restituisco cod errore se trovato
return libraryError;
@@ -2906,13 +2822,24 @@ namespace Thermo.Active.NC
return libraryError;
}
/// <summary>
/// Write all warmers termocam data for recipe
/// Write all warmers termocam TEMP data for reference
/// </summary>
/// <param name="updtSetpTCam">Oggetto parametri da aggiornare (from HMI)</param>
/// <param name="referenceTemp">Oggetto temperature canali da aggiornare (from HMI) come reference</param>
/// <returns></returns>
public CmsError WriteRecipeWarmChSetpTermoCam(Dictionary<int, int> updtSetpTCam)
public CmsError WriteRecipeWarmChSetpThermoCam(Dictionary<int, double> referenceTemp)
{
CmsError libraryError = numericalControl.PLC_WWarmerChSetpTCam(updtSetpTCam);
CmsError libraryError = numericalControl.PLC_WWarmerChTCamSetp(referenceTemp);
return libraryError;
}
/// <summary>
/// Write all warmers ACTUAL termocam TEMP data
/// </summary>
/// <param name="actualTemp">Oggetto temperature canali letto da ThermoCam</param>
/// <returns></returns>
public CmsError WriteRecipeWarmChThermoCamActual(Dictionary<int, double> actualTemp)
{
CmsError libraryError = numericalControl.PLC_WWarmerChTCamActual(actualTemp);
return libraryError;
}
File diff suppressed because it is too large Load Diff
@@ -14,11 +14,129 @@ namespace Thermo.Active.Controllers.WebApi
[RoutePrefix("api/warmers")]
public class WarmersController : ApiController
{
#region Fields
/// <summary>
/// Oggetto adapter condiviso da WebAPI
/// </summary>
protected static NcAdapter ncAdapter = new NcAdapter();
#endregion Fields
#region Methods
/// <summary>
/// Cancel recipe modification (parameters: PLC --> HMI)
/// </summary>
/// <returns></returns>
[Route("cancel"), HttpPut]
[WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.RECIPE_MANAGER, Action = ACTIONS.READ)]
public IHttpActionResult CancelEdit()
{
// Try connection
CmsError libraryError = ncAdapter.Connect();
if (libraryError.IsError())
{
ThermoActiveLogger.LogError($"NC Not connected! | Recipe CancelEdit | {libraryError.exception}");
return BadRequest(libraryError.localizationKey);
}
// scrivo sul PLC il comando annula!
libraryError = ncAdapter.ConfirmRecipeData(false);
if (libraryError.IsError())
{
ThermoActiveLogger.LogError($"Warmers CancelEdit error | ConfirmRecipeData | {libraryError.exception}");
return BadRequest(libraryError.localizationKey);
}
// recupero i dati LIVE dei parametri HMI dei riscaldi...
libraryError = ncAdapter.ReadWarmers(false, out Dictionary<int, DTOWarmers> currWarmers);
if (libraryError.IsError())
{
ThermoActiveLogger.LogError($"Warmers ConfirmEdit error | ReadWarmers | {libraryError.exception}");
return BadRequest(libraryError.localizationKey);
}
// rileggo la ricetta
var currParams = new Dictionary<int, int>();
foreach (var item in currWarmers)
{
currParams.Add(item.Key, item.Value.SetpointHMI);
}
saveCurrentRecipeWarmers(currParams);
// ritorno solo fatto!
return Ok();
}
/// <summary>
/// Confirm recipe modification (parameters: HMI --> PLC)
/// </summary>
/// <returns></returns>
[Route("confirm"), HttpPut]
[WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.RECIPE_MANAGER, Action = ACTIONS.READ)]
public IHttpActionResult ConfirmEdit()
{
// Try connection
CmsError libraryError = ncAdapter.Connect();
if (libraryError.IsError())
{
ThermoActiveLogger.LogError($"NC Not connected! | Warmers ConfirmEdit | {libraryError.exception}");
return BadRequest(libraryError.localizationKey);
}
// scrivo sul PLC il comando conferma!
libraryError = ncAdapter.ConfirmRecipeData(true);
if (libraryError.IsError())
{
ThermoActiveLogger.LogError($"Warmers ConfirmEdit error | ConfirmRecipeData | {libraryError.exception}");
return BadRequest(libraryError.localizationKey);
}
// recupero i dati LIVE dei parametri HMI dei riscaldi...
libraryError = ncAdapter.ReadWarmers(false, out Dictionary<int, DTOWarmers> currWarmers);
if (libraryError.IsError())
{
ThermoActiveLogger.LogError($"Warmers ConfirmEdit error | ReadWarmers | {libraryError.exception}");
return BadRequest(libraryError.localizationKey);
}
// rileggo la ricetta
var currParams = new Dictionary<int, int>();
foreach (var item in currWarmers)
{
currParams.Add(item.Key, item.Value.SetpointHMI);
}
saveCurrentRecipeWarmers(currParams);
// ritorno solo fatto!
return Ok();
}
[Route("area"), HttpGet]
public IHttpActionResult GetCurrentAreaPerc()
{
// Try connection
CmsError libraryError = ncAdapter.Connect();
if (libraryError.IsError())
{
ThermoActiveLogger.LogError($"NC Not connected! | GetCurrentAreaPerc | {libraryError.exception}");
return BadRequest(libraryError.localizationKey);
}
// recupera aree % X / Y
libraryError = ncAdapter.GetWarmMaterialArea(out Dictionary<string, double> currAreaPerc);
if (libraryError.IsError())
{
ThermoActiveLogger.LogError($"GetCurrentAreaPerc error | {libraryError.exception}");
return BadRequest(libraryError.localizationKey);
}
return Ok(currAreaPerc);
}
[Route("channels"), HttpGet]
public IHttpActionResult GetCurrentWarmersChannels()
{
@@ -30,7 +148,7 @@ namespace Thermo.Active.Controllers.WebApi
return BadRequest(libraryError.localizationKey);
}
libraryError = ncAdapter.ReadWarmers(out Dictionary<int, DTOWarmers> currWarmers);
libraryError = ncAdapter.ReadWarmers(false, out Dictionary<int, DTOWarmers> currWarmers);
if (libraryError.IsError())
{
ThermoActiveLogger.LogError($"GetRecipeOverview error | {libraryError.exception}");
@@ -59,29 +177,36 @@ namespace Thermo.Active.Controllers.WebApi
return Ok(currWarmers);
}
[Route("area"), HttpGet]
public IHttpActionResult GetCurrentAreaPerc()
[Route("setConfig"), HttpPut]
[WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.RECIPE_MANAGER, Action = ACTIONS.READ)]
public IHttpActionResult SetConfig()
{
// scrive configurazioni RISK
// Try connection
CmsError libraryError = ncAdapter.Connect();
if (libraryError.IsError())
{
ThermoActiveLogger.LogError($"NC Not connected! | GetCurrentAreaPerc | {libraryError.exception}");
ThermoActiveLogger.LogError($"NC Not connected! | SetConfig | {libraryError.exception}");
return BadRequest(libraryError.localizationKey);
}
// recupera aree % X / Y
libraryError = ncAdapter.GetWarmMaterialArea(out Dictionary<string, double> currAreaPerc);
// scrivo sul PLC
libraryError = ncAdapter.WriteRecipeWarmConfig();
if (libraryError.IsError())
{
ThermoActiveLogger.LogError($"GetCurrentAreaPerc error | {libraryError.exception}");
ThermoActiveLogger.LogError($"Warmers SetConfig error | WriteRecipeWarmConfig | {libraryError.exception}");
return BadRequest(libraryError.localizationKey);
}
return Ok(currAreaPerc);
// ritorno solo fatto!
return Ok();
}
/// <summary>
/// Write SetpointHMI (%)
/// </summary>
/// <param name="channelsLoad"></param>
/// <returns></returns>
[Route("update"), HttpPut]
[WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.RECIPE_MANAGER, Action = ACTIONS.READ)]
public IHttpActionResult WriteSetpoints(Dictionary<int, int> channelsLoad)
@@ -114,121 +239,40 @@ namespace Thermo.Active.Controllers.WebApi
}
/// <summary>
/// Confirm recipe modification (parameters: HMI --> PLC)
/// Write TermocamSetpoint (%)
/// </summary>
/// <param name="channelsTemp"></param>
/// <returns></returns>
[Route("confirm"), HttpPut]
[Route("updateThermocam"), HttpPut]
[WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.RECIPE_MANAGER, Action = ACTIONS.READ)]
public IHttpActionResult ConfirmEdit()
public IHttpActionResult WriteThermocamSetpoints(Dictionary<int, double> channelsTemp)
{
// Try connection
CmsError libraryError = ncAdapter.Connect();
if (libraryError.IsError())
// scrive su CHp da ricetta oppure da override x parametri utente...
if (channelsTemp != null)
{
ThermoActiveLogger.LogError($"NC Not connected! | Warmers ConfirmEdit | {libraryError.exception}");
return BadRequest(libraryError.localizationKey);
}
// Try connection
CmsError libraryError = ncAdapter.Connect();
if (libraryError.IsError())
{
ThermoActiveLogger.LogError($"NC Not connected! | WriteThermocamSetpoints | {libraryError.exception}");
return BadRequest(libraryError.localizationKey);
}
// scrivo sul PLC
libraryError = ncAdapter.WriteRecipeWarmChSetpThermoCam(channelsTemp);
if (libraryError.IsError())
{
ThermoActiveLogger.LogError($"WriteThermocamSetpoints error | {libraryError.exception}");
return BadRequest(libraryError.localizationKey);
}
// scrivo sul PLC il comando conferma!
libraryError = ncAdapter.ConfirmRecipeData(true);
if (libraryError.IsError())
// ritorno solo fatto!
return Ok();
}
else
{
ThermoActiveLogger.LogError($"Warmers ConfirmEdit error | ConfirmRecipeData | {libraryError.exception}");
return BadRequest(libraryError.localizationKey);
return NotFound();
}
// recupero i dati LIVE dei parametri HMI dei riscaldi...
libraryError = ncAdapter.ReadWarmers(out Dictionary<int, DTOWarmers> currWarmers);
if (libraryError.IsError())
{
ThermoActiveLogger.LogError($"Warmers ConfirmEdit error | ReadWarmers | {libraryError.exception}");
return BadRequest(libraryError.localizationKey);
}
// rileggo la ricetta
var currParams = new Dictionary<int, int>();
foreach (var item in currWarmers)
{
currParams.Add(item.Key, item.Value.SetpointHMI);
}
saveCurrentRecipeWarmers(currParams);
// ritorno solo fatto!
return Ok();
}
/// <summary>
/// Cancel recipe modification (parameters: PLC --> HMI)
/// </summary>
/// <returns></returns>
[Route("cancel"), HttpPut]
[WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.RECIPE_MANAGER, Action = ACTIONS.READ)]
public IHttpActionResult CancelEdit()
{
// Try connection
CmsError libraryError = ncAdapter.Connect();
if (libraryError.IsError())
{
ThermoActiveLogger.LogError($"NC Not connected! | Recipe CancelEdit | {libraryError.exception}");
return BadRequest(libraryError.localizationKey);
}
// scrivo sul PLC il comando annula!
libraryError = ncAdapter.ConfirmRecipeData(false);
if (libraryError.IsError())
{
ThermoActiveLogger.LogError($"Warmers CancelEdit error | ConfirmRecipeData | {libraryError.exception}");
return BadRequest(libraryError.localizationKey);
}
// recupero i dati LIVE dei parametri HMI dei riscaldi...
libraryError = ncAdapter.ReadWarmers(out Dictionary<int, DTOWarmers> currWarmers);
if (libraryError.IsError())
{
ThermoActiveLogger.LogError($"Warmers ConfirmEdit error | ReadWarmers | {libraryError.exception}");
return BadRequest(libraryError.localizationKey);
}
// rileggo la ricetta
var currParams = new Dictionary<int, int>();
foreach (var item in currWarmers)
{
currParams.Add(item.Key, item.Value.SetpointHMI);
}
saveCurrentRecipeWarmers(currParams);
// ritorno solo fatto!
return Ok();
}
[Route("setConfig"), HttpPut]
[WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.RECIPE_MANAGER, Action = ACTIONS.READ)]
public IHttpActionResult SetConfig()
{
// scrive configurazioni RISK
// Try connection
CmsError libraryError = ncAdapter.Connect();
if (libraryError.IsError())
{
ThermoActiveLogger.LogError($"NC Not connected! | SetConfig | {libraryError.exception}");
return BadRequest(libraryError.localizationKey);
}
// scrivo sul PLC
libraryError = ncAdapter.WriteRecipeWarmConfig();
if (libraryError.IsError())
{
ThermoActiveLogger.LogError($"Warmers SetConfig error | WriteRecipeWarmConfig | {libraryError.exception}");
return BadRequest(libraryError.localizationKey);
}
// ritorno solo fatto!
return Ok();
}
/// <summary>
/// Do actual recipe warmers setpoints FileSave
/// </summary>
@@ -247,5 +291,7 @@ namespace Thermo.Active.Controllers.WebApi
ThermoActiveLogger.LogError($"Warmers | SaveCurrentRecipeParams exception | {exc}");
}
}
#endregion Methods
}
}