diff --git a/Step.Config/Step.Config.csproj b/Step.Config/Step.Config.csproj
index 155fb1d8..f9398d06 100644
--- a/Step.Config/Step.Config.csproj
+++ b/Step.Config/Step.Config.csproj
@@ -47,7 +47,7 @@
-
+
Always
Designer
@@ -63,7 +63,7 @@
-
+
Always
Designer
diff --git a/Step.Config/startupConfig.xml b/Step.Config/serverConfig.xml
similarity index 100%
rename from Step.Config/startupConfig.xml
rename to Step.Config/serverConfig.xml
diff --git a/Step.Config/startupValidator.xsd b/Step.Config/serverConfigValidator.xsd
similarity index 100%
rename from Step.Config/startupValidator.xsd
rename to Step.Config/serverConfigValidator.xsd
diff --git a/Step.Database/Controllers/FunctionAccessController.cs b/Step.Database/Controllers/FunctionAccessController.cs
index 8356decc..b03a8df8 100644
--- a/Step.Database/Controllers/FunctionAccessController.cs
+++ b/Step.Database/Controllers/FunctionAccessController.cs
@@ -30,11 +30,11 @@ namespace Step.Database.Controllers
.FirstOrDefault();
}
- public List GetFunctionAccess()
+ public List GetFunctionAccess()
{
return dbCtx
.FunctionsAccess
- .Select(f => new FunctionAccessModelDTO()
+ .Select(f => new DTOFunctionAccessModel()
{
Id = f.FunctionAccessId,
Name = f.Name,
diff --git a/Step.Model/DTOModels/AlarmsModel.cs b/Step.Model/DTOModels/DTOAlarmsModel.cs
similarity index 72%
rename from Step.Model/DTOModels/AlarmsModel.cs
rename to Step.Model/DTOModels/DTOAlarmsModel.cs
index 525056df..94916477 100644
--- a/Step.Model/DTOModels/AlarmsModel.cs
+++ b/Step.Model/DTOModels/DTOAlarmsModel.cs
@@ -6,13 +6,13 @@ using System.Threading.Tasks;
namespace Step.Model.DTOModels
{
- public class AlarmsModel
+ public class DTOAlarmsModel
{
- public List NcAlarms;
- public List PlcAlarms;
- public List ProcessAlarms;
+ public List NcAlarms { get; set; }
+ public List PlcAlarms { get; set; }
+ public List ProcessAlarms { get; set; }
- public AlarmsModel()
+ public DTOAlarmsModel()
{
NcAlarms = new List();
PlcAlarms = new List();
@@ -29,13 +29,11 @@ namespace Step.Model.DTOModels
public struct GenericAlarmModel
{
- public ushort id;
public string alarmMessage;
}
public struct ProcessAlarmModel
{
- public ushort id;
public string alarmMessage;
public ushort process;
}
diff --git a/Step.Model/DTOModels/DTOAxesModel.cs b/Step.Model/DTOModels/DTOAxesModel.cs
new file mode 100644
index 00000000..82d89a98
--- /dev/null
+++ b/Step.Model/DTOModels/DTOAxesModel.cs
@@ -0,0 +1,33 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Step.Model.DTOModels
+{
+ public class DTOAxesModel
+ {
+ public Dictionary interpolated;
+ public Dictionary machine;
+ public Dictionary programmePos;
+ public Dictionary toGo;
+ public Dictionary followingErr;
+
+ public DTOAxesModel()
+ {
+ interpolated = new Dictionary();
+ machine = new Dictionary();
+ programmePos = new Dictionary();
+ toGo = new Dictionary();
+ followingErr = new Dictionary();
+ }
+
+
+ public struct AxisModel
+ {
+ public string name;
+ public double value;
+ }
+ }
+}
diff --git a/Step.Model/DTOModels/FunctionAccessModelDTO.cs b/Step.Model/DTOModels/DTOFunctionAccessModel.cs
similarity index 84%
rename from Step.Model/DTOModels/FunctionAccessModelDTO.cs
rename to Step.Model/DTOModels/DTOFunctionAccessModel.cs
index 085d69be..a48eac33 100644
--- a/Step.Model/DTOModels/FunctionAccessModelDTO.cs
+++ b/Step.Model/DTOModels/DTOFunctionAccessModel.cs
@@ -1,6 +1,6 @@
namespace Step.Model.DTOModels
{
- public class FunctionAccessModelDTO
+ public class DTOFunctionAccessModel
{
public int Id { get; set; }
diff --git a/Step.Model/DTOModels/DTONcGenericDataModel.cs b/Step.Model/DTOModels/DTONcGenericDataModel.cs
new file mode 100644
index 00000000..9abe86f1
--- /dev/null
+++ b/Step.Model/DTOModels/DTONcGenericDataModel.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Step.Model.DTOModels
+{
+ public class DTONcGenericDataModel
+ {
+ public CultureInfo Language { get; set; }
+ public string SerialNumber { get; set; }
+ public string SoftwareVersion { get; set; }
+ public string Model { get; set; }
+ public DateTime DateTime { get; set; }
+ public string MachineNumber { get; set; }
+ public ushort ProcessNumber { get; set; }
+ }
+}
diff --git a/Step.Model/Step.Model.csproj b/Step.Model/Step.Model.csproj
index b4d84590..bb74478a 100644
--- a/Step.Model/Step.Model.csproj
+++ b/Step.Model/Step.Model.csproj
@@ -66,13 +66,15 @@
DtsGenerator
RoleModel.cs.d.ts
-
+
+
+
DtsGenerator
UserModel.cs.d.ts
-
+
diff --git a/Step.NC/NcHandler.cs b/Step.NC/NcHandler.cs
new file mode 100644
index 00000000..98235485
--- /dev/null
+++ b/Step.NC/NcHandler.cs
@@ -0,0 +1,189 @@
+using System;
+using System.Collections.Generic;
+using static Step.Utils.Constants;
+using static Step.Config.StartupConfig;
+using CMS_CORE;
+using CMS_CORE.Demo;
+using CMS_CORE.Fanuc;
+using CMS_CORE.Siemens;
+using CMS_CORE.Osai;
+using Step.Model.DTOModels;
+using System.Globalization;
+using static Step.Utils.ExceptionManager;
+
+namespace Step.NC
+{
+ public class NcHandler : IDisposable
+ {
+ public Nc numericalControl;
+
+ public NcHandler()
+ {
+ try
+ {
+ // Choose NC
+ numericalControl = SetNumericalControl();
+
+ // Connect NC
+ if (!numericalControl.NC_IsConnected())
+ numericalControl.NC_Connect();
+
+ }
+ catch (Exception ex)
+ {
+
+ }
+
+ }
+
+
+ public Nc SetNumericalControl()
+ {
+ // Return new Numerical control instance choosed from the configuration
+ switch ((NC_VENDOR)NcConfig.NcVendor)
+ {
+ 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);
+ case NC_VENDOR.SIEMENS:
+ return new Nc_Siemens(2000);
+ case NC_VENDOR.OSAI:
+ return new Nc_Osai(NcConfig.NcIpAddress, NcConfig.NcPort, 2);
+ }
+
+ return null;
+ }
+
+ public DTONcGenericDataModel GetNcGenericData()
+ {
+ DTONcGenericDataModel genericData = new DTONcGenericDataModel();
+
+ // Get date time
+ DateTime dateTime = new DateTime();
+ numericalControl.NC_RDateTime(ref dateTime);
+ genericData.DateTime = dateTime;
+
+ // Get language
+ CultureInfo lang = new CultureInfo("en");
+ numericalControl.NC_RLanguage(ref lang);
+ genericData.Language = lang;
+
+ string tmpInfo = "";
+ // Get serial number
+ numericalControl.NC_RSerialNumber(ref tmpInfo);
+ genericData.SerialNumber = tmpInfo;
+
+ // Get software version
+ numericalControl.NC_RSoftwareVersion(ref tmpInfo);
+ genericData.SoftwareVersion = tmpInfo;
+
+ // Get model name
+ numericalControl.NC_RModelName(ref tmpInfo);
+ genericData.Model = tmpInfo;
+
+ // Get machine number
+ numericalControl.NC_RMachineNumber(ref tmpInfo);
+ genericData.MachineNumber = tmpInfo;
+
+ // Get max process number
+ ushort procNum = 0;
+ numericalControl.NC_RProcessesNum(ref procNum);
+ genericData.ProcessNumber = procNum;
+
+ return genericData;
+ }
+
+ public DTOAlarmsModel GetNcAlarms()
+ {
+ DTOAlarmsModel alarms = new DTOAlarmsModel();
+ List tmpAlarms = new List();
+ // Read NC active alarms
+ numericalControl.NC_RActiveAlarms(ref tmpAlarms);
+
+ // Create response list from strings
+ foreach (string alarmMessage in tmpAlarms)
+ {
+ alarms.NcAlarms.Add(new GenericAlarmModel()
+ {
+ alarmMessage = alarmMessage,
+ });
+ }
+
+ // Get NC max process number
+ ushort maxProcNumber = 0;
+ numericalControl.NC_RProcessesNum(ref maxProcNumber);
+
+ // For each process
+ for (ushort i = 1; i <= maxProcNumber; i++)
+ {
+ // Get process active alarms
+ numericalControl.PROC_RActiveAlarms(i, ref tmpAlarms);
+ // Create response list from strings
+ foreach (string alarmMessage in tmpAlarms)
+ {
+ alarms.ProcessAlarms.Add(new ProcessAlarmModel()
+ {
+ alarmMessage = alarmMessage,
+ process = i
+ });
+ }
+ }
+
+ // Read PLC Active Messages
+ numericalControl.PLC_RActiveMessages(ref tmpAlarms);
+ // Formatting response list from strings
+ foreach (string alarmMessage in tmpAlarms)
+ {
+ alarms.PlcAlarms.Add(new GenericAlarmModel()
+ {
+ alarmMessage = alarmMessage,
+ });
+ }
+
+ return alarms;
+ }
+
+ public List GetAxesPositions()
+ {
+ List axes = new List();
+
+ // Get NC max process number
+ ushort maxProcNumber = 0;
+ numericalControl.NC_RProcessesNum(ref maxProcNumber);
+
+ // For each process
+ for (ushort i = 1; i <= maxProcNumber; i++)
+ {
+ DTOAxesModel axis = GetAxesPositionsByProcess(i);
+
+ axes.Add(axis);
+ }
+
+ return axes;
+ }
+
+ public DTOAxesModel GetAxesPositionsByProcess(ushort processNum)
+ {
+
+ DTOAxesModel axes = new DTOAxesModel();
+
+ numericalControl.AXES_RInterpPosition(processNum, ref axes.interpolated);
+ numericalControl.AXES_RMachinePosition(processNum, ref axes.machine);
+ numericalControl.AXES_RProgrPosition(processNum, ref axes.programmePos);
+ numericalControl.AXES_RDistanceToGo(processNum, ref axes.toGo);
+
+ //numericalControl.AXES_RFollowingError(1, ref axes.followingErr);
+
+ return axes;
+ }
+
+
+ public void Dispose()
+ {
+ numericalControl.NC_Disconnect();
+
+ numericalControl = null;
+ }
+ }
+}
diff --git a/Step.NC/Step.NC.csproj b/Step.NC/Step.NC.csproj
index 7c169047..da57ddcb 100644
--- a/Step.NC/Step.NC.csproj
+++ b/Step.NC/Step.NC.csproj
@@ -32,6 +32,9 @@
4
+
+ ..\..\CMS_CORE_LIBRARY\CMS_CORE_Library\bin\x86\Debug\CMS_CORE_Library.dll
+
@@ -42,6 +45,7 @@
+
@@ -96,5 +100,19 @@
Always
+
+
+ {3f5c2483-fc87-43ef-92a8-66ff7d0e440f}
+ Step.Config
+
+
+ {631375DD-06D3-49BB-8130-D9DDB34C429D}
+ Step.Model
+
+
+ {CBEB631B-ABFA-4042-9779-C0060B0DFEFE}
+ Step.Utils
+
+
\ No newline at end of file
diff --git a/Step.Tasks/Step.Core.csproj b/Step.Tasks/Step.Core.csproj
index d2fd4c10..baa84e58 100644
--- a/Step.Tasks/Step.Core.csproj
+++ b/Step.Tasks/Step.Core.csproj
@@ -64,6 +64,10 @@
{631375DD-06D3-49BB-8130-D9DDB34C429D}
Step.Model
+
+ {b2366b08-96bd-4f6b-b748-b45089b87a14}
+ Step.NC
+
{cbeb631b-abfa-4042-9779-c0060b0dfefe}
Step.Utils
diff --git a/Step.Tasks/ThreadsFunctions.cs b/Step.Tasks/ThreadsFunctions.cs
index 2bf10194..d147e713 100644
--- a/Step.Tasks/ThreadsFunctions.cs
+++ b/Step.Tasks/ThreadsFunctions.cs
@@ -1,84 +1,123 @@
using System;
using System.Collections.Generic;
-using System.Diagnostics;
+using System.Globalization;
using System.Threading;
-using System.Threading.Tasks;
using CMS_CORE;
-using CMS_CORE.Fanuc;
using Step.Model.DTOModels;
using TeamDev.SDK.MVVM;
+using static Step.Utils.Constants;
+using Step.NC;
+using System.Diagnostics;
+using Step.Core;
-namespace Step.Core
+public static class ThreadsFunctions
{
- public static class ThreadsFunctions
+ public static bool reconnectionIsRunning = false;
+
+ public static void ReadAlarmsAsync()
{
- public static bool ReadAlarmsAsync(Nc numericalControl)
+ NcHandler ncHandler = new NcHandler();
+ while (true)
{
- AlarmsModel alarms = new AlarmsModel();
- List tmpAlarms = new List();
-
- //if (!numericalControl.NC_IsConnected())
- // numericalControl.NC_Connect();
-
- while (true)
+ try
{
- //PAOLO Qui ci sono problemi con il CN
-
- //if (numericalControl.NC_IsConnected())
- //{
- // // Read NC active alarms
- // numericalControl.NC_RActiveAlarms(ref tmpAlarms);
-
- // // Create response list from strings
- // foreach (string alarmMessage in tmpAlarms)
- // {
- // alarms.NcAlarms.Add(new GenericAlarmModel()
- // {
- // alarmMessage = alarmMessage,
- // id = 1
- // });
- // }
-
- // // Get NC max process number
- // ushort maxProcNumber = 0;
- // numericalControl.NC_RProcessesNum(ref maxProcNumber);
-
- // // For each process
- // for (ushort i = 1; i <= maxProcNumber; i++)
- // {
- // // Get process active alarms
- // numericalControl.PROC_RActiveAlarms(i, ref tmpAlarms);
- // // Create response list from strings
- // foreach (string alarmMessage in tmpAlarms)
- // {
- // alarms.ProcessAlarms.Add(new ProcessAlarmModel()
- // {
- // alarmMessage = alarmMessage,
- // id = 1,
- // process = i
- // });
- // }
- // }
-
- // // Read PLC Active Messages
- // numericalControl.PLC_RActiveMessages(ref tmpAlarms);
- // // Formatting response list from strings
- // foreach (string alarmMessage in tmpAlarms)
- // {
- // alarms.PlcAlarms.Add(new GenericAlarmModel()
- // {
- // alarmMessage = alarmMessage,
- // id = 1
- // });
- // }
-
- // MessageServices.Current.Publish("testsignal", null, alarms);
- // Thread.Sleep(200);
- // alarms.Clear();
-
- //}
+ if (ncHandler.numericalControl.NC_IsConnected())
+ {
+ // Get Alarms from NC
+ DTOAlarmsModel alarms = ncHandler.GetNcAlarms();
+ // Send through signalR
+ MessageServices.Current.Publish(SEND_ALARMS, null, alarms);
+ }
+ Thread.Sleep(200);
}
- return true;
+ catch (Exception ex)
+ {
+ Send(ncHandler);
+ }
+ }
+ }
+
+ public static void ReadNcGenericInfo()
+ {
+ NcHandler ncHandler = new NcHandler();
+
+ while (true)
+ {
+ try
+ {
+ if (ncHandler.numericalControl.NC_IsConnected())
+ {
+ // Get Generic data from NC
+ DTONcGenericDataModel genericData = ncHandler.GetNcGenericData();
+ // Send through signalR
+ MessageServices.Current.Publish(SEND_GENERIC_DATA, null, genericData);
+ }
+ Thread.Sleep(1000);
+ }
+ catch (Exception ex)
+ {
+ Send(ncHandler);
+ }
+ }
+ }
+
+ public static void ReadAxes()
+ {
+ NcHandler ncHandler = new NcHandler();
+
+ while (true)
+ {
+ try
+ {
+ 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);
+ }
+ Thread.Sleep(200);
+ }
+ catch (Exception ex)
+ {
+ Send(ncHandler);
+ }
+
+ }
+ }
+
+ public static void WillReconnect(NcHandler ncHandler)
+ {
+ // Stop all the NC threads
+ ThreadsHandler.Stop();
+
+ while (!ncHandler.numericalControl.NC_IsConnected())
+ {
+ Console.WriteLine("Riconnessione");
+ // Clear connection
+ ncHandler.Dispose();
+ // Try reconnection
+ ncHandler = new NcHandler();
+ Thread.Sleep(1000);
+ }
+ // Restart NC threads
+ ThreadsHandler.Start();
+
+ reconnectionIsRunning = false;
+ }
+
+ private static void Send(NcHandler ncHandler)
+ {
+ if(reconnectionIsRunning == false)
+ { // Set reconnection threas as running
+ reconnectionIsRunning = true;
+
+ // Start reconnection thread
+ Thread t = new Thread(() =>
+ WillReconnect(ncHandler)
+ );
+
+ t.Start();
}
}
}
diff --git a/Step.Tasks/ThreadsHandler.cs b/Step.Tasks/ThreadsHandler.cs
index 054df816..a2c91bc9 100644
--- a/Step.Tasks/ThreadsHandler.cs
+++ b/Step.Tasks/ThreadsHandler.cs
@@ -9,73 +9,48 @@ using CMS_CORE.Demo;
using CMS_CORE.Fanuc;
using CMS_CORE.Osai;
using CMS_CORE.Siemens;
+using Step.NC;
using static Step.Config.StartupConfig;
using static Step.Utils.Constants;
namespace Step.Core
{
- public class ThreadsHandler
+ public static class ThreadsHandler
{
- private List> ThreadFunctionsList;
- private List RunningThreadsList;
-
- public ThreadsHandler()
- {
- ThreadFunctionsList = new List>
+ private static List ThreadFunctionsList = new List
{
ThreadsFunctions.ReadAlarmsAsync,
- ThreadsFunctions.ReadAlarmsAsync,
- ThreadsFunctions.ReadAlarmsAsync,
- ThreadsFunctions.ReadAlarmsAsync,
- ThreadsFunctions.ReadAlarmsAsync
+ ThreadsFunctions.ReadNcGenericInfo,
+ ThreadsFunctions.ReadAxes
};
+ private static List RunningThreadsList = new List();
- RunningThreadsList = new List();
- }
- public void Start()
+ public static void Start()
{
- // Create numerical control instance
- Nc numericalControl = SetNumericalControl();
-
-
// For each function run in the list a thread
ThreadFunctionsList.ForEach(threadFunction =>
{
- // Run new Thread
+ // Run new Thread in the list
Thread t = new Thread(() =>
- threadFunction(numericalControl)
+ threadFunction()
);
+
t.Start();
// Add thread to running threads list
RunningThreadsList.Add(t);
});
}
- public void Stop()
- { // Stop each thread
+ public static void Stop()
+ {
+ // Stop each thread
RunningThreadsList.ForEach(thread =>
{
thread.Abort();
});
- }
-
- public Nc SetNumericalControl()
- {
- // Return new Numerical control instance choosed from the configuration
- switch ((NC_VENDOR)NcConfig.NcVendor)
- {
- case NC_VENDOR.DEMO:
- return new Nc_Demo(NcConfig.NcIpAddress, NcConfig.NcPort);
- case NC_VENDOR.FANUC:
- return new Nc_Fanuc(NcConfig.NcIpAddress, NcConfig.NcPort, 2000);
- case NC_VENDOR.SIEMENS:
- return new Nc_Siemens(2000);
- case NC_VENDOR.OSAI:
- return new Nc_Osai(NcConfig.NcIpAddress, NcConfig.NcPort, 2000);
- }
-
- return null;
+ // No running status
+ RunningThreadsList.Clear();
}
}
}
diff --git a/Step.UI/ServerControlWindow.cs b/Step.UI/ServerControlWindow.cs
index ebdc25a6..23b69952 100644
--- a/Step.UI/ServerControlWindow.cs
+++ b/Step.UI/ServerControlWindow.cs
@@ -86,7 +86,7 @@ namespace Step.UI
private void StopServerButton_Click(object sender, EventArgs e)
{
// Send message to listeners and close server
- MessageServices.Current.Publish("StopServer");
+ MessageServices.Current.Publish(STOP_SERVER);
}
private void NotifyIcon_Click(object sender, EventArgs e)
diff --git a/Step.Utils/Constants.cs b/Step.Utils/Constants.cs
index 44c5baf9..e89aeb14 100644
--- a/Step.Utils/Constants.cs
+++ b/Step.Utils/Constants.cs
@@ -47,11 +47,16 @@
}
// Filenames
- public const string STARTUP_CONFIG_SCHEMA_PATH = "startupValidator.xsd";
- public const string STARTUP_CONFIG_PATH = "startupConfig.xml";
+ public const string STARTUP_CONFIG_SCHEMA_PATH = "serverConfigValidator.xsd";
+ public const string STARTUP_CONFIG_PATH = "serverConfig.xml";
- // Message Headers
- public const string STOP_SERVER = "StopServer";
- public const string SEND_MESSAGE = "SendMessage";
+ // MVVM Messages names
+ public const string STOP_SERVER = "STOP_SERVER";
+ public const string SEND_MESSAGE = "SEND_MESSAGE";
+
+ // MVVM Messages tasks names
+ public const string SEND_ALARMS = "SEND_ALARMS";
+ public const string SEND_GENERIC_DATA = "SEND_GENERIC_DATA";
+ public const string SEND_AXES = "SEND_AXES";
}
}
diff --git a/Step.Utils/ExceptionManager.cs b/Step.Utils/ExceptionManager.cs
index 071a466c..fb3c9f13 100644
--- a/Step.Utils/ExceptionManager.cs
+++ b/Step.Utils/ExceptionManager.cs
@@ -33,8 +33,7 @@ namespace Step.Utils
{
// Default case
LogAndNotifyUsers(CreateMessageModel("Generic Error!", ex.Message, ERROR_LEVEL.FATAL));
- // Close the application
- Environment.Exit(1);
+
}
}
}
diff --git a/Step/Controllers/SignalR/NcHub.cs b/Step/Controllers/SignalR/NcHub.cs
new file mode 100644
index 00000000..93d56d4c
--- /dev/null
+++ b/Step/Controllers/SignalR/NcHub.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Microsoft.AspNet.SignalR;
+
+namespace Step.Controllers.SignalR
+{
+ public class NcHub : Hub
+ {
+
+ }
+}
diff --git a/Step/Controllers/WebApi/ConfigurationController.cs b/Step/Controllers/WebApi/ConfigurationController.cs
index cc00b533..8f892602 100644
--- a/Step/Controllers/WebApi/ConfigurationController.cs
+++ b/Step/Controllers/WebApi/ConfigurationController.cs
@@ -14,7 +14,7 @@ namespace Step.Controllers.WebApi
{
using (FunctionAccessController functionController = new FunctionAccessController())
{
- List functionsList = functionController.GetFunctionAccess();
+ List functionsList = functionController.GetFunctionAccess();
if (functionsList == null)
return NotFound();
diff --git a/Step/Controllers/WebApi/NcApiController.cs b/Step/Controllers/WebApi/NcApiController.cs
new file mode 100644
index 00000000..e116c0ac
--- /dev/null
+++ b/Step/Controllers/WebApi/NcApiController.cs
@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Web.Http;
+using CMS_CORE;
+using Step.Model.DTOModels;
+using Step.NC;
+using static Step.Utils.Constants;
+
+namespace Step.Controllers.WebApi
+{
+ [RoutePrefix("api/nc")]
+ public class NcApiController : ApiController
+ {
+ [Route("generic_data"), HttpGet]
+ [WebApiAuthorize(FunctionAccess = "test", Action = ACTIONS.READ)]
+ public IHttpActionResult GetNcGenericData()
+ {
+ DTONcGenericDataModel genericData = new DTONcGenericDataModel();
+ Stopwatch stop = new Stopwatch();
+ stop.Start();
+ try
+ {
+ using( NcHandler ncHandler = new NcHandler()) {
+ genericData = ncHandler.GetNcGenericData();
+ }
+ }
+ catch (Exception ex)
+ {
+ return InternalServerError(ex);
+ }
+
+ Console.WriteLine("API" + stop.ElapsedMilliseconds);
+ return Ok(genericData);
+ }
+ }
+}
diff --git a/Step/Listeners/ListenersHandler.cs b/Step/Listeners/ListenersHandler.cs
index afe0aad6..6f18f5bb 100644
--- a/Step/Listeners/ListenersHandler.cs
+++ b/Step/Listeners/ListenersHandler.cs
@@ -1,37 +1,44 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using System.Collections.Generic;
using Step.Listeners.Database;
using Step.Listeners.SignalR;
using TeamDev.SDK.MVVM;
+using static Step.Utils.Constants;
namespace Step.Listeners
{
public class ListenersHandler
{
- List infos = new List();
+ private static List infos = new List();
public ListenersHandler()
{
infos = new List();
}
- public void Start()
+ public static void Start()
{
infos.Add(MessageServices.Current.Subscribe("testdb", async (a, b) =>
{
DatabaseTest.DbTest(a.ToString());
}));
- infos.Add(MessageServices.Current.Subscribe("testsignal", async (a, b) =>
+ infos.Add(MessageServices.Current.Subscribe(SEND_ALARMS, async (a, b) =>
{
- SignalRListener.SignalRtest(a);
+ SignalRListener.SendDataToClient(a);
+ }));
+
+ infos.Add(MessageServices.Current.Subscribe(SEND_GENERIC_DATA, async (a, b) =>
+ {
+ SignalRListener.SendDataToClient(a);
+ }));
+
+ infos.Add(MessageServices.Current.Subscribe(SEND_AXES, async (a, b) =>
+ {
+ SignalRListener.SendDataToClient(a);
}));
}
- public void Stop()
+ public static void Stop()
{
MessageServices.Current.UnSubscribe(infos.ToArray());
}
diff --git a/Step/Listeners/SignalR/SignalRListener.cs b/Step/Listeners/SignalR/SignalRListener.cs
index e072e007..eef67c22 100644
--- a/Step/Listeners/SignalR/SignalRListener.cs
+++ b/Step/Listeners/SignalR/SignalRListener.cs
@@ -9,7 +9,7 @@ namespace Step.Listeners.SignalR
{
public static class SignalRListener
{
- public static void SignalRtest(object taskName)
+ public static void SendDataToClient(object taskName)
{
var context = GlobalHost.ConnectionManager.GetHubContext();
context.Clients.All.hello(taskName);
diff --git a/Step/Step.csproj b/Step/Step.csproj
index cc2c6cd9..62623736 100644
--- a/Step/Step.csproj
+++ b/Step/Step.csproj
@@ -41,6 +41,7 @@
4
+
..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll
@@ -152,8 +153,10 @@
+
+
diff --git a/Step/program.cs b/Step/program.cs
index f935d4b7..7aab43f1 100644
--- a/Step/program.cs
+++ b/Step/program.cs
@@ -20,12 +20,8 @@ namespace Step
public static int MessageService { get; private set; }
- public static ThreadsHandler tasksHandler = new ThreadsHandler();
- public static ListenersHandler listenersHandler = new ListenersHandler();
-
public static void Main()
{
- GC.TryStartNoGCRegion(10000000);
LogInfo("Application started");
StartupConfigController.ReadStartupConfig();
@@ -42,22 +38,23 @@ namespace Step
{
StopRequest.Set();
});
- // Start tasks
- tasksHandler.Start();
+
+ // Start Threads
+ ThreadsHandler.Start();
// Start listeners
- listenersHandler.Start();
+ ListenersHandler.Start();
// Start server services
using (WebApp.Start(url: configuredUri))
{
// Wait interrupt from client
StopRequest.WaitOne();
- // Stop tasks
- tasksHandler.Stop();
+
+ // Stop Threads
+ ThreadsHandler.Stop();
// Stop messageservice listeners
- listenersHandler.Stop();
- GC.EndNoGCRegion();
- LogInfo("Application closed");
+ ListenersHandler.Stop();
+ LogInfo("Application closed");
}
// Close WinForm