Merge branch 'feature/Scada' into develop
# Conflicts: # Client.Utils/Constants.cs # Client/View/NcWindow.cs # Libs/CMS_CORE_Library.dll # Step.Config/Config/serverConfig.xml # Step.Core/ThreadsFunctions.cs # Step.Model/Constants.cs # Step.Model/DTOModels/AlarmModels/DTOAlarmHistoricModel.cs # Step.Model/DatabaseModels/NcMagazinePositionModel.cs # Step.Model/Step.Model.csproj
This commit is contained in:
@@ -3,14 +3,17 @@ using Step.Config;
|
||||
using Step.Core;
|
||||
using Step.Model.DTOModels;
|
||||
using Step.Model.DTOModels.AlarmModels;
|
||||
using Step.Model.DTOModels.Scada;
|
||||
using Step.Model.DTOModels.ToolModels;
|
||||
using Step.NC;
|
||||
using Step.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using TeamDev.SDK.MVVM;
|
||||
using static Step.Config.ServerConfig;
|
||||
using static Step.Model.Constants;
|
||||
using static Step.Utils.ExceptionManager;
|
||||
|
||||
@@ -29,7 +32,6 @@ public static class ThreadsFunctions
|
||||
private static long ReadToolDataTimer = 0, ReadToolDataTimes = 0;
|
||||
private static long WatchdogTimer = 0, WatchdogTimes = 0;
|
||||
|
||||
|
||||
private static Thread ConnThread;
|
||||
|
||||
#region Functions
|
||||
@@ -716,8 +718,8 @@ public static class ThreadsFunctions
|
||||
{
|
||||
ncHandler.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void MonitorPanelPCResources()
|
||||
{
|
||||
float sumRec, sumSen;
|
||||
@@ -726,7 +728,7 @@ public static class ThreadsFunctions
|
||||
int cardId = ServerConfig.ServerStartupConfig.NetworkCardId - 1;
|
||||
|
||||
PerformanceCounterCategory performanceCounterCategory = new PerformanceCounterCategory("Network Interface");
|
||||
|
||||
|
||||
if (cardId < 0 || cardId > performanceCounterCategory.GetInstanceNames().Length)
|
||||
{
|
||||
Monitor.Name = "No card to monitor";
|
||||
@@ -734,9 +736,8 @@ public static class ThreadsFunctions
|
||||
return;
|
||||
}
|
||||
|
||||
Monitor.Name = performanceCounterCategory.GetInstanceNames()[cardId];
|
||||
|
||||
|
||||
Monitor.Name = performanceCounterCategory.GetInstanceNames()[cardId];
|
||||
|
||||
PerformanceCounter PC_Bandwith = new PerformanceCounter("Network Interface", "Current Bandwidth", Monitor.Name);
|
||||
PerformanceCounter PC_RecievedBytes = new PerformanceCounter("Network Interface", "Bytes Received/sec", Monitor.Name);
|
||||
PerformanceCounter PC_SentBytes = new PerformanceCounter("Network Interface", "Bytes Sent/sec", Monitor.Name);
|
||||
@@ -756,7 +757,7 @@ public static class ThreadsFunctions
|
||||
sumRec += PC_RecievedBytes.NextValue();
|
||||
sumSen += PC_SentBytes.NextValue();
|
||||
}
|
||||
Monitor.Value = Math.Round(((8 * (sumSen + sumRec)) / (Monitor.Bandwidth * 50) * 100), 2) ;
|
||||
Monitor.Value = Math.Round(((8 * (sumSen + sumRec)) / (Monitor.Bandwidth * 50) * 100), 2);
|
||||
MessageServices.Current.Publish(NETWORK_USAGE, null, Monitor);
|
||||
sw.Stop();
|
||||
|
||||
@@ -767,13 +768,55 @@ public static class ThreadsFunctions
|
||||
catch (ThreadAbortException)
|
||||
{
|
||||
ExceptionManager.Manage(ERROR_LEVEL.FATAL, "Fatal error in Network Performance monitor Thread");
|
||||
}
|
||||
}
|
||||
|
||||
public static void ReadScadaData()
|
||||
{
|
||||
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();
|
||||
|
||||
// Check if client is connected
|
||||
if (ncHandler.numericalControl.NC_IsConnected())
|
||||
{
|
||||
List<ScadaSchemaModel> scadaToRead = ProductionScadaSchema.Concat(SubscribedScada).ToList();
|
||||
|
||||
// Get new data from PLC
|
||||
libraryError = ncHandler.ReadScadasData(scadaToRead, out List<DTOScadaModel> scadas);
|
||||
if (libraryError.IsError())
|
||||
ManageLibraryError(libraryError);
|
||||
|
||||
MessageServices.Current.Publish(SEND_SCADA_DATA, null, scadas);
|
||||
}
|
||||
else
|
||||
RestoreConnection();
|
||||
sw.Stop();
|
||||
|
||||
// Wait
|
||||
Thread.Sleep(CalcSleepTime(500, (int)sw.ElapsedMilliseconds));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
catch (ThreadAbortException)
|
||||
{
|
||||
ncHandler.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Functions
|
||||
|
||||
|
||||
#region SupportFunctions
|
||||
|
||||
|
||||
private static void TryNcConnection()
|
||||
{
|
||||
// Stop all the NC threads
|
||||
|
||||
Reference in New Issue
Block a user