diff --git a/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs b/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs index 4604c56..757ebc9 100644 --- a/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs +++ b/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs @@ -604,7 +604,7 @@ namespace CMS_CORE_Library.Fanuc public override CmsError PLC_WRefreshAllMessages() { - return NO_ERROR; + return PLC_WNcSoftKey(REFRESH_ALL_ALARMS_SFKEY_INDEX); } // Get pre and post power on data diff --git a/CMS_CORE_Library/Osai/Nc_Osai.cs b/CMS_CORE_Library/Osai/Nc_Osai.cs index 6a0bc0f..efb7558 100644 --- a/CMS_CORE_Library/Osai/Nc_Osai.cs +++ b/CMS_CORE_Library/Osai/Nc_Osai.cs @@ -412,7 +412,25 @@ namespace CMS_CORE_Library.Osai // Get NC unit of measure public override CmsError NC_RUnitOfMeasure(ref string unitOfMeasure) { - unitOfMeasure = "mm"; + ushort nReturn = OpenNC.GetNcInfo1(1, out GETINFO1DATA info, out uint errorClass, out uint errorNum); + if (errorClass != 0 || errorNum != 0 || nReturn == 0) + return GetNCError(errorClass, errorNum); + + switch (info.feedmisunit) + { + case 0: + unitOfMeasure = "inch"; + break; + case 1: + unitOfMeasure = "mm"; + break; + case 2: + unitOfMeasure = "inch"; + break; + case 3: + unitOfMeasure = "mm"; + break; + } return NO_ERROR; } @@ -1729,10 +1747,13 @@ namespace CMS_CORE_Library.Osai // 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, 0, AXES_BUTTON_VISIBLE.Size, ref ids); + List ints = new List(); + cmsError = MEM_RWIntegerList(R, 0, AXES_BUTTON_VISIBLE.MemType, AXES_BUTTON_VISIBLE.Address, AXES_BUTTON_VISIBLE.Size / 4, ref ints); if (cmsError.IsError()) return cmsError; + ids = IntsToBytes(ints); + for (int i = 0; i < axesNumber; i++) { var charName = Convert.ToChar(axesName[i]); diff --git a/CMS_CORE_Library/Siemens/Nc_Siemens.cs b/CMS_CORE_Library/Siemens/Nc_Siemens.cs index 6a36c52..06d12a3 100644 --- a/CMS_CORE_Library/Siemens/Nc_Siemens.cs +++ b/CMS_CORE_Library/Siemens/Nc_Siemens.cs @@ -1684,6 +1684,7 @@ 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()) @@ -1703,7 +1704,10 @@ namespace CMS_CORE_Library.Siemens public override CmsError AXES_RMachinePosition(ushort channel, ref Dictionary axes) { try - { // Cycle between axes + { + 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()) { @@ -1722,7 +1726,9 @@ namespace CMS_CORE_Library.Siemens public override CmsError AXES_RProgrPosition(ushort channel, ref Dictionary axes) { 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()) @@ -1743,6 +1749,8 @@ 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()) @@ -1763,13 +1771,15 @@ 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()) { axes.Add(axis.Key, axis.Value); } - axes = ToGoAxesPosition.ToDictionary(x => x.Key, x => x.Value); + // axes = ToGoAxesPosition.ToDictionary(x => x.Key, x => x.Value); } catch (Exception ex) { diff --git a/CMS_CORE_Library/Utils/Nc_Utils.cs b/CMS_CORE_Library/Utils/Nc_Utils.cs index 1af1d60..21807d3 100644 --- a/CMS_CORE_Library/Utils/Nc_Utils.cs +++ b/CMS_CORE_Library/Utils/Nc_Utils.cs @@ -193,6 +193,11 @@ namespace CMS_CORE_Library.Utils return BitConverter.GetBytes(Convert.ToInt32(val)); } + internal static List IntsToBytes(List ints) + { + return ints.SelectMany(BitConverter.GetBytes).ToList(); + } + internal static List ListOfByteToListOf(byte[] array, Func bitConverter) { var size = Marshal.SizeOf(typeof(T));