From 69733580e86faac985c5d245ee15507e0d083117 Mon Sep 17 00:00:00 2001 From: Lucio Maranta Date: Mon, 4 Feb 2019 17:34:42 +0100 Subject: [PATCH] Fix m154 --- Step.Core/ThreadsFunctions.cs | 21 ++++++++++------ Step.NC/NcHandler.cs | 9 +++++-- .../Database/SignalRDatabaseHandler.cs | 25 +++++++++++++++++-- 3 files changed, 43 insertions(+), 12 deletions(-) diff --git a/Step.Core/ThreadsFunctions.cs b/Step.Core/ThreadsFunctions.cs index ac9269f5..091bd311 100644 --- a/Step.Core/ThreadsFunctions.cs +++ b/Step.Core/ThreadsFunctions.cs @@ -22,7 +22,7 @@ public static class ThreadsFunctions public static bool reconnectionIsRunning = false; private static long ReadAlarmsTimer = 0, ReadAlarmsTimes = 0; private static long ReadAxesTimer = 0, ReadAxesTimes = 0; - private static long ReadPowerOnTimer = 0, ReadPowerOnTimes = 0; + private static long ReadPowerOnTimer = 0, ReadPowerOnTimes = 0; private static long ReadProcPPTimer = 0, ReadProcPPTimes = 0; private static long ReadFunctionTimer = 0, ReadFunctionTimes = 0; private static long ReadMaintenanceTimer = 0, ReadMaintenanceTimes = 0; @@ -787,14 +787,14 @@ public static class ThreadsFunctions if (libraryError.IsError()) ManageLibraryError(libraryError); - string MTCProcessName = "PROGRAMPARSER_MTC_ADAPTER"; - string ApplicationPath = ServerStartupConfig.MTCFolderPath + ServerStartupConfig.MTCApplicationName + ".exe"; + string ApplicationPath = ServerStartupConfig.MTCFolderPath + "\\" + ServerStartupConfig.MTCApplicationName + ".exe"; if (ServerStartupConfig.MTCFolderPath != "") { // Check if process exists - Process[] processes = Process.GetProcessesByName(MTCProcessName); + Process[] processes = Process.GetProcessesByName(ServerStartupConfig.MTCApplicationName); if (!MTCStatus) { + // Kill if is running if (processes.Count() > 0) processes[0].Kill(); } @@ -836,15 +836,15 @@ public static class ThreadsFunctions if (!Directory.Exists(ServerStartupConfig.MTCFolderPath)) Directory.CreateDirectory(ServerStartupConfig.MTCFolderPath); - string outputFileName = ServerStartupConfig.MTCFolderPath + "CmsGeneralStatus.mtc"; + string outputFileName = ServerStartupConfig.MTCFolderPath + "\\DATA\\CmsGeneralStatus.mtc"; // Create file if not exits if (!File.Exists(outputFileName)) - File.Create(outputFileName); + using (var f = File.Create(outputFileName)) { }; // Read file List fileLines = File.ReadAllLines(outputFileName).ToList(); string[] parametersInLine; bool found = false; - for (int i = 0; i < fileLines.Count(); i++) + for (int i = 0; i < fileLines.Count() && !found; i++) { // Get tag & value from row parametersInLine = fileLines[i].Split('|'); @@ -859,7 +859,12 @@ public static class ThreadsFunctions fileLines.Add(stringVal + "|" + val); // Write file - File.WriteAllLines(ServerStartupConfig.MTCFolderPath, fileLines.ToArray()); + File.WriteAllLines(outputFileName, fileLines.ToArray()); + + // Write ack + libraryError = ncHandler.WriteM154Ack((int)m154.Process); + if (libraryError.IsError()) + ManageLibraryError(libraryError); } } } diff --git a/Step.NC/NcHandler.cs b/Step.NC/NcHandler.cs index 6905fe5e..7ea4e575 100644 --- a/Step.NC/NcHandler.cs +++ b/Step.NC/NcHandler.cs @@ -222,7 +222,7 @@ namespace Step.NC TimeLeft = data.TimeLeft }; - return cmsError; + return cmsError; // TODO FIX OSAI } public CmsError SetActiveProgramInfo(string path, out DTOActiveProgramDataModel dtoData) @@ -1385,11 +1385,16 @@ namespace Step.NC public CmsError GetM154Data(out List data, out bool MTCStatus) { MTCStatus = false; - data = new List(); + data = new List(); return numericalControl.PLC_RM154Data(ref data, ref MTCStatus); } + public CmsError WriteM154Ack(int processId) + { + return numericalControl.PLC_W154ManageAck(processId); + } + #endregion Read Data #region Write data diff --git a/Step/Listeners/Database/SignalRDatabaseHandler.cs b/Step/Listeners/Database/SignalRDatabaseHandler.cs index 462f7724..ab564cba 100644 --- a/Step/Listeners/Database/SignalRDatabaseHandler.cs +++ b/Step/Listeners/Database/SignalRDatabaseHandler.cs @@ -27,7 +27,7 @@ namespace Step.Listeners.Database List dbTools = controller.FindTools(); if (dbTools.Count > 0) { - // Loop through new data + // Loop through new data foreach (var live in data.UpdatedLives) { // Find tool and update residual life @@ -50,7 +50,7 @@ namespace Step.Listeners.Database .Where(x => x.ToolId == status.Key) // Get tool by id ?.Select(x => { - x.Status = status.Value; + x.Status = UpdateStatus(x.Status, status.Value); return x; }) .FirstOrDefault(); @@ -73,6 +73,27 @@ namespace Step.Listeners.Database } } + private static byte UpdateStatus(byte oldValue, byte newValue) + { + switch (newValue) + { + case 1: + return (byte)(oldValue | (1 << 0)); + case 2: + return (byte)(oldValue | (1 << 1)); + case 3: + return (byte)(oldValue | (1 << 2)); + case 9: + return (byte)(oldValue | (0 << 0)); + case 10: + return (byte)(oldValue | (0 << 1)); + case 11: + return (byte)(oldValue | (0 << 2)); + } + + return 0; + } + public static void UpdateQueue(object queue) { List newQueue = queue as List;