diff --git a/CMS_CORE_Application/Form1.cs b/CMS_CORE_Application/Form1.cs index 65df3ea..f2e2fe8 100644 --- a/CMS_CORE_Application/Form1.cs +++ b/CMS_CORE_Application/Form1.cs @@ -131,6 +131,8 @@ namespace CMS_CORE_Application } List axes = new List(); + List m155 = new List(); + cmsError = N.PLC_ROperatorInputIsNeeded(ref m155); ////////////// SPEED TEST Stopwatch st = new Stopwatch(); sw.Restart(); diff --git a/CMS_CORE_Library/Siemens/Nc_Siemens.cs b/CMS_CORE_Library/Siemens/Nc_Siemens.cs index 1daf02c..529f328 100644 --- a/CMS_CORE_Library/Siemens/Nc_Siemens.cs +++ b/CMS_CORE_Library/Siemens/Nc_Siemens.cs @@ -95,7 +95,7 @@ namespace CMS_CORE_Library.Siemens private static bool MULTITOOL_OPTION_ACTIVE; private const string PLC_MESSAGES_FILE_PATH = "C:\\Program Files (x86)\\Siemens\\MotionControl\\oem\\sinumerik\\hmi\\lng\\"; - private const string AXES_FILE_PATH = "Config\\axesConfig.xml"; + private static string AXES_FILE_PATH = System.AppDomain.CurrentDomain.BaseDirectory + "\\Config\\axesConfig.xml"; private SiemensEdgesConfiguration Add_Edges_Param_Config = new SiemensEdgesConfiguration(); @@ -888,7 +888,8 @@ namespace CMS_CORE_Library.Siemens public override CmsError PLC_ROperatorInputIsNeeded(ref List data) { byte val = 0; - CmsError cmsError = MEM_RWByte(R, 0, OPERATOR_INPUT_NEEDED.MemType, OPERATOR_INPUT_NEEDED.Address, 0, ref val); + // Read memory + CmsError cmsError = MEM_RWByte(R, 0, OPERATOR_INPUT_NEEDED.MemType, OPERATOR_INPUT_NEEDED.Address, OPERATOR_INPUT_NEEDED.SubAddress, 0, ref val); if (cmsError.IsError()) return cmsError; // Convert byte to an array of bits @@ -900,27 +901,30 @@ namespace CMS_CORE_Library.Siemens foreach (bool bit in bits) { - // Read active program line - cmsError = ReadActiveLine(processId, ref actualLine); - if (cmsError.IsError()) - return cmsError; - - // Parse&Get parameters - parameters = ExtractParametersFromNcCodeLine(actualLine); - - byte i = 1; - // Skip first parameter because it is the message - // Set button with -> id = 1..5 -> value = parameter value - Dictionary buttons = parameters.Skip(1)?.ToDictionary(x => i++, x => x); - - data.Add(new M155InputIsNeededModel() + if (bit) { - Process = processId, - IsNeeded = bit, - Message = parameters[0], - Type = parameters.Count() > 1 ? M155_TYPE.MULTIPLE_BUTTONS : M155_TYPE.REAL, // if there aren't buttons is a simple request - Buttons = buttons - }); + // Read active program line + cmsError = ReadActiveLine(processId, ref actualLine); + if (cmsError.IsError()) + return cmsError; + + // Parse&Get parameters + parameters = ExtractM155ParametersFromNcCodeLine(actualLine); + + byte i = 1; + // Skip first parameter because it is the message + // Set button with -> id = 1..5 -> value = parameter value + Dictionary buttons = parameters.Skip(1)?.ToDictionary(x => i++, x => x); + + data.Add(new M155InputIsNeededModel() + { + Process = processId, + IsNeeded = bit, + Message = parameters[0], + Type = parameters.Count() > 1 ? M155_TYPE.MULTIPLE_BUTTONS : M155_TYPE.REAL, // if there aren't buttons is a simple request + Buttons = buttons + }); + } // Next path processId++; @@ -950,7 +954,7 @@ namespace CMS_CORE_Library.Siemens return cmsError; // Parse parameters - parameters = ExtractParametersFromNcCodeLine(tmpStr); + parameters = ExtractM154ParametersFromNcCodeLine(tmpStr); data.Add(new MtConnectDataIsNeededModel() { Process = processId, @@ -977,6 +981,8 @@ namespace CMS_CORE_Library.Siemens DataSvc dataSvc = new DataSvc(); dataSvc.Read(item); + + line = item.Value.ToString(); } catch (Exception ex) { @@ -1491,13 +1497,18 @@ namespace CMS_CORE_Library.Siemens // Get from PLC which axis can be selected List ids = new List(); - cmsError = MEM_RWByteList(R, 0, AXES_BUTTON_VISIBLE.MemType, AXES_BUTTON_VISIBLE.Address, AXES_BUTTON_VISIBLE.SubAddress, AXES_BUTTON_VISIBLE.Size, ref ids); + cmsError = MEM_RWByteList(R, 0, AXES_BUTTON_VISIBLE.MemType, AXES_BUTTON_VISIBLE.Address, AXES_BUTTON_VISIBLE.SubAddress, 0, AXES_BUTTON_VISIBLE.Size, ref ids); if (cmsError.IsError()) return cmsError; // Set true if can be selected foreach (byte id in ids) { - axesData[id].IsSelectable = true; + if(id != 0) + { + var tmpAxis = axesData.Where(x => x.Id == id).FirstOrDefault(); + if (tmpAxis != null) + tmpAxis.IsSelectable = true; + } } } catch (Exception ex) diff --git a/CMS_CORE_Library/Utils/Nc_Utils.cs b/CMS_CORE_Library/Utils/Nc_Utils.cs index 8ee247f..f69fbd4 100644 --- a/CMS_CORE_Library/Utils/Nc_Utils.cs +++ b/CMS_CORE_Library/Utils/Nc_Utils.cs @@ -180,7 +180,7 @@ namespace CMS_CORE_Library.Utils public static bool[] ByteToBits(byte val) { - return new BitArray(val) + return new BitArray(new byte[] { val }) .Cast() .ToArray(); } @@ -197,7 +197,7 @@ namespace CMS_CORE_Library.Utils return SIEMENS_MAGAZINE_TYPE.BOX_MAGAZINE; } - public static string[] ExtractParametersFromNcCodeLine(string codeLine) + public static string[] ExtractM154ParametersFromNcCodeLine(string codeLine) { string[] returnVal = new string[1]; int startPos = 0, endPos = 0; @@ -224,5 +224,33 @@ namespace CMS_CORE_Library.Utils return returnVal; } + + public static string[] ExtractM155ParametersFromNcCodeLine(string codeLine) + { + string[] returnVal = new string[1]; + int startPos = 0, endPos = 0; + + // Get first position + startPos = codeLine.IndexOf('['); + if (startPos == -1) + startPos = codeLine.IndexOf(','); + + // Get second position + endPos = codeLine.IndexOf(']', startPos + 1); + if (startPos != -1 && endPos == -1) + endPos = codeLine.Length; + + // if not exists + if (startPos != -1) + { + string tmpString = codeLine; + if (endPos != -1) + tmpString = codeLine.Substring(startPos + 1, endPos - startPos - 1); + + returnVal = tmpString.Split(','); + } + + return returnVal; + } } } \ No newline at end of file