From bdc0ce1aa571d97daad2dee5bb5ecfa80ef0be25 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 8 Jun 2020 22:30:37 +0200 Subject: [PATCH] Added method for Prod Info & Cycle data read --- Thermo.Active.Core/ThreadsFunctions.cs | 88 +++++++++++++++++++ Thermo.Active.Core/ThreadsHandler.cs | 8 +- Thermo.Active.Model/Constants.cs | 2 + Thermo.Active.NC/NcAdapter.cs | 14 +++ Thermo.Active/Listeners/ListenersHandler.cs | 12 ++- .../Listeners/SignalR/SignalRListener.cs | 4 +- 6 files changed, 119 insertions(+), 9 deletions(-) diff --git a/Thermo.Active.Core/ThreadsFunctions.cs b/Thermo.Active.Core/ThreadsFunctions.cs index cf558517..47b10f28 100644 --- a/Thermo.Active.Core/ThreadsFunctions.cs +++ b/Thermo.Active.Core/ThreadsFunctions.cs @@ -694,6 +694,94 @@ public static class ThreadsFunctions ncAdapter.Dispose(); } } + public static void ReadProdInfoData() + { + NcAdapter ncAdapter = new NcAdapter(); + Stopwatch sw = new Stopwatch(); + + try + { + // Try connection + CmsError libraryError = ncAdapter.Connect(); + if (libraryError.errorCode != 0) + ManageLibraryError(libraryError); + + while (true) + { + sw.Restart(); + + // Check if client is connected + if (ncAdapter.numericalControl.NC_IsConnected()) + { + + // Get new data from PLC + libraryError = ncAdapter.ReadProdInfoData(out ThermoModels.ProdInfoModel prodInfoData); + if (libraryError.IsError()) + ManageLibraryError(libraryError); + + MessageServices.Current.Publish(SEND_THERMO_PROD_INFO_DATA, null, prodInfoData); + } + else + RestoreConnection(); + + sw.Stop(); + + //Update thread timer + UpdateStat(MethodBase.GetCurrentMethod().Name, sw.ElapsedMilliseconds); + // Wait + Thread.Sleep(CalcSleepTime(500, (int)sw.ElapsedMilliseconds)); + } + } + catch (ThreadAbortException) + { + ncAdapter.Dispose(); + } + } + public static void ReadProdCycleData() + { + NcAdapter ncAdapter = new NcAdapter(); + Stopwatch sw = new Stopwatch(); + + try + { + // Try connection + CmsError libraryError = ncAdapter.Connect(); + if (libraryError.errorCode != 0) + ManageLibraryError(libraryError); + + while (true) + { + sw.Restart(); + + // Check if client is connected + if (ncAdapter.numericalControl.NC_IsConnected()) + { + +#if false + // Get new data from PLC + libraryError = ncAdapter.ReadProdCycle(out ThermoModels.GaugeModel gaugeData); + if (libraryError.IsError()) + ManageLibraryError(libraryError); + + MessageServices.Current.Publish(SEND_THERMO_GAUGE_DATA, null, gaugeData); +#endif + } + else + RestoreConnection(); + + sw.Stop(); + + //Update thread timer + UpdateStat(MethodBase.GetCurrentMethod().Name, sw.ElapsedMilliseconds); + // Wait + Thread.Sleep(CalcSleepTime(500, (int)sw.ElapsedMilliseconds)); + } + } + catch (ThreadAbortException) + { + ncAdapter.Dispose(); + } + } public static void ReadRecipeData() { NcAdapter ncAdapter = new NcAdapter(); diff --git a/Thermo.Active.Core/ThreadsHandler.cs b/Thermo.Active.Core/ThreadsHandler.cs index ff2a4420..5b7b22b3 100644 --- a/Thermo.Active.Core/ThreadsHandler.cs +++ b/Thermo.Active.Core/ThreadsHandler.cs @@ -14,19 +14,21 @@ namespace Thermo.Active.Core ThreadsFunctions.ReadAlarms, ThreadsFunctions.ReadPowerOnData, ThreadsFunctions.StatThread, - ThreadsFunctions.ReadProcessesPPStatus, + //ThreadsFunctions.ReadProcessesPPStatus, ThreadsFunctions.ReadEnabledFunctionality, ThreadsFunctions.ReadExpiredMaintenances, - ThreadsFunctions.ReadAxesPositionsData, + //ThreadsFunctions.ReadAxesPositionsData, ThreadsFunctions.ReadUserSoftKeysData, //ThreadsFunctions.ReadHeadsData, - ThreadsFunctions.ReadAxesNamesData, + //ThreadsFunctions.ReadAxesNamesData, //ThreadsFunctions.ReadActiveProgramData, //ThreadsFunctions.ReadPartProgramQueueData, ThreadsFunctions.ReadScadaData, ThreadsFunctions.ReadM154Data, // levare? // ThreadsFunctions.ReadNcSoftKeysData, ThreadsFunctions.ReadGaugeData, + ThreadsFunctions.ReadProdInfoData, + ThreadsFunctions.ReadProdCycleData, ThreadsFunctions.ReadRecipeData, ThreadsFunctions.ReadWarmersData, ThreadsFunctions.ReadModulesData diff --git a/Thermo.Active.Model/Constants.cs b/Thermo.Active.Model/Constants.cs index cfd49200..a9e7be3f 100644 --- a/Thermo.Active.Model/Constants.cs +++ b/Thermo.Active.Model/Constants.cs @@ -299,6 +299,8 @@ namespace Thermo.Active.Model public const string SEND_THERMO_MODULE_DATA = "SEND_THERMO_MODULE_DATA"; public const string SEND_THERMO_WARMERS_DATA = "SEND_THERMO_WARMERS_DATA"; public const string SEND_THERMO_GAUGE_DATA = "SEND_THERMO_GAUGE_DATA"; + public const string SEND_THERMO_PROD_INFO_DATA = "SEND_THERMO_PROD_INFO_DATA"; + public const string SEND_THERMO_PROD_CYCLE_DATA = "SEND_THERMO_PROD_CYCLE_DATA"; public const string BROADCAST_DATA = "BROADCAST_DATA"; diff --git a/Thermo.Active.NC/NcAdapter.cs b/Thermo.Active.NC/NcAdapter.cs index 391117d9..ef664d97 100644 --- a/Thermo.Active.NC/NcAdapter.cs +++ b/Thermo.Active.NC/NcAdapter.cs @@ -1063,6 +1063,20 @@ namespace Thermo.Active.NC return cmsError; } + public CmsError ReadProdInfoData(out ThermoModels.ProdInfoModel prodInfoData) + { + prodInfoData = new ThermoModels.ProdInfoModel(); + CmsError cmsError = numericalControl.PLC_RProdInfo(ref prodInfoData); + + return cmsError; + } + public CmsError ReadProdCycleData(out ThermoModels.ProdCycleModel prodCycleData) + { + prodCycleData = new ThermoModels.ProdCycleModel(); + CmsError cmsError = numericalControl.PLC_RProdCycle(ref prodCycleData); + + return cmsError; + } /// /// Vero metodo lettura ricetta da 2 aree memoria PLC /// diff --git a/Thermo.Active/Listeners/ListenersHandler.cs b/Thermo.Active/Listeners/ListenersHandler.cs index 47bb4851..5acea833 100644 --- a/Thermo.Active/Listeners/ListenersHandler.cs +++ b/Thermo.Active/Listeners/ListenersHandler.cs @@ -113,10 +113,14 @@ namespace Thermo.Active.Listeners { SignalRListener.SendThermoGaugeData(a); })); - - // FIXME TODO ADD ProdCycle - - // FIXME TODO ADD ProdInfo + infos.Add(MessageServices.Current.Subscribe(SEND_THERMO_PROD_INFO_DATA, (a, b) => + { + SignalRListener.SendThermoProdInfoData(a); + })); + infos.Add(MessageServices.Current.Subscribe(SEND_THERMO_PROD_CYCLE_DATA, (a, b) => + { + SignalRListener.SendThermoProdCycleData(a); + })); // Broadcast infos.Add(MessageServices.Current.Subscribe(BROADCAST_DATA, (a, b) => diff --git a/Thermo.Active/Listeners/SignalR/SignalRListener.cs b/Thermo.Active/Listeners/SignalR/SignalRListener.cs index 99df14c5..5d0a8a4e 100644 --- a/Thermo.Active/Listeners/SignalR/SignalRListener.cs +++ b/Thermo.Active/Listeners/SignalR/SignalRListener.cs @@ -359,7 +359,7 @@ namespace Thermo.Active.Listeners.SignalR context.Clients.Group("ncData").gaugeData(currGauge); } } - public static void SendProdInfoData(object prodInfoData) + public static void SendThermoProdInfoData(object prodInfoData) { ProdInfoModel currProdInfo = prodInfoData as ProdInfoModel; @@ -371,7 +371,7 @@ namespace Thermo.Active.Listeners.SignalR context.Clients.Group("ncData").prodInfoData(currProdInfo); } } - public static void SendProdCycleData(object prodCycleData) + public static void SendThermoProdCycleData(object prodCycleData) { ProdCycleModel currProdCycle = prodCycleData as ProdCycleModel;