diff --git a/Libs/CMS_CORE_Library.dll b/Libs/CMS_CORE_Library.dll
index 532637c8..e1ad7996 100644
Binary files a/Libs/CMS_CORE_Library.dll and b/Libs/CMS_CORE_Library.dll differ
diff --git a/Step.Core/ThreadsFunctions.cs b/Step.Core/ThreadsFunctions.cs
index 4979a0ec..9e89e03c 100644
--- a/Step.Core/ThreadsFunctions.cs
+++ b/Step.Core/ThreadsFunctions.cs
@@ -484,6 +484,52 @@ public static class ThreadsFunctions
ncHandler.Dispose();
}
}
+
+ public static void ReadActiveProgramData()
+ {
+ 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.GetActiveProgramInfo(out DTOActiveProgramDataModel active);
+ if (libraryError.errorCode != 0)
+ ManageLibraryError(libraryError);
+ else
+ // Send through signalR
+ MessageServices.Current.Publish(SEND_ACTIVE_PROGRAM_DATA, null, active);
+ }
+ else
+ TryNcConnection();
+
+ sw.Stop();
+
+ //Update thread timer
+ ReadAxesNamesTimer += sw.ElapsedMilliseconds;
+ ReadAxesNamesTimes++;
+
+ // Wait
+ Thread.Sleep(CalcSleepTime(400, (int)sw.ElapsedMilliseconds));
+ }
+ }
+ catch (ThreadAbortException)
+ {
+ ncHandler.Dispose();
+ }
+ }
+
#endregion Nc threads
#region SupportFunctions
diff --git a/Step.Core/ThreadsHandler.cs b/Step.Core/ThreadsHandler.cs
index 109d0516..44b8afdc 100644
--- a/Step.Core/ThreadsHandler.cs
+++ b/Step.Core/ThreadsHandler.cs
@@ -20,7 +20,8 @@ namespace Step.Core
ThreadsFunctions.ReadMagazinesStatus,
ThreadsFunctions.ReadUserSoftKeysData,
ThreadsFunctions.ReadHeadsData,
- ThreadsFunctions.ReadAxesNamesData
+ ThreadsFunctions.ReadAxesNamesData,
+ ThreadsFunctions.ReadActiveProgramData
// ThreadsFunctions.ReadNcSoftKeysData,
};
diff --git a/Step.Model/Constants.cs b/Step.Model/Constants.cs
index 8a993f37..901b7a11 100644
--- a/Step.Model/Constants.cs
+++ b/Step.Model/Constants.cs
@@ -150,6 +150,7 @@ namespace Step.Model
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 SEND_ACTIVE_PROGRAM_DATA = "SEND_ACTIVE_PROGRAM_DATA";
public const string BROADCAST_DATA = "BROADCAST_DATA";
diff --git a/Step.Model/DTOModels/DTOActiveProgramInfoModel.cs b/Step.Model/DTOModels/DTOActiveProgramInfoModel.cs
new file mode 100644
index 00000000..f0839563
--- /dev/null
+++ b/Step.Model/DTOModels/DTOActiveProgramInfoModel.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using static CMS_CORE_Library.DataStructures;
+
+namespace Step.Model.DTOModels
+{
+ public class DTOActiveProgramDataModel : ActiveProgramDataModel
+ {
+ public override bool Equals(object obj)
+ {
+ var item = obj as DTOActiveProgramDataModel;
+ if (item == null)
+ return false;
+
+ if (Path != item.Path)
+ return false;
+ if (!IsoLines.SequenceEqual(item.IsoLines))
+ return false;
+ if (TimeLeft != item.TimeLeft)
+ return false;
+
+ return true;
+ }
+ }
+}
diff --git a/Step.Model/Step.Model.csproj b/Step.Model/Step.Model.csproj
index 355ea9d2..fc5396ee 100644
--- a/Step.Model/Step.Model.csproj
+++ b/Step.Model/Step.Model.csproj
@@ -82,6 +82,7 @@
+
diff --git a/Step.NC/NcHandler.cs b/Step.NC/NcHandler.cs
index 88dbd310..3bf8a66d 100644
--- a/Step.NC/NcHandler.cs
+++ b/Step.NC/NcHandler.cs
@@ -78,6 +78,36 @@ namespace Step.NC
return numericalControl.FILES_RGetFileInfo(path, ref fileInfo);
}
+ public CmsError GetActiveProgramInfo(out DTOActiveProgramDataModel dtoData)
+ {
+ ActiveProgramDataModel data = new ActiveProgramDataModel();
+ CmsError cmsError = numericalControl.FILES_RActiveProgramData(ref data);
+
+ dtoData = new DTOActiveProgramDataModel()
+ {
+ IsoLines = data.IsoLines,
+ Path = data.Path,
+ TimeLeft = data.TimeLeft
+ };
+
+ return cmsError;
+ }
+
+ public CmsError SetActiveProgramInfo(string path, out DTOActiveProgramDataModel dtoData)
+ {
+ ActiveProgramDataModel data = new ActiveProgramDataModel();
+ CmsError cmsError = numericalControl.FILES_WSetActiveProgram(path, ref data);
+
+ dtoData = new DTOActiveProgramDataModel()
+ {
+ IsoLines = data.IsoLines,
+ Path = data.Path,
+ TimeLeft = data.TimeLeft
+ };
+
+ return cmsError;
+ }
+
#endregion
#region Read Data
diff --git a/Step/Controllers/WebApi/NcFileController.cs b/Step/Controllers/WebApi/NcFileController.cs
index 87452262..d6b91258 100644
--- a/Step/Controllers/WebApi/NcFileController.cs
+++ b/Step/Controllers/WebApi/NcFileController.cs
@@ -1,4 +1,5 @@
-using Step.NC;
+using Step.Model.DTOModels;
+using Step.NC;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -45,5 +46,20 @@ namespace Step.Controllers.WebApi
return Ok(fileInfo);
}
}
+
+ [Route("file/active"), HttpPut]
+ public IHttpActionResult SetActiveProgram([FromUri]string filePath)
+ {
+ using (NcHandler ncHandler = new NcHandler())
+ {
+ ncHandler.Connect();
+
+ CmsError cmsError = ncHandler.SetActiveProgramInfo(filePath, out DTOActiveProgramDataModel fileInfo);
+ if (cmsError.IsError())
+ return BadRequest(cmsError.localizationKey);
+
+ return Ok(fileInfo);
+ }
+ }
}
}
diff --git a/Step/Listeners/ListenersHandler.cs b/Step/Listeners/ListenersHandler.cs
index 0cad27ad..94b7044b 100644
--- a/Step/Listeners/ListenersHandler.cs
+++ b/Step/Listeners/ListenersHandler.cs
@@ -67,11 +67,14 @@ namespace Step.Listeners
{
SignalRListener.SendAxesToClient(a);
}));
-
infos.Add(MessageServices.Current.Subscribe(SEND_MAGAZINES_STATUS, async (a, b) =>
{
SignalRListener.SendMagazinesStatus(a);
}));
+ infos.Add(MessageServices.Current.Subscribe(SEND_ACTIVE_PROGRAM_DATA, async (a, b) =>
+ {
+ SignalRListener.SendActiveProgramData(a);
+ }));
infos.Add(MessageServices.Current.Subscribe(BROADCAST_DATA, async (a, b) =>
{
diff --git a/Step/Listeners/SignalR/SignalRListener.cs b/Step/Listeners/SignalR/SignalRListener.cs
index bacfef4f..66eb67fd 100644
--- a/Step/Listeners/SignalR/SignalRListener.cs
+++ b/Step/Listeners/SignalR/SignalRListener.cs
@@ -24,6 +24,7 @@ namespace Step.Listeners.SignalR
private static DTOAxesModel LastAxesPositions = new DTOAxesModel();
private static List LastAxesNamesData = new List();
private static DTOMagazineActionModel LastMagazineStatus = new DTOMagazineActionModel();
+ private static DTOActiveProgramDataModel LastProgramData = new DTOActiveProgramDataModel();
private static bool LastIsNcConnected = false;
@@ -201,6 +202,16 @@ namespace Step.Listeners.SignalR
}
}
+ public static void SendActiveProgramData(object programData)
+ {
+ var context = GlobalHost.ConnectionManager.GetHubContext();
+ if (!LastProgramData.Equals(programData))
+ {
+ LastProgramData = programData as DTOActiveProgramDataModel;
+
+ context.Clients.Group("ncData").activeProgramData(programData);
+ }
+ }
private volatile static object _broadcastlock = new Object();
public static void BroadcastData()