fix cyclelogData
This commit is contained in:
+43
-109
@@ -56,10 +56,16 @@ namespace Thermo.Active.NC
|
||||
protected static Dictionary<int, DTOAxisInfoModel> lastAxisData = new Dictionary<int, DTOAxisInfoModel>();
|
||||
|
||||
/// <summary>
|
||||
/// Last recipe data from PLCINFO data from PLC
|
||||
/// Last AxisInfo data from PLC
|
||||
/// </summary>
|
||||
protected static Dictionary<int, ThermoModels.AxisInfo> lastAxisInfoReadData = new Dictionary<int, ThermoModels.AxisInfo>();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Last LogCycle data from PLC
|
||||
/// </summary>
|
||||
protected static Dictionary<DateTime, int> lastLogCycleData = new Dictionary<DateTime, int>();
|
||||
|
||||
/// <summary>
|
||||
/// Last prod info from PLC
|
||||
/// </summary>
|
||||
@@ -508,132 +514,60 @@ namespace Thermo.Active.NC
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Legge dal PLC elenco di eventi LOG del ciclo e li presenta
|
||||
/// Restituisce elenco di eventi LOG del ciclo
|
||||
/// </summary>
|
||||
/// <param name="doRefresh">Ricarica da PLC il cycle log o rilegge solamente</param>
|
||||
/// <param name="machineLog">Oggetto elenco elementi LOG registrati da macchina</param>
|
||||
/// <returns></returns>
|
||||
public CmsError GetCycleLog(bool doRefresh, out Dictionary<DateTime, int> machineLog)
|
||||
{
|
||||
CmsError libraryError = NO_ERROR;
|
||||
|
||||
if (doRefresh)
|
||||
{
|
||||
// chiama refresh
|
||||
RefreshCycleLog();
|
||||
}
|
||||
machineLog = lastLogCycleData;
|
||||
// restituisco cod errore se trovato
|
||||
return libraryError;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Legge dal PLC elenco di eventi LOG del ciclo e li salva in memoria
|
||||
/// </summary>
|
||||
/// <param name="machineLog">Oggetto elenco elementi LOG registrati da macchina</param>
|
||||
/// <returns></returns>
|
||||
public CmsError GetCycleLog(out Dictionary<DateTime, int> machineLog)
|
||||
public CmsError RefreshCycleLog()
|
||||
{
|
||||
CmsError libraryError = NO_ERROR;
|
||||
machineLog = new Dictionary<DateTime, int>();
|
||||
Dictionary<DateTime, int> machineLog = new Dictionary<DateTime, int>();
|
||||
|
||||
if (false)
|
||||
// recupero l'oggetto dall'NC...
|
||||
List<ThermoModels.LogCycleData> currLogCycleData = new List<ThermoModels.LogCycleData>();
|
||||
// get LogCycle Data
|
||||
libraryError = numericalControl.PLC_RLogCycleData(out currLogCycleData);
|
||||
// effettuo traduzione e riordino
|
||||
foreach (var item in currLogCycleData.OrderByDescending(i => i.DtEvent))
|
||||
{
|
||||
// recupero l'oggetto dall'NC
|
||||
|
||||
// effettuo traduzione
|
||||
#if false
|
||||
// overview di base: ultima salvata...
|
||||
var err2fix = new Dictionary<RecipeSection, RecipeCatStatus>();
|
||||
|
||||
// leggo la ricetta dal PLC!
|
||||
var currRecipe = new Dictionary<string, DTORecipeParam>();
|
||||
libraryError = ReadFullRecipe(out currRecipe);
|
||||
if (libraryError.IsError())
|
||||
return libraryError;
|
||||
|
||||
// leggo l'intero array delle DB... QUI FAKE sulle DB configurate...
|
||||
List<DTORecipeConfigModel> recipeConfig = RecipeConfig.Select(x => new DTORecipeConfigModel()
|
||||
{
|
||||
Id = x.Id,
|
||||
ScaleFactor = x.ScaleFactor,
|
||||
NumDec = x.NumDec,
|
||||
Category = x.Category.ToString(),
|
||||
SubCategory_1 = x.SubCategory_1,
|
||||
SubCategory_2 = x.SubCategory_2,
|
||||
Name = x.Name,
|
||||
Description = x.Description,
|
||||
Format = x.Format,
|
||||
Label = $"{x.Category}_{x.SubCategory_1}_{x.SubCategory_2}_{x.Name}".Replace("__", "_").Replace("__", "_").ToLower(),
|
||||
EnumVal = x.EnumVal
|
||||
}).ToList();
|
||||
|
||||
RecipeCatStatus currStatus = RecipeCatStatus.Unchanged;
|
||||
|
||||
// da conf ricetta --> se ci sono li leggo da li...
|
||||
if (NcFileAdapter.RecipeLiveData.RecipeOverview != null)
|
||||
{
|
||||
currOverview = NcFileAdapter.RecipeLiveData.RecipeOverview;
|
||||
}
|
||||
|
||||
// verifico eventualmente se mancasse qualcosa...
|
||||
bool changed = false;
|
||||
foreach (var item in recipeConfig)
|
||||
{
|
||||
if (!currOverview.ContainsKey(getRecipeSection(item.Category)))
|
||||
if (machineLog.ContainsKey(item.DtEvent))
|
||||
{
|
||||
currOverview.Add(getRecipeSection(item.Category), RecipeCatStatus.Unchanged);
|
||||
changed = true;
|
||||
machineLog[item.DtEvent] = item.Code;
|
||||
}
|
||||
}
|
||||
|
||||
// ricerco SE co fossero errori --> reset come changedOK
|
||||
foreach (var item in currOverview)
|
||||
{
|
||||
if (item.Value == RecipeCatStatus.HasError)
|
||||
err2fix.Add(item.Key, RecipeCatStatus.ChangedOk);
|
||||
}
|
||||
foreach (var item in err2fix)
|
||||
{
|
||||
currOverview[item.Key] = item.Value;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
// se cambiato --> salvo in live data...
|
||||
if (changed)
|
||||
{
|
||||
NcFileAdapter.RecipeLiveData.RecipeOverview = currOverview;
|
||||
}
|
||||
|
||||
// ORA percorro conf ricetta x cercare eventuali ERRORI......
|
||||
foreach (var item in recipeConfig)
|
||||
{
|
||||
currStatus = currOverview[getRecipeSection(item.Category)];
|
||||
|
||||
// se lo stato è errore --> esco...
|
||||
if (currStatus == RecipeCatStatus.HasError)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
// altrimenti controllo
|
||||
else
|
||||
{
|
||||
// se in errore AND visibile --> registro...
|
||||
bool checkCondition = false;
|
||||
checkCondition = (currRecipe[item.Label].Status.HasError);
|
||||
// 2020.07.29 - controllo condizione secondo status debug/release...
|
||||
if (checkCondition)
|
||||
{
|
||||
currOverview[getRecipeSection(item.Category)] = RecipeCatStatus.HasError;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
// altrimenti genero FAKE data
|
||||
else
|
||||
{
|
||||
int eventVal = 0;
|
||||
DateTime eventDate = DateTime.Now;
|
||||
// genero random eventi da 1..maxEvent
|
||||
Random rndGen = new Random();
|
||||
int maxEvent = 16;
|
||||
int maxDelay = 30000;
|
||||
for (int i = 0; i < 1024; i++)
|
||||
{
|
||||
// calcolo nuovo evento
|
||||
eventVal = rndGen.Next(maxEvent);
|
||||
// calcolo tempo anticipato
|
||||
eventDate = eventDate.AddMilliseconds(-rndGen.Next(maxDelay));
|
||||
//salvo
|
||||
machineLog.Add(eventDate, eventVal);
|
||||
machineLog.Add(item.DtEvent, item.Code);
|
||||
}
|
||||
}
|
||||
// salvo
|
||||
lastLogCycleData = machineLog;
|
||||
|
||||
|
||||
// restituisco cod errore se trovato
|
||||
return libraryError;
|
||||
}
|
||||
|
||||
|
||||
public CmsError GetExpiredMaintenances(out List<DTOExpiredMaintenanceModel> expiredMaintenance)
|
||||
{
|
||||
// Return value
|
||||
|
||||
@@ -35,11 +35,32 @@ namespace Thermo.Active.Controllers.WebApi
|
||||
/// </summary>
|
||||
protected static NcAdapter ncAdapter = new NcAdapter();
|
||||
|
||||
[ResponseType(typeof(DTOCycleLog))]
|
||||
[Route("cycleLogRefresh"), HttpGet]
|
||||
public IHttpActionResult RefreshCycleLog()
|
||||
{
|
||||
// Try connection
|
||||
CmsError libraryError = ncAdapter.Connect();
|
||||
if (libraryError.IsError())
|
||||
{
|
||||
ThermoActiveLogger.LogError($"ncAdapter Not connected! | RefreshCycleLog | {libraryError.exception}");
|
||||
}
|
||||
|
||||
libraryError = ncAdapter.RefreshCycleLog();
|
||||
if (libraryError.IsError())
|
||||
{
|
||||
ThermoActiveLogger.LogError($"RefreshCycleLog error | {libraryError.exception}");
|
||||
return BadRequest(libraryError.localizationKey);
|
||||
}
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[ResponseType(typeof(DTOCycleLog))]
|
||||
[Route("cyclelog"), HttpGet]
|
||||
public IHttpActionResult GetCycleLog()
|
||||
{
|
||||
// // Try connection
|
||||
// Try connection
|
||||
CmsError libraryError = ncAdapter.Connect();
|
||||
DTOCycleLog currCycleLog = new DTOCycleLog();
|
||||
|
||||
@@ -48,7 +69,7 @@ namespace Thermo.Active.Controllers.WebApi
|
||||
ThermoActiveLogger.LogError($"ncAdapter Not connected! | GetCycleLog | {libraryError.exception}");
|
||||
}
|
||||
|
||||
libraryError = ncAdapter.GetCycleLog(out Dictionary<DateTime, int> cycleLog);
|
||||
libraryError = ncAdapter.GetCycleLog(true, out Dictionary<DateTime, int> cycleLog);
|
||||
foreach (var item in cycleLog)
|
||||
{
|
||||
currCycleLog.events.Add(new CycleEvent() { dtEvent=item.Key, code=item.Value });
|
||||
|
||||
Reference in New Issue
Block a user