Fix NC comunication

Added UI connection tooltip
This commit is contained in:
Lucio Maranta
2017-12-21 13:39:36 +01:00
parent 5bd278fa69
commit 64ca48eb8d
8 changed files with 129 additions and 73 deletions
+52 -35
View File
@@ -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<DTOAxesModel> 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();