Added magazine action SignalR thread
This commit is contained in:
Binary file not shown.
@@ -1,5 +1,6 @@
|
||||
using Step.Core;
|
||||
using Step.Model.DTOModels;
|
||||
using Step.Model.DTOModels.ToolModels;
|
||||
using Step.NC;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
@@ -24,7 +25,7 @@ public static class ThreadsFunctions
|
||||
|
||||
private static Thread ConnThread;
|
||||
|
||||
#region Nc Threads
|
||||
#region Nc functions threads
|
||||
|
||||
public static void ReadAlarms()
|
||||
{
|
||||
@@ -394,7 +395,51 @@ public static class ThreadsFunctions
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Nc Threads
|
||||
public static void ReadMagazinesStatus()
|
||||
{
|
||||
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 config and PLC
|
||||
libraryError = ncHandler.GetMagazineStatus(out DTOMagazineActionModel magazineStatus);
|
||||
if (libraryError.errorCode != 0)
|
||||
ManageLibraryError(libraryError);
|
||||
else
|
||||
// Send through signalR
|
||||
MessageServices.Current.Publish(SEND_MAGAZINES_STATUS, null, magazineStatus);
|
||||
}
|
||||
else
|
||||
TryNcConnection();
|
||||
|
||||
sw.Stop();
|
||||
|
||||
//Update thread timer
|
||||
ReadAxesNamesTimer += sw.ElapsedMilliseconds;
|
||||
ReadAxesNamesTimes++;
|
||||
|
||||
// Wait
|
||||
Thread.Sleep(CalcSleepTime(200, (int)sw.ElapsedMilliseconds));
|
||||
}
|
||||
}
|
||||
catch (ThreadAbortException)
|
||||
{
|
||||
ncHandler.Dispose();
|
||||
}
|
||||
}
|
||||
#endregion Nc threads
|
||||
|
||||
#region SupportFunctions
|
||||
|
||||
@@ -582,7 +627,7 @@ public static class ThreadsFunctions
|
||||
{
|
||||
int sleep = 0;
|
||||
// Check if the execution time is greater than the half of the max sleep time
|
||||
if ( maxSleep - execTime < maxSleep / 2 )
|
||||
if (maxSleep - execTime < maxSleep / 2)
|
||||
{
|
||||
sleep = maxSleep;
|
||||
}
|
||||
@@ -593,51 +638,6 @@ public static class ThreadsFunctions
|
||||
|
||||
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();
|
||||
// }
|
||||
//}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ namespace Step.Core
|
||||
ThreadsFunctions.ReadEnabledFunctionality,
|
||||
ThreadsFunctions.ReadExpiredMaintenances,
|
||||
// ThreadsFunctions.ReadNcSoftKeysData,
|
||||
ThreadsFunctions.ReadMagazinesStatus,
|
||||
ThreadsFunctions.ReadUserSoftKeysData,
|
||||
ThreadsFunctions.ReadHeadsData,
|
||||
ThreadsFunctions.ReadAxesNamesData
|
||||
|
||||
@@ -124,6 +124,7 @@ namespace Step.Model
|
||||
public const string SEND_NC_SOFTKEYS_DATA = "SEND_NC_SOFTKEYS_DATA";
|
||||
public const string SEND_HEADS_DATA = "SEND_HEADS_DATA";
|
||||
public const string SEND_AXIS_NAMES_DATA = "SEND_AXIS_NAMES_DATA";
|
||||
public const string SEND_MAGAZINES_STATUS = "SEND_MAGAZINES_STATUS";
|
||||
|
||||
public const string BROADCAST_DATA = "BROADCAST_DATA";
|
||||
|
||||
|
||||
@@ -101,6 +101,7 @@
|
||||
<Compile Include="DTOModels\DTOStartupConfigurationModel.cs" />
|
||||
<Compile Include="DTOModels\DTOUserModel.cs" />
|
||||
<Compile Include="DTOModels\ToolModels\DTOEdgeModel.cs" />
|
||||
<Compile Include="DTOModels\ToolModels\DTOMagazineStatusModel.cs" />
|
||||
<Compile Include="DTOModels\ToolModels\DTOShankModel.cs" />
|
||||
<Compile Include="DTOModels\ToolModels\DTOSiemensToolModel.cs" />
|
||||
<Compile Include="DTOModels\ToolModels\DTOUpdateMagazineModel.cs" />
|
||||
|
||||
@@ -6,6 +6,7 @@ using CMS_CORE.Siemens;
|
||||
using Step.Database.Controllers;
|
||||
using Step.Model.DatabaseModels;
|
||||
using Step.Model.DTOModels;
|
||||
using Step.Model.DTOModels.ToolModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
@@ -674,6 +675,22 @@ namespace Step.NC
|
||||
magazinesPositions = new List<PositionModel>();
|
||||
return numericalControl.TOOLS_RMagazinePositions(ref magazinesPositions);
|
||||
}
|
||||
|
||||
public CmsError GetMagazineStatus(out DTOMagazineActionModel magazineStatus)
|
||||
{
|
||||
// Set up models
|
||||
magazineStatus= new DTOMagazineActionModel();
|
||||
MagazineActionModel libModel = new MagazineActionModel();
|
||||
// Read status from NC
|
||||
CmsError cmsError = numericalControl.TOOLS_GetMagazinesStatus(ref libModel);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
magazineStatus = (DTOMagazineActionModel)libModel;
|
||||
|
||||
return cmsError;
|
||||
}
|
||||
|
||||
#endregion Read Data
|
||||
|
||||
#region Write data
|
||||
|
||||
@@ -63,6 +63,10 @@ namespace Step.Listeners
|
||||
{
|
||||
SignalRListener.SendAxesNamesData(a);
|
||||
}));
|
||||
infos.Add(MessageServices.Current.Subscribe(SEND_MAGAZINES_STATUS, async (a, b) =>
|
||||
{
|
||||
SignalRListener.SendMagazinesStatus(a);
|
||||
}));
|
||||
|
||||
infos.Add(MessageServices.Current.Subscribe(BROADCAST_DATA, async (a, b) =>
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Step.Config;
|
||||
using Step.Controllers.SignalR;
|
||||
using Step.Model.DTOModels;
|
||||
using Step.Model.DTOModels.ToolModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
@@ -21,6 +22,7 @@ namespace Step.Listeners.SignalR
|
||||
private static List<DTONcSoftKeyModel> LastNcSoftKeysData = new List<DTONcSoftKeyModel>();
|
||||
private static List<DTOHeadModel> LastHeadsData = new List<DTOHeadModel>();
|
||||
private static List<DTOAxisNameModel> LastAxesNamesData = new List<DTOAxisNameModel>();
|
||||
private static DTOMagazineActionModel LastMagazineStatus = new DTOMagazineActionModel();
|
||||
|
||||
private static bool LastIsNcConnected = false;
|
||||
|
||||
@@ -176,6 +178,17 @@ namespace Step.Listeners.SignalR
|
||||
}
|
||||
}
|
||||
|
||||
public static void SendMagazinesStatus(object magazinesStatus)
|
||||
{
|
||||
var context = GlobalHost.ConnectionManager.GetHubContext<NcHub>();
|
||||
if (!LastMagazineStatus.Equals(magazinesStatus))
|
||||
{
|
||||
LastMagazineStatus = magazinesStatus as DTOMagazineActionModel;
|
||||
|
||||
context.Clients.Group("ncData").magazinesStatus(magazinesStatus);
|
||||
}
|
||||
}
|
||||
|
||||
private volatile static object _broadcastlock = new Object();
|
||||
|
||||
public static void BroadcastData()
|
||||
@@ -210,12 +223,14 @@ namespace Step.Listeners.SignalR
|
||||
|
||||
// Send softkeys Nc
|
||||
context.Clients.Group("ncData").ncSoftKeys(LastNcSoftKeysData);
|
||||
// Send user softKeys
|
||||
// Send user softKeys
|
||||
context.Clients.Group("ncData").userSoftKeys(LastUserSoftKeysData);
|
||||
// Send heads data
|
||||
context.Clients.Group("ncData").headsData(LastHeadsData);
|
||||
// Send axesNames data
|
||||
context.Clients.Group("ncData").axesNames(LastAxesNamesData);
|
||||
// Send magazine status
|
||||
context.Clients.Group("ncData").magazinesStatus(LastMagazineStatus);
|
||||
|
||||
Debug.WriteLine(string.Format("{0} {1} Broadcast..completed", DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"), DateTime.Now.Millisecond));
|
||||
Monitor.Exit(_broadcastlock);
|
||||
|
||||
Reference in New Issue
Block a user