First softkey implementation

Added config and API
Added Thread and signal
This commit is contained in:
Lucio Maranta
2018-03-06 17:58:02 +01:00
parent 6db3b6d328
commit 6332ed9732
22 changed files with 528 additions and 53 deletions
+52 -2
View File
@@ -18,7 +18,8 @@ public static class ThreadsFunctions
private static long ReadProcPPTimer = 0, ReadProcPPTimes = 0;
private static long ReadFunctionTimer = 0, ReadFunctionTimes = 0;
private static long ReadMaintenanceTimer = 0, ReadMaintenanceTimes = 0;
private static long ReadSoftKeysTimer = 0, ReadSoftKeysTimes = 0;
private static Thread ConnThread;
#region Nc Threads
@@ -242,6 +243,50 @@ public static class ThreadsFunctions
}
}
public static void ReadSoftKeysData()
{
NcHandler ncHandler = new NcHandler();
Stopwatch sw = new Stopwatch();
try
{
// Try connection
CmsError libraryError = ncHandler.Connect();
if (libraryError.errorCode != 0)
ManageLibraryError(libraryError);
while (true)
{
sw.Restart();
if (ncHandler.numericalControl.NC_IsConnected())
{
// Get Data from database and PLC
libraryError = ncHandler.GetSoftKeys(out List<DTOSoftKeyModel> softKeys);
if (libraryError.errorCode != 0)
ManageLibraryError(libraryError);
else
// Send through signalR
MessageServices.Current.Publish(SEND_SOFT_KEYS_DATA, null, softKeys);
}
else
TryNcConnection();
sw.Stop();
//Send to the UI the time
ReadSoftKeysTimer += sw.ElapsedMilliseconds;
ReadSoftKeysTimes++;
// Wait
Thread.Sleep(200);
}
}
catch (ThreadAbortException)
{
ncHandler.Dispose();
}
}
#endregion Nc Threads
#region SupportFunctions
@@ -383,7 +428,12 @@ public static class ThreadsFunctions
ReadMaintenanceTimer = 0;
ReadMaintenanceTimes = 0;
}
if (ThreadsHandler.RunningThreadStatus.ContainsKey("ReadSoftKeysData") && ReadSoftKeysTimes != 0)
{
ThreadsHandler.RunningThreadStatus["ReadSoftKeysData"] = (ReadSoftKeysTimer / ReadSoftKeysTimes) + " mS";
ReadSoftKeysTimer = 0;
ReadSoftKeysTimes = 0;
}
MessageServices.Current.Publish(SEND_THREADS_STATUS, null, ThreadsHandler.RunningThreadStatus);