From 9ec6bd9ad2b87897c0141e80e4cf7def752bf409 Mon Sep 17 00:00:00 2001 From: Lucio Maranta Date: Tue, 12 Mar 2019 16:42:41 +0000 Subject: [PATCH] Fixed issue # --- CMS_CORE_Library/Demo/Nc_Demo.cs | 2 +- CMS_CORE_Library/Fanuc/Nc_Fanuc.cs | 3 +- CMS_CORE_Library/Models/DataStructures.cs | 2 +- CMS_CORE_Library/Osai/Nc_Osai.cs | 22 +++--- CMS_CORE_Library/Siemens/Nc_Siemens.cs | 89 ++++++++++++++--------- CMS_CORE_Library/Utils/Nc_Utils.cs | 2 +- 6 files changed, 72 insertions(+), 48 deletions(-) diff --git a/CMS_CORE_Library/Demo/Nc_Demo.cs b/CMS_CORE_Library/Demo/Nc_Demo.cs index a52415d..a9c916b 100644 --- a/CMS_CORE_Library/Demo/Nc_Demo.cs +++ b/CMS_CORE_Library/Demo/Nc_Demo.cs @@ -690,7 +690,7 @@ namespace CMS_CORE_Library.Demo Id = (uint)i + 1, Process = readValues[headOffset], Override = readValues[headOffset + 1], - Load_Abrasive = BitConverter.ToUInt16(readValues.ToArray(), headOffset + 2), // Uint16 = 2 byte + Load_Abrasive = BitConverter.ToInt16(readValues.ToArray(), headOffset + 2), // Uint16 = 2 byte ActualSpeed_Pressure = BitConverter.ToInt32(readValues.ToArray(), headOffset + 4), // Int32 = 4byte MountedTool_Vacum = BitConverter.ToInt16(readValues.ToArray(), headOffset + 8), // Uint 16 = 2byte IsActive = (readValues[headOffset + 10] & 1) != 0, // bit 0 diff --git a/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs b/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs index 251db21..829e060 100644 --- a/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs +++ b/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs @@ -811,7 +811,7 @@ namespace CMS_CORE_Library.Fanuc Id = (uint)i + 1, Process = readValues[headOffset], Override = readValues[headOffset + 1], - Load_Abrasive = BitConverter.ToUInt16(readValues.ToArray(), headOffset + 2), // Uint 16 = 2byte + Load_Abrasive = BitConverter.ToInt16(readValues.ToArray(), headOffset + 2), // Uint 16 = 2byte MountedTool_Vacum = BitConverter.ToInt16(readValues.ToArray(), headOffset + 4), // Uint 16 = 2byte ActualSpeed_Pressure = BitConverter.ToInt32(readValues.ToArray(), headOffset + 6), // Int32 = 4byte IsActive = (readValues[headOffset + 10] & 1) != 0, // bit 0 @@ -1162,7 +1162,6 @@ namespace CMS_CORE_Library.Fanuc // Set action ASSISTED_TOOLING_ACTION action = ASSISTED_TOOLING_ACTION.NONE; - if (GetBitValue(procFinalValue, 2)) action = ASSISTED_TOOLING_ACTION.UNLOAD; diff --git a/CMS_CORE_Library/Models/DataStructures.cs b/CMS_CORE_Library/Models/DataStructures.cs index a9b8a75..2d502df 100644 --- a/CMS_CORE_Library/Models/DataStructures.cs +++ b/CMS_CORE_Library/Models/DataStructures.cs @@ -338,7 +338,7 @@ namespace CMS_CORE_Library.Models public uint Id; public byte Process; public byte Override; - public ushort Load_Abrasive; + public short Load_Abrasive; public int ActualSpeed_Pressure; public short MountedTool_Vacum; diff --git a/CMS_CORE_Library/Osai/Nc_Osai.cs b/CMS_CORE_Library/Osai/Nc_Osai.cs index ad59b32..d12a241 100644 --- a/CMS_CORE_Library/Osai/Nc_Osai.cs +++ b/CMS_CORE_Library/Osai/Nc_Osai.cs @@ -778,7 +778,7 @@ namespace CMS_CORE_Library.Osai Id = (uint)i + 1, Process = readValues[headOffset], Override = readValues[headOffset + 1], - Load_Abrasive = BitConverter.ToUInt16(readValues.ToArray(), headOffset + 2), // Uint 16 = 2byte + Load_Abrasive = BitConverter.ToInt16(readValues.ToArray(), headOffset + 2), // Uint 16 = 2byte MountedTool_Vacum = BitConverter.ToInt16(readValues.ToArray(), headOffset + 4), // Uint 16 = 2byte ActualSpeed_Pressure = BitConverter.ToInt32(readValues.ToArray(), headOffset + 6), // Int32 = 4byte IsActive = (readValues[headOffset + 10] & 1) != 0, // bit 0 @@ -856,7 +856,7 @@ namespace CMS_CORE_Library.Osai { // Skip first parameter because it's the message string // Set button with -> id = 1..5 -> value = parameter value - Dictionary buttons = parameters.Skip(2)?.ToDictionary(x => i++, x => x); + Dictionary buttons = parameters.Skip(1)?.ToDictionary(x => i++, x => x); value.Add(new M155InputIsNeededModel() { @@ -890,13 +890,13 @@ namespace CMS_CORE_Library.Osai if (cmsError.IsError()) return cmsError; - byte val = 0; - cmsError = MEM_RWByte(R, 0, M154_STROBE.MemType, M154_STROBE.Address, 0, ref val); + ushort val = 0; + cmsError = MEM_RWWord(R, 0, M154_STROBE.MemType, M154_STROBE.Address, ref val); if (cmsError.IsError()) return cmsError; // Convert a byte to an array of booleans - bool[] bits = ByteToBits(val); + bool[] bits = ByteToBits(Convert.ToByte(val)); string[] parameters; string tmpStr = ""; @@ -1370,7 +1370,9 @@ namespace CMS_CORE_Library.Osai try { // Execute the method - nReturn = OpenNC.GetActivePartProgramFullPath(ProcNumber, out Level, out MainName, out SubName, out uint errorClass, out uint errorNum); + // nReturn = OpenNC.GetActivePartProgramFullPath(ProcNumber, out Level, out MainName, out SubName, out uint errorClass, out uint errorNum); + // WAITING OSAI FIX + nReturn = OpenNC.GetActivePartProgram(ProcNumber, out Level, out MainName, out SubName, out uint errorClass, out uint errorNum); // If there's an error launch exception if (errorClass != 0 || errorNum != 0 || nReturn == 0) @@ -3915,7 +3917,9 @@ namespace CMS_CORE_Library.Osai try { //Execute the method - nReturn = OpenNC.GetActivePartProgramFullPath(procNumber, out Level, out mainPath, out SubPath, out errorClass, out errorNum); + // nReturn = OpenNC.GetActivePartProgramFullPath(procNumber, out Level, out mainPath, out SubPath, out errorClass, out errorNum); + // WAIT + nReturn = OpenNC.GetActivePartProgram(procNumber, out Level, out mainPath, out SubPath, out errorClass, out errorNum); //If there's an error launch exception\ if (errorClass != 0 || errorNum != 0 || nReturn == 0) @@ -4214,8 +4218,8 @@ namespace CMS_CORE_Library.Osai internal static MEMORY_CELL M155_INPUT_STROBE = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 4310, 1); internal static MEMORY_CELL M154_SWITCH_ONOFF = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 4000, 1, 2); - internal static MEMORY_CELL M154_STROBE = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 4312, 1); - internal static MEMORY_CELL M154_ACK = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 4314, 1); + internal static MEMORY_CELL M154_STROBE = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 4314, 1); + internal static MEMORY_CELL M154_ACK = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 4312, 1); internal static MEMORY_CELL AXES_BUTTON_VISIBLE = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 4320, 16); diff --git a/CMS_CORE_Library/Siemens/Nc_Siemens.cs b/CMS_CORE_Library/Siemens/Nc_Siemens.cs index c31dd6f..12998ac 100644 --- a/CMS_CORE_Library/Siemens/Nc_Siemens.cs +++ b/CMS_CORE_Library/Siemens/Nc_Siemens.cs @@ -257,21 +257,33 @@ namespace CMS_CORE_Library.Siemens private void ManageAxes(Guid guid, Item[] item, DataSvcStatus[] status) { - MachineAxesPosition.Clear(); - ProgrammedAxisPosition.Clear(); - InterpAxesPosition.Clear(); - ToGoAxesPosition.Clear(); - - for (int i = 0; i < AxesData.Count(); i++) + lock (MachineAxesPosition) { - if(status[i * 4].Ok) - MachineAxesPosition.Add(item[i * 4].SymbolicName, Convert.ToDouble(item[i * 4].Value)); - if(status[i * 4 + 1].Ok) - ProgrammedAxisPosition.Add(item[i * 4 + 1].SymbolicName, Convert.ToDouble(item[i * 4 + 1].Value)); - if (status[i * 4 + 2].Ok) - InterpAxesPosition.Add(item[i * 4 + 2].SymbolicName, Convert.ToDouble(item[i * 4 + 2].Value)); - if (status[i * 4 + 3].Ok) - ToGoAxesPosition.Add(item[i * 4 + 3].SymbolicName, Convert.ToDouble(item[i * 4 + 3].Value)); + lock(ProgrammedAxisPosition) + { + lock (InterpAxesPosition) + { + lock (ToGoAxesPosition) + { + MachineAxesPosition.Clear(); + ProgrammedAxisPosition.Clear(); + InterpAxesPosition.Clear(); + ToGoAxesPosition.Clear(); + + for (int i = 0; i < AxesData.Count(); i++) + { + if (status[i * 4].Ok) + MachineAxesPosition.Add(item[i * 4].SymbolicName, Convert.ToDouble(item[i * 4].Value)); + if (status[i * 4 + 1].Ok) + ProgrammedAxisPosition.Add(item[i * 4 + 1].SymbolicName, Convert.ToDouble(item[i * 4 + 1].Value)); + if (status[i * 4 + 2].Ok) + InterpAxesPosition.Add(item[i * 4 + 2].SymbolicName, Convert.ToDouble(item[i * 4 + 2].Value)); + if (status[i * 4 + 3].Ok) + ToGoAxesPosition.Add(item[i * 4 + 3].SymbolicName, Convert.ToDouble(item[i * 4 + 3].Value)); + } + } + } + } } } @@ -1003,7 +1015,7 @@ namespace CMS_CORE_Library.Siemens Id = (uint)i + 1, Process = readValues[headOffset], Override = readValues[headOffset + 1], - Load_Abrasive = SwapShortEndianFormat(BitConverter.ToUInt16(readValues.ToArray(), headOffset + 2)), // Uint 16 = 2byte + Load_Abrasive = SwapShortEndianFormat(BitConverter.ToInt16(readValues.ToArray(), headOffset + 2)), // Uint 16 = 2byte MountedTool_Vacum = toolId, // Uint 16 = 2byte ActualSpeed_Pressure = SwapIntEndianFormat(BitConverter.ToInt32(readValues.ToArray(), headOffset + 6)), // Int32 = 4byte IsActive = (readValues[headOffset + 10] & 1) != 0, // bit 0 @@ -1804,11 +1816,14 @@ namespace CMS_CORE_Library.Siemens { axes = new Dictionary(); - // Cycle between axes - // The dictionary is written asynchronously so i have to create a copy of the dictionary with .ToList() to avoid exceptions - foreach (var axis in MachineAxesPosition.ToList()) + lock (MachineAxesPosition) { - axes.Add(axis.Key, axis.Value); + // Cycle between axes + // The dictionary is written asynchronously so i have to create a copy of the dictionary with .ToList() to avoid exceptions + foreach (var axis in MachineAxesPosition.ToList()) + { + axes.Add(axis.Key, axis.Value); + } } } catch (Exception ex) @@ -1824,12 +1839,14 @@ namespace CMS_CORE_Library.Siemens try { axes = new Dictionary(); - - // Cycle between axes - // The dictionary is written asynchronously so i have to create a copy of the dictionary with .ToList() to avoid exceptions - foreach (var axis in ProgrammedAxisPosition.ToList()) + lock (ProgrammedAxisPosition) { - axes.Add(axis.Key, axis.Value); + // Cycle between axes + // The dictionary is written asynchronously so i have to create a copy of the dictionary with .ToList() to avoid exceptions + foreach (var axis in ProgrammedAxisPosition.ToList()) + { + axes.Add(axis.Key, axis.Value); + } } } catch (Exception ex) @@ -1845,12 +1862,14 @@ namespace CMS_CORE_Library.Siemens try { axes = new Dictionary(); - - // Cycle between axes - // The dictionary is written asynchronously so i have to create a copy of the dictionary with .ToList() to avoid exceptions - foreach (var axis in InterpAxesPosition.ToList()) + lock (InterpAxesPosition) { - axes.Add(axis.Key, axis.Value); + // Cycle between axes + // The dictionary is written asynchronously so i have to create a copy of the dictionary with .ToList() to avoid exceptions + foreach (var axis in InterpAxesPosition.ToList()) + { + axes.Add(axis.Key, axis.Value); + } } } catch (Exception ex) @@ -1866,12 +1885,14 @@ namespace CMS_CORE_Library.Siemens try { axes = new Dictionary(); - - // Cycle between axes - // The dictionary is written asynchronously so i have to create a copy of the dictionary with .ToList() to avoid exceptions - foreach (var axis in ToGoAxesPosition.ToList()) + lock (ToGoAxesPosition) { - axes.Add(axis.Key, axis.Value); + // Cycle between axes + // The dictionary is written asynchronously so i have to create a copy of the dictionary with .ToList() to avoid exceptions + foreach (var axis in ToGoAxesPosition.ToList()) + { + axes.Add(axis.Key, axis.Value); + } } } catch (Exception ex) diff --git a/CMS_CORE_Library/Utils/Nc_Utils.cs b/CMS_CORE_Library/Utils/Nc_Utils.cs index 2ccb63d..389fd5b 100644 --- a/CMS_CORE_Library/Utils/Nc_Utils.cs +++ b/CMS_CORE_Library/Utils/Nc_Utils.cs @@ -238,7 +238,7 @@ namespace CMS_CORE_Library.Utils { string tmpString = codeLine; if (endPos != -1) - tmpString = codeLine.Substring(startPos, endPos - startPos - 1); + tmpString = codeLine.Substring(startPos + 1 , endPos - startPos - 1); returnVal = tmpString.Trim(';').Split(',');