diff --git a/Step.Config/serverConfig.xml b/Step.Config/serverConfig.xml index 8d54230d..94e9d057 100644 --- a/Step.Config/serverConfig.xml +++ b/Step.Config/serverConfig.xml @@ -1,9 +1,9 @@ - 3 - 192.168.157.2 - 8080 + 1 + 10.69.36.33 + 8193 9000 diff --git a/Step.NC/NcHandler.cs b/Step.NC/NcHandler.cs index 98235485..77796a15 100644 --- a/Step.NC/NcHandler.cs +++ b/Step.NC/NcHandler.cs @@ -19,21 +19,16 @@ namespace Step.NC public NcHandler() { - try - { - // Choose NC - numericalControl = SetNumericalControl(); - // Connect NC - if (!numericalControl.NC_IsConnected()) - numericalControl.NC_Connect(); - - } - catch (Exception ex) - { - - } + // Choose NC + numericalControl = SetNumericalControl(); + } + public void Connect() + { + // Connect NC + if (!numericalControl.NC_IsConnected()) + numericalControl.NC_Connect(); } @@ -45,9 +40,9 @@ namespace Step.NC case NC_VENDOR.DEMO: return new Nc_Demo(NcConfig.NcIpAddress, NcConfig.NcPort); case NC_VENDOR.FANUC: - return new Nc_Fanuc(NcConfig.NcIpAddress, NcConfig.NcPort, 2); + return new Nc_Fanuc(NcConfig.NcIpAddress, NcConfig.NcPort, 2000); case NC_VENDOR.SIEMENS: - return new Nc_Siemens(2000); + return new Nc_Siemens(2); case NC_VENDOR.OSAI: return new Nc_Osai(NcConfig.NcIpAddress, NcConfig.NcPort, 2); } @@ -182,8 +177,6 @@ namespace Step.NC public void Dispose() { numericalControl.NC_Disconnect(); - - numericalControl = null; } } } diff --git a/Step.Tasks/ThreadsFunctions.cs b/Step.Tasks/ThreadsFunctions.cs index d147e713..45230beb 100644 --- a/Step.Tasks/ThreadsFunctions.cs +++ b/Step.Tasks/ThreadsFunctions.cs @@ -17,9 +17,11 @@ public static class ThreadsFunctions public static void ReadAlarmsAsync() { NcHandler ncHandler = new NcHandler(); - while (true) + try { - try + ncHandler.Connect(); + + while (true) { if (ncHandler.numericalControl.NC_IsConnected()) { @@ -29,22 +31,25 @@ public static class ThreadsFunctions MessageServices.Current.Publish(SEND_ALARMS, null, alarms); } Thread.Sleep(200); + } - catch (Exception ex) - { - Send(ncHandler); - } + } + catch (Exception ex) + { + ncHandler.Dispose(); + TryNcConnection(); } } public static void ReadNcGenericInfo() { NcHandler ncHandler = new NcHandler(); - - while (true) + try { - try + ncHandler.Connect(); + while (true) { + if (ncHandler.numericalControl.NC_IsConnected()) { // Get Generic data from NC @@ -54,67 +59,79 @@ public static class ThreadsFunctions } Thread.Sleep(1000); } - catch (Exception ex) - { - Send(ncHandler); - } + } + catch (Exception ex) + { + ncHandler.Dispose(); + TryNcConnection(); } } public static void ReadAxes() { NcHandler ncHandler = new NcHandler(); - - while (true) + try { - try + ncHandler.Connect(); + + while (true) { + if (ncHandler.numericalControl.NC_IsConnected()) { // Get the list of the axes List genericData = ncHandler.GetAxesPositions(); // Send through signalR - MessageServices.Current.Publish(SEND_ALARMS, null, genericData); + MessageServices.Current.Publish(SEND_AXES, null, genericData); } Thread.Sleep(200); } - catch (Exception ex) - { - Send(ncHandler); - } - + } + catch (Exception ex) + { + ncHandler.Dispose(); + TryNcConnection(); } } - public static void WillReconnect(NcHandler ncHandler) + private static void WillReconnect() { // Stop all the NC threads ThreadsHandler.Stop(); - + NcHandler ncHandler = new NcHandler(); + + while (!ncHandler.numericalControl.NC_IsConnected()) { - Console.WriteLine("Riconnessione"); // Clear connection - ncHandler.Dispose(); - // Try reconnection - ncHandler = new NcHandler(); + try + { + // Try reconnection + ncHandler.Connect(); + } + catch (Exception ex) + { + ncHandler.Dispose(); + } + // Send through signalR Thread.Sleep(1000); + MessageServices.Current.Publish(NC_STATUS, null, ncHandler.numericalControl.NC_IsConnected()); } // Restart NC threads - ThreadsHandler.Start(); - + ThreadsHandler.StartWorkers(); + reconnectionIsRunning = false; } - private static void Send(NcHandler ncHandler) + public static void TryNcConnection() { - if(reconnectionIsRunning == false) - { // Set reconnection threas as running + if (reconnectionIsRunning == false) + { // Set thread as running state reconnectionIsRunning = true; - + // Start reconnection thread Thread t = new Thread(() => - WillReconnect(ncHandler) + WillReconnect() ); t.Start(); diff --git a/Step.Tasks/ThreadsHandler.cs b/Step.Tasks/ThreadsHandler.cs index a2c91bc9..b8c08929 100644 --- a/Step.Tasks/ThreadsHandler.cs +++ b/Step.Tasks/ThreadsHandler.cs @@ -27,6 +27,11 @@ namespace Step.Core public static void Start() + { + ThreadsFunctions.TryNcConnection(); + } + + public static void StartWorkers() { // For each function run in the list a thread ThreadFunctionsList.ForEach(threadFunction => diff --git a/Step.UI/ServerControlWindow.cs b/Step.UI/ServerControlWindow.cs index 23b69952..711bce0f 100644 --- a/Step.UI/ServerControlWindow.cs +++ b/Step.UI/ServerControlWindow.cs @@ -17,22 +17,15 @@ namespace Step.UI { String HomePageUI; String TestJSPageUI; - + bool ncStatus = false; public ServerControlWindow() { InitializeComponent(); HomePageUI = "http://localhost:" + ServerConfig.ServerPort.ToString() + "/index.html"; TestJSPageUI = "http://localhost:" + ServerConfig.ServerPort.ToString() + "/Testjavascript//index.html"; - MessageServices.Current.Subscribe(SEND_MESSAGE, (a, b) => - { - // Cast object to ErrorMessageModel - ErrorMessageModel message = (ErrorMessageModel)a; - // If error has a fatal level, icon must be error - message.ErrorLevel = message.ErrorLevel > (int)ERROR_LEVEL.ERROR ? (int)ERROR_LEVEL.ERROR : message.ErrorLevel; - // Open BalloonTip with data - StepNotifyIcon.ShowBalloonTip(1000, message.Title, message.Message, (ToolTipIcon)message.ErrorLevel); - }); + + InitializeMessageListeners(); } private static ServerControlWindow ctrlwindow = null; @@ -106,15 +99,15 @@ namespace Step.UI { //Setup the Path Variable String CMSClientPath = ""; - + //Check if the system is 64/32 bit if (Environment.Is64BitOperatingSystem && File.Exists(Environment.CurrentDirectory + @"\Client\x64\CMS_Client.exe")) CMSClientPath = Environment.CurrentDirectory + @"\Client\x64\CMS_Client.exe"; else if (File.Exists(Environment.CurrentDirectory + @"\Client\x86\CMS_Client.exe")) - CMSClientPath = Environment.CurrentDirectory + @"\Client\x86\CMS_Client.exe"; + CMSClientPath = Environment.CurrentDirectory + @"\Client\x86\CMS_Client.exe"; - if(!String.IsNullOrEmpty(CMSClientPath)) + if (!String.IsNullOrEmpty(CMSClientPath)) Process.Start(CMSClientPath, url); else MessageBox.Show("CMS_Client.Exe not found"); @@ -126,5 +119,41 @@ namespace Step.UI StartCMSClient(TestJSPageUI); } + + private void InitializeMessageListeners() + { + MessageServices.Current.Subscribe(SEND_MESSAGE, (a, b) => + { + // Cast object to ErrorMessageModel + ErrorMessageModel message = (ErrorMessageModel)a; + // If error has a fatal level, icon must be error + message.ErrorLevel = message.ErrorLevel > (int)ERROR_LEVEL.ERROR ? (int)ERROR_LEVEL.ERROR : message.ErrorLevel; + // Open BalloonTip with data + StepNotifyIcon.ShowBalloonTip(1000, message.Title, message.Message, (ToolTipIcon)message.ErrorLevel); + }); + + MessageServices.Current.Subscribe(NC_STATUS, (a, b) => + { + bool newNcStatus = (bool)a; + + if(ncStatus != newNcStatus) + { + ncStatus = newNcStatus; + string title = "NC not connected"; + string message = "Check NC connection"; + ToolTipIcon toolTipIcon = ToolTipIcon.Error; + + if (ncStatus == true) + { + title = "Nc connection established"; + message = "Comunication started"; + toolTipIcon = ToolTipIcon.Info; + } + + // Open BalloonTip with data + StepNotifyIcon.ShowBalloonTip(1000, title, message, toolTipIcon); + } + }); + } } } diff --git a/Step.Utils/Constants.cs b/Step.Utils/Constants.cs index e89aeb14..0f45e967 100644 --- a/Step.Utils/Constants.cs +++ b/Step.Utils/Constants.cs @@ -53,6 +53,7 @@ // MVVM Messages names public const string STOP_SERVER = "STOP_SERVER"; public const string SEND_MESSAGE = "SEND_MESSAGE"; + public const string NC_STATUS = "NC_STATUS"; // MVVM Messages tasks names public const string SEND_ALARMS = "SEND_ALARMS"; diff --git a/Step/Listeners/ListenersHandler.cs b/Step/Listeners/ListenersHandler.cs index 6f18f5bb..68da472d 100644 --- a/Step/Listeners/ListenersHandler.cs +++ b/Step/Listeners/ListenersHandler.cs @@ -24,17 +24,17 @@ namespace Step.Listeners infos.Add(MessageServices.Current.Subscribe(SEND_ALARMS, async (a, b) => { - SignalRListener.SendDataToClient(a); + SignalRListener.SendAlarmsToClient(a); })); infos.Add(MessageServices.Current.Subscribe(SEND_GENERIC_DATA, async (a, b) => { - SignalRListener.SendDataToClient(a); + SignalRListener.SendNcInfoToClient(a); })); infos.Add(MessageServices.Current.Subscribe(SEND_AXES, async (a, b) => { - SignalRListener.SendDataToClient(a); + SignalRListener.SendAxesToClient(a); })); } diff --git a/Step/Listeners/SignalR/SignalRListener.cs b/Step/Listeners/SignalR/SignalRListener.cs index eef67c22..afac65c8 100644 --- a/Step/Listeners/SignalR/SignalRListener.cs +++ b/Step/Listeners/SignalR/SignalRListener.cs @@ -9,10 +9,21 @@ namespace Step.Listeners.SignalR { public static class SignalRListener { - public static void SendDataToClient(object taskName) + public static void SendNcInfoToClient(object taskName) { var context = GlobalHost.ConnectionManager.GetHubContext(); - context.Clients.All.hello(taskName); + context.Clients.All.machineInfo(taskName); } + public static void SendAlarmsToClient(object taskName) + { + var context = GlobalHost.ConnectionManager.GetHubContext(); + context.Clients.All.alarms(taskName); + } + public static void SendAxesToClient(object taskName) + { + var context = GlobalHost.ConnectionManager.GetHubContext(); + context.Clients.All.axes(taskName); + } + } }