Fix siemens hmi managing

Added siemens library
This commit is contained in:
Lucio Maranta
2018-04-12 09:47:02 +02:00
parent de2ec2da7d
commit 24475452dd
6 changed files with 76 additions and 66 deletions
+69 -59
View File
@@ -60,7 +60,7 @@ public static class ThreadsFunctions
ReadAlarmsTimes++;
// Wait
Thread.Sleep(200);
Thread.Sleep(CalcSleepTime(200, (int)sw.ElapsedMilliseconds));
}
}
catch (ThreadAbortException)
@@ -103,7 +103,7 @@ public static class ThreadsFunctions
ReadPowerOnTimes++;
// Wait
Thread.Sleep(400);
Thread.Sleep(CalcSleepTime(400, (int)sw.ElapsedMilliseconds));
}
}
catch (ThreadAbortException)
@@ -160,7 +160,7 @@ public static class ThreadsFunctions
ReadProcPPTimes++;
// Wait
Thread.Sleep(200);
Thread.Sleep(CalcSleepTime(200, (int)sw.ElapsedMilliseconds));
}
}
catch (ThreadAbortException)
@@ -205,7 +205,7 @@ public static class ThreadsFunctions
ReadFunctionTimes++;
// Wait
Thread.Sleep(200);
Thread.Sleep(CalcSleepTime(200, (int)sw.ElapsedMilliseconds));
}
}
catch (ThreadAbortException)
@@ -295,7 +295,7 @@ public static class ThreadsFunctions
ReadUserSoftKeysTimes++;
// Wait
Thread.Sleep(200);
Thread.Sleep(CalcSleepTime(200, (int)sw.ElapsedMilliseconds));
}
}
catch (ThreadAbortException)
@@ -304,51 +304,6 @@ public static class ThreadsFunctions
}
}
//public static void ReadNcSoftKeysData()
//{
// 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 softkey data from config and PLC
// libraryError = ncHandler.GetNcSoftKeys(out List<DTONcSoftKeyModel> ncSoftKeys);
// if (libraryError.errorCode != 0)
// ManageLibraryError(libraryError);
// else
// // Send through signalR
// MessageServices.Current.Publish(SEND_NC_SOFTKEYS_DATA, null, ncSoftKeys);
// }
// else
// TryNcConnection();
// sw.Stop();
// // Update thread timer
// ReadUserSoftKeysTimer += sw.ElapsedMilliseconds;
// ReadUserSoftKeysTimes++;
// // Wait
// Thread.Sleep(200);
// }
// }
// catch (ThreadAbortException)
// {
// ncHandler.Dispose();
// }
//}
public static void ReadHeadsData()
{
NcHandler ncHandler = new NcHandler();
@@ -385,7 +340,7 @@ public static class ThreadsFunctions
ReadHeadsTimes++;
// Wait
Thread.Sleep(500);
Thread.Sleep(CalcSleepTime(500, (int)sw.ElapsedMilliseconds));
}
}
catch (ThreadAbortException)
@@ -430,7 +385,7 @@ public static class ThreadsFunctions
ReadAxesNamesTimes++;
// Wait
Thread.Sleep(800);
Thread.Sleep(CalcSleepTime(800, (int)sw.ElapsedMilliseconds));
}
}
catch (ThreadAbortException)
@@ -598,12 +553,6 @@ public static class ThreadsFunctions
ReadAxesNamesTimer = 0;
ReadAxesNamesTimes = 0;
}
//if (ThreadsHandler.RunningThreadStatus.ContainsKey("ReadNcSoftKeysData") && ReadNcSoftKeysTimes != 0)
//{
// ThreadsHandler.RunningThreadStatus["ReadNcSoftKeysData"] = (ReadNcSoftKeysTimer / ReadNcSoftKeysTimes) + " mS";
// ReadNcSoftKeysTimer = 0;
// ReadNcSoftKeysTimes = 0;
//}
MessageServices.Current.Publish(SEND_THREADS_STATUS, null, ThreadsHandler.RunningThreadStatus);
@@ -629,5 +578,66 @@ public static class ThreadsFunctions
ReadAxesNamesTimes = 0;
}
private static int CalcSleepTime(int maxSleep, int execTime)
{
int sleep = 0;
// Check if the execution time is greater than the half of the max sleep time
if ( maxSleep - execTime < maxSleep / 2 )
{
sleep = maxSleep;
}
else
{
sleep = maxSleep - execTime;
}
return sleep;
}
#endregion SupportFunctions
}
}
//public static void ReadNcSoftKeysData()
//{
// 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 softkey data from config and PLC
// libraryError = ncHandler.GetNcSoftKeys(out List<DTONcSoftKeyModel> ncSoftKeys);
// if (libraryError.errorCode != 0)
// ManageLibraryError(libraryError);
// else
// // Send through signalR
// MessageServices.Current.Publish(SEND_NC_SOFTKEYS_DATA, null, ncSoftKeys);
// }
// else
// TryNcConnection();
// sw.Stop();
// // Update thread timer
// ReadUserSoftKeysTimer += sw.ElapsedMilliseconds;
// ReadUserSoftKeysTimes++;
// // Wait
// Thread.Sleep(200);
// }
// }
// catch (ThreadAbortException)
// {
// ncHandler.Dispose();
// }
//}