Added axes names and selected axis

This commit is contained in:
Lucio Maranta
2018-03-20 17:02:59 +01:00
parent e9110db28b
commit 696aa24341
11 changed files with 241 additions and 62 deletions
Binary file not shown.
+1
View File
@@ -123,6 +123,7 @@ namespace Step.Model
public const string SEND_USER_SOFTKEYS_DATA = "SEND_USER_SOFTKEYS_DATA";
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 BROADCAST_DATA = "BROADCAST_DATA";
+29
View File
@@ -0,0 +1,29 @@
using static CMS_CORE_Library.DataStructures;
namespace Step.Model.DTOModels
{
public class DTOAxisNameModel : AxisModel
{
public override bool Equals(object obj)
{
var item = obj as DTOAxisNameModel;
// Object is not a DTOAxisNameModel instance
if (item == null)
return false;
if (item.Id != Id)
return false;
if (item.Name != Name)
return false;
return true;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
}
@@ -8,6 +8,7 @@ namespace Step.Model.DTOModels
{
public bool isRunning;
public ushort selectedProcess;
public byte selectedAxis;
public List<ProcessDataModel> processes;
public DTOProcessDataModel()
+1
View File
@@ -82,6 +82,7 @@
<Compile Include="DatabaseModels\SessionModel.cs" />
<Compile Include="DTOModels\DTOAlarmsModel.cs" />
<Compile Include="DTOModels\DTOAxesModel.cs" />
<Compile Include="DTOModels\DTOAxisNameModel.cs" />
<Compile Include="DTOModels\DTOClientConfigurationModel.cs" />
<Compile Include="DTOModels\DTOExpiredMaintenanceModel.cs" />
<Compile Include="DTOModels\DTOHeadModel.cs" />
+37 -4
View File
@@ -9,7 +9,7 @@ using Step.Model.DTOModels;
using System;
using System.Collections.Generic;
using System.Globalization;
using static CMS_CORE.Nc;
using System.Linq;
using static CMS_CORE_Library.DataStructures;
using static Step.Config.ServerConfig;
using static Step.Model.Constants;
@@ -304,6 +304,10 @@ namespace Step.NC
// Read selected process
cmsError = numericalControl.PROC_RSelectedProcess(ref processesData.selectedProcess);
if (cmsError.IsError())
return cmsError;
// Read selected axes
cmsError = numericalControl.AXES_RSelectedAxis(ref processesData.selectedAxis);
return cmsError;
}
@@ -487,6 +491,7 @@ namespace Step.NC
return cmsError;
}
public CmsError GetNcSoftKeys(out List<DTONcSoftKeyModel> ncSoftKeys)
{
ncSoftKeys = new List<DTONcSoftKeyModel>();
@@ -501,8 +506,8 @@ namespace Step.NC
{
// Find the plc matching data
var plcSoftKey = plcSoftKeys.Find(x => x.Id == softKey.Id);
// Create and add Nc softkey model
// Create and add Nc softkey model
ncSoftKeys.Add(new DTONcSoftKeyModel()
{
Id = softKey.Id,
@@ -527,7 +532,7 @@ namespace Step.NC
if (cmsError.IsError())
return cmsError;
foreach(var head in plcHeads)
foreach (var head in plcHeads)
{
// Get current head config
var configuredHead = HeadsConfig.Find(x => x.Id == head.Id);
@@ -551,6 +556,7 @@ namespace Step.NC
});
}
break;
case HEAD_TYPE.AWJ:
{
heads.Add(new DTOAbrasiveWaterJet()
@@ -568,6 +574,7 @@ namespace Step.NC
});
}
break;
case HEAD_TYPE.WJ:
{
heads.Add(new DTOHeadModel()
@@ -588,6 +595,27 @@ namespace Step.NC
return cmsError;
}
public CmsError ReadAxisData(out List<DTOAxisNameModel> axesNames)
{
axesNames = new List<DTOAxisNameModel>();
List<AxisModel> plcAxes = new List<AxisModel>();
// Read selected process
ushort selectedProcess = 0;
CmsError cmsError = numericalControl.PROC_RSelectedProcess(ref selectedProcess);
if (cmsError.IsError())
return cmsError;
// Read axes names
cmsError = numericalControl.AXES_RAxesNames(selectedProcess, ref plcAxes);
axesNames = plcAxes.Select(x => new DTOAxisNameModel()
{
Id = x.Id,
Name = x.Name
}).ToList();
return cmsError;
}
#endregion Read Data
#region Write data
@@ -613,6 +641,11 @@ namespace Step.NC
return numericalControl.PROC_WSelectProcess(procNumber);
}
public CmsError PutSelectAxis(byte axisId)
{
return numericalControl.AXES_WSelectAxis(axisId);
}
public CmsError PutOverride(uint id, string action)
{
HEAD_OVERRIDE_SIGN sign = HEAD_OVERRIDE_SIGN.MINUS;
+121 -48
View File
@@ -19,7 +19,8 @@ public static class ThreadsFunctions
private static long ReadFunctionTimer = 0, ReadFunctionTimes = 0;
private static long ReadMaintenanceTimer = 0, ReadMaintenanceTimes = 0;
private static long ReadUserSoftKeysTimer = 0, ReadUserSoftKeysTimes = 0;
private static long ReadNcSoftKeysTimer = 0, ReadNcSoftKeysTimes = 0;
private static long ReadAxesNamesTimer = 0, ReadAxesNamesTimes = 0;
private static long ReadHeadsTimer = 0, ReadHeadsTimes = 0;
private static Thread ConnThread;
@@ -135,8 +136,19 @@ public static class ThreadsFunctions
if (libraryError.errorCode != 0)
ManageLibraryError(libraryError);
else
// Send through signalR
MessageServices.Current.Publish(SEND_PROCESSES_DATA, null, processesPPData);
{
// Get softkey data from config and PLC
libraryError = ncHandler.GetNcSoftKeys(out List<DTONcSoftKeyModel> ncSoftKeys);
if (libraryError.errorCode != 0)
ManageLibraryError(libraryError);
else
{
// Send processes through signalR
MessageServices.Current.Publish(SEND_PROCESSES_DATA, null, processesPPData);
// Send ncSoftKeys through signalR
MessageServices.Current.Publish(SEND_NC_SOFTKEYS_DATA, null, ncSoftKeys);
}
}
}
else
TryNcConnection();
@@ -292,50 +304,50 @@ public static class ThreadsFunctions
}
}
public static void ReadNcSoftKeysData()
{
NcHandler ncHandler = new NcHandler();
Stopwatch sw = new Stopwatch();
//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);
// try
// {
// // Try connection
// CmsError libraryError = ncHandler.Connect();
// if (libraryError.errorCode != 0)
// ManageLibraryError(libraryError);
while (true)
{
sw.Restart();
// 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();
// 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();
// sw.Stop();
// Update thread timer
ReadUserSoftKeysTimer += sw.ElapsedMilliseconds;
ReadUserSoftKeysTimes++;
// // Update thread timer
// ReadUserSoftKeysTimer += sw.ElapsedMilliseconds;
// ReadUserSoftKeysTimes++;
// Wait
Thread.Sleep(200);
}
}
catch (ThreadAbortException)
{
ncHandler.Dispose();
}
}
// // Wait
// Thread.Sleep(200);
// }
// }
// catch (ThreadAbortException)
// {
// ncHandler.Dispose();
// }
//}
public static void ReadHeadsData()
{
@@ -367,10 +379,10 @@ public static class ThreadsFunctions
TryNcConnection();
sw.Stop();
//Update thread timer
ReadNcSoftKeysTimer += sw.ElapsedMilliseconds;
ReadNcSoftKeysTimes++;
ReadHeadsTimer += sw.ElapsedMilliseconds;
ReadHeadsTimes++;
// Wait
Thread.Sleep(500);
@@ -382,6 +394,51 @@ public static class ThreadsFunctions
}
}
public static void ReadAxesNamesData()
{
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.ReadAxisData(out List<DTOAxisNameModel> axes);
if (libraryError.errorCode != 0)
ManageLibraryError(libraryError);
else
// Send through signalR
MessageServices.Current.Publish(SEND_AXIS_NAMES_DATA, null, axes);
}
else
TryNcConnection();
sw.Stop();
//Update thread timer
ReadAxesNamesTimer += sw.ElapsedMilliseconds;
ReadAxesNamesTimes++;
// Wait
Thread.Sleep(800);
}
}
catch (ThreadAbortException)
{
ncHandler.Dispose();
}
}
#endregion Nc Threads
#region SupportFunctions
@@ -529,12 +586,24 @@ public static class ThreadsFunctions
ReadUserSoftKeysTimer = 0;
ReadUserSoftKeysTimes = 0;
}
if (ThreadsHandler.RunningThreadStatus.ContainsKey("ReadNcSoftKeysData") && ReadNcSoftKeysTimes != 0)
if (ThreadsHandler.RunningThreadStatus.ContainsKey("ReadHeadsData") && ReadHeadsTimes != 0)
{
ThreadsHandler.RunningThreadStatus["ReadNcSoftKeysData"] = (ReadNcSoftKeysTimer / ReadNcSoftKeysTimes) + " mS";
ReadNcSoftKeysTimer = 0;
ReadNcSoftKeysTimes = 0;
ThreadsHandler.RunningThreadStatus["ReadHeadsData"] = (ReadHeadsTimer / ReadHeadsTimes) + " mS";
ReadHeadsTimer = 0;
ReadHeadsTimes = 0;
}
if (ThreadsHandler.RunningThreadStatus.ContainsKey("ReadAxesNamesData") && ReadAxesNamesTimer != 0)
{
ThreadsHandler.RunningThreadStatus["ReadAxesNamesData"] = (ReadAxesNamesTimer / ReadAxesNamesTimes) + " mS";
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);
@@ -554,6 +623,10 @@ public static class ThreadsFunctions
ReadFunctionTimes = 0;
ReadMaintenanceTimer = 0;
ReadMaintenanceTimes = 0;
ReadHeadsTimer = 0;
ReadHeadsTimes = 0;
ReadAxesNamesTimer = 0;
ReadAxesNamesTimes = 0;
}
#endregion SupportFunctions
+3 -2
View File
@@ -16,9 +16,10 @@ namespace Step.Core
ThreadsFunctions.ReadProcessesPPStatus,
ThreadsFunctions.ReadEnabledFunctionality,
ThreadsFunctions.ReadExpiredMaintenances,
ThreadsFunctions.ReadNcSoftKeysData,
// ThreadsFunctions.ReadNcSoftKeysData,
ThreadsFunctions.ReadUserSoftKeysData,
ThreadsFunctions.ReadHeadsData
ThreadsFunctions.ReadHeadsData,
ThreadsFunctions.ReadAxesNamesData
};
private volatile static List<Thread> RunningThreadsList = new List<Thread>();
+23 -5
View File
@@ -142,23 +142,39 @@ namespace Step.Controllers.SignalR
{
using (NcHandler ncHandler = new NcHandler())
{
// Connect the NC
CmsError libraryError = ncHandler.Connect();
// Put value into memory
libraryError = ncHandler.PutSelectProcess(procNumber);
if (libraryError.IsError())
throw new HubException(libraryError.message);
}
}
public void SelectAxis(byte axisId)
{
using (NcHandler ncHandler = new NcHandler())
{
// Connect the Nc
CmsError libraryError = ncHandler.Connect();
// Put value into memory
libraryError = ncHandler.PutSelectAxis(axisId);
if (libraryError.IsError())
throw new HubException(libraryError.message);
}
}
public void AddOverride(uint id)
{
using (NcHandler ncHandler = new NcHandler())
{
// Connect the Nc
CmsError libraryError = ncHandler.Connect();
// Put value into memory
libraryError = ncHandler.PutOverride(id, "plus");
if (libraryError.IsError())
throw new HubException(libraryError.message);
libraryError = ncHandler.PutOverride(id, "plus");
}
}
@@ -166,11 +182,13 @@ namespace Step.Controllers.SignalR
{
using (NcHandler ncHandler = new NcHandler())
{
// Connect the Nc
CmsError libraryError = ncHandler.Connect();
// Put value into memory
libraryError = ncHandler.PutOverride(id, "minus");
if (libraryError.IsError())
throw new HubException(libraryError.message);
libraryError = ncHandler.PutOverride(id, "minus");
}
}
}
+4
View File
@@ -59,6 +59,10 @@ namespace Step.Listeners
{
SignalRListener.SendHeadsData(a);
}));
infos.Add(MessageServices.Current.Subscribe(SEND_AXIS_NAMES_DATA, async (a, b) =>
{
SignalRListener.SendAxesNamesData(a);
}));
infos.Add(MessageServices.Current.Subscribe(BROADCAST_DATA, async (a, b) =>
{
+21 -3
View File
@@ -20,6 +20,7 @@ namespace Step.Listeners.SignalR
private static List<DTOUserSoftKeyModel> LastUserSoftKeysData = new List<DTOUserSoftKeyModel>();
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 bool LastIsNcConnected = false;
@@ -157,7 +158,21 @@ namespace Step.Listeners.SignalR
{
LastHeadsData = newData;
// Send data to clients
context.Clients.Group("ncData").heads(heads);
context.Clients.Group("ncData").headsData(heads);
}
}
public static void SendAxesNamesData(object axesNames)
{
var context = GlobalHost.ConnectionManager.GetHubContext<NcHub>();
List<DTOAxisNameModel> newData = axesNames as List<DTOAxisNameModel>;
// Check if collections are equals
if (newData.Count != LastAxesNamesData.Count || !LastAxesNamesData.All(newData.Contains))
{
LastAxesNamesData = newData;
// Send data to clients
context.Clients.Group("ncData").axesNames(axesNames);
}
}
@@ -192,12 +207,15 @@ namespace Step.Listeners.SignalR
{
connected = LastIsNcConnected
});
// Send softkeys
context.Clients.Group("ncData").ncSoftKeys(LastNcSoftKeysData);
// Send softkeys Nc
context.Clients.Group("ncData").ncSoftKeys(LastNcSoftKeysData);
// Send user softKeys
context.Clients.Group("ncData").userSoftKeys(LastUserSoftKeysData);
// Send heads data
context.Clients.Group("ncData").heads(LastHeadsData);
// Send axesNames data
context.Clients.Group("ncData").axesNames(LastAxesNamesData);
Debug.WriteLine(string.Format("{0} {1} Broadcast..completed", DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"), DateTime.Now.Millisecond));
Monitor.Exit(_broadcastlock);