Fix NC comunication
Added UI connection tooltip
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<ncConfig>
|
||||
<ncVendor>3</ncVendor>
|
||||
<ncIpAddress>192.168.157.2</ncIpAddress>
|
||||
<ncPort>8080</ncPort>
|
||||
<ncVendor>1</ncVendor>
|
||||
<ncIpAddress>10.69.36.33</ncIpAddress>
|
||||
<ncPort>8193</ncPort>
|
||||
</ncConfig>
|
||||
<serverConfig>
|
||||
<serverPort>9000</serverPort>
|
||||
|
||||
+10
-17
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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 =>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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);
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
@@ -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<DataHub>();
|
||||
context.Clients.All.hello(taskName);
|
||||
context.Clients.All.machineInfo(taskName);
|
||||
}
|
||||
public static void SendAlarmsToClient(object taskName)
|
||||
{
|
||||
var context = GlobalHost.ConnectionManager.GetHubContext<DataHub>();
|
||||
context.Clients.All.alarms(taskName);
|
||||
}
|
||||
public static void SendAxesToClient(object taskName)
|
||||
{
|
||||
var context = GlobalHost.ConnectionManager.GetHubContext<DataHub>();
|
||||
context.Clients.All.axes(taskName);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user