diff --git a/CMS_CORE_Application/Form1.cs b/CMS_CORE_Application/Form1.cs index 9d1b04d..ad81bff 100644 --- a/CMS_CORE_Application/Form1.cs +++ b/CMS_CORE_Application/Form1.cs @@ -73,6 +73,7 @@ namespace CMS_CORE_Application List Lines = new List(); List keys = new List(); List test = new List(); + List axesNames = new List(); N = SetNcByType(); @@ -107,7 +108,7 @@ namespace CMS_CORE_Application error = true; SetError(Lines, cmsError); } - sw.Restart(); + cmsError = N.PLC_RActiveMessages(ref Msg); if (cmsError.IsError()) { @@ -115,8 +116,6 @@ namespace CMS_CORE_Application SetError(Lines, cmsError); } - sw.Stop(); - cmsError = N.NC_RDateTime(ref NcTime); if (cmsError.IsError()) { @@ -131,14 +130,22 @@ namespace CMS_CORE_Application SetError(Lines, cmsError); } - cmsError = N.PLC_RHeadsData(test, 1); - cmsError = N.PLC_WHeadOverride(19, HEAD_OVERRIDE_SIGN.MINUS); + cmsError = N.PLC_RNcSoftKeys(ref keys); + cmsError = N.PLC_WNcSoftKey(1); + + cmsError = N.AXES_RAxesNames(2, ref axesNames); + cmsError = N.AXES_WSelectAxis(2); + byte axisId = 0; + cmsError = N.AXES_RSelectedAxis(ref axisId); - Dictionary messages = new Dictionary(); - cmsError = N.NC_GetTranslatedPlcMessages("en", ref messages); + //cmsError = N.PLC_RHeadsData(test, 1); + //cmsError = N.PLC_WHeadOverride(19, HEAD_OVERRIDE_SIGN.MINUS); + + //Dictionary messages = new Dictionary(); + //cmsError = N.NC_GetTranslatedPlcMessages("en", ref messages); + + //cmsError = N.PROC_RSelectedProcess(ref procnum); - cmsError = N.PROC_RSelectedProcess(ref procnum); - if (!this.IsDisposed && this.InvokeRequired) { this.Invoke((ThreadStart)delegate () diff --git a/CMS_CORE_Library/DataStructures.cs b/CMS_CORE_Library/DataStructures.cs index fcfa3b9..4c844e8 100644 --- a/CMS_CORE_Library/DataStructures.cs +++ b/CMS_CORE_Library/DataStructures.cs @@ -7,7 +7,7 @@ namespace CMS_CORE_Library { /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - #region Data structor models + #region Data structure models #region Pre and Post Power on Models @@ -293,6 +293,12 @@ namespace CMS_CORE_Library public bool OverrideEditable; } + public class AxisModel + { + public int Id; + public string Name; + } + #endregion Data structor models /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -360,7 +366,8 @@ namespace CMS_CORE_Library #region Constants - public const int SOFTKEYS_NUMBER = 128; + public const int USER_SOFTKEYS_NUMBER = 128; + public const int NC_SOFTKEYS_NUMBER = 32; public const int PROCESS_NUMBER = 6; public const int ALARMS_NUMBER = 1024; public const int HEADS_NUMBER = 20; diff --git a/CMS_CORE_Library/Demo/Nc_Demo.cs b/CMS_CORE_Library/Demo/Nc_Demo.cs index 14c8016..14cc674 100644 --- a/CMS_CORE_Library/Demo/Nc_Demo.cs +++ b/CMS_CORE_Library/Demo/Nc_Demo.cs @@ -301,16 +301,16 @@ namespace CMS_CORE.Demo // try // { // alarms.Clear(); - // List readedValues = new List(); + // List readValues = new List(); // // Read status alarm data data from memory // CmsError cmsError = MEM_RWIntegerList(R, 0, // MEMORY_ADDRESS.ALARMS_STATUS.MemType, // MEMORY_ADDRESS.ALARMS_STATUS.Address, // MEMORY_ADDRESS.ALARMS_STATUS.Size / 4, - // ref readedValues); + // ref readValues); - // bool[] statusBits = new BitArray(readedValues.ToArray()).Cast().ToArray(); + // bool[] statusBits = new BitArray(readValues.ToArray()).Cast().ToArray(); // // Convert array into structured data // byte alarmData = 0; @@ -364,19 +364,19 @@ namespace CMS_CORE.Demo public override CmsError PLC_RActiveMessages(ref List alarms) { alarms.Clear(); - List readedValues = new List(); + List readValues = new List(); // Read on data from memory CmsError cmsError = MEM_RWIntegerList(R, 0, MEMORY_ADDRESS.ALARMS_STATUS.MemType, MEMORY_ADDRESS.ALARMS_STATUS.Address, (MEMORY_ADDRESS.ALARMS_STATUS.Size + MEMORY_ADDRESS.ALARMS_DATA.Size) / 4, - ref readedValues); + ref readValues); if (cmsError.IsError()) return cmsError; // Convert integer array into bit array - bool[] statusBits = new BitArray(readedValues.ToArray()).Cast().ToArray(); + bool[] statusBits = new BitArray(readValues.ToArray()).Cast().ToArray(); for (int i = 0; i < MEMORY_ADDRESS.ALARMS_STATUS.Size * 8; i++) { @@ -415,20 +415,20 @@ namespace CMS_CORE.Demo return INCORRECT_PARAMETERS_ERROR; CmsError cmsError; - bool readedValue = false; + bool readValue = false; bool writeValue = true; - int ackByte = MEMORY_ADDRESS.ALARM_ACK.Address + ((int)id / 8); - int strobeByte = MEMORY_ADDRESS.ALARM_REFRESH_STROBE.Address + ((int)id / 8); - int alarmBitId = ((int)id % 8) - 1; + int ackByte = MEMORY_ADDRESS.ALARM_ACK.Address + (((int)id - 1) / 8); + int strobeByte = MEMORY_ADDRESS.ALARM_REFRESH_STROBE.Address + (((int)id - 1) / 8); + int alarmBitId = (((int)id - 1) % 8); // Check ACK - cmsError = MEM_RWBoolean(R, 0, MEMORY_ADDRESS.ALARM_ACK.MemType, ackByte, alarmBitId, ref readedValue); + cmsError = MEM_RWBoolean(R, 0, MEMORY_ADDRESS.ALARM_ACK.MemType, ackByte, alarmBitId, ref readValue); if (cmsError.IsError()) return cmsError; // If PLC it's performing another request then return - if (readedValue) + if (readValue) return NO_ERROR; // Write data @@ -444,6 +444,16 @@ namespace CMS_CORE.Demo return NO_ERROR; } + public override CmsError PLC_WRestoreMessage(uint id) + { + // Call restore message + CmsError cmsError = PLC_WRefreshMessage(id); + if (cmsError.IsError()) + return cmsError; + + return NO_ERROR; + } + public override CmsError PLC_RPowerOnData(ref PreAndPostPowerOnModel powerOnModel) { int readValue = 0; @@ -504,15 +514,15 @@ namespace CMS_CORE.Demo public override CmsError PLC_RFunctionAccess(ref List functions) { - List readedValues = new List(); + List readValues = new List(); // Read functions access data from memory - CmsError cmsError = MEM_RWIntegerList(R, 0, MEMORY_ADDRESS.FUNCTION_ACCESS.MemType, MEMORY_ADDRESS.FUNCTION_ACCESS.Address, 4, ref readedValues); + CmsError cmsError = MEM_RWIntegerList(R, 0, MEMORY_ADDRESS.FUNCTION_ACCESS.MemType, MEMORY_ADDRESS.FUNCTION_ACCESS.Address, 4, ref readValues); if (cmsError.IsError()) return cmsError; functions = new List(); // Convert int into to true/false array - bool[] bits = new BitArray(readedValues.ToArray()).Cast().ToArray(); + bool[] bits = new BitArray(readValues.ToArray()).Cast().ToArray(); // Convert array into structured data for (int i = 0; i < bits.Count(); i++) { @@ -552,44 +562,64 @@ namespace CMS_CORE.Demo public override CmsError PLC_RMachineCounters(ref List counters) { counters = new List(); - List readedValues = new List(); + List readValues = new List(); // Read on data from memory - CmsError cmsError = MEM_RWIntegerList(R, 0, MEMORY_ADDRESS.COUNTERS.MemType, MEMORY_ADDRESS.COUNTERS.Address, MEMORY_ADDRESS.COUNTERS.Size / 4, ref readedValues); + CmsError cmsError = MEM_RWIntegerList(R, 0, MEMORY_ADDRESS.COUNTERS.MemType, MEMORY_ADDRESS.COUNTERS.Address, MEMORY_ADDRESS.COUNTERS.Size / 4, ref readValues); if (cmsError.IsError()) return cmsError; // Foreach counters - for (int i = 0; i < readedValues.Count; i++) + for (int i = 0; i < readValues.Count; i++) { // Add counters value into returned value counters.Add(new CounterModel() { Id = (uint)i, - Value = (uint)readedValues[i] + Value = (uint)readValues[i] }); } return NO_ERROR; } + + public override CmsError PLC_RNcSoftKeys(ref List ncSoftKeys) + { + CmsError cmsError = PLC_RSoftKeys(MEMORY_ADDRESS.NC_SOFTKEYS_VALUE, MEMORY_ADDRESS.NC_SOFTKEYS_CLICKABLE, ref ncSoftKeys); + if (cmsError.IsError()) + return cmsError; - public override CmsError PLC_RSoftKeys(ref List softKeys) + return NO_ERROR; + } + + public override CmsError PLC_RUserSoftKeys(ref List softKeys) + { + CmsError cmsError = PLC_RSoftKeys(MEMORY_ADDRESS.USER_SOFTKEYS_VALUE, MEMORY_ADDRESS.USER_SOFTKEYS_CLICKABLE, ref softKeys); + if (cmsError.IsError()) + return cmsError; + + return NO_ERROR; + } + + private CmsError PLC_RSoftKeys(MEMORY_CELL softKeyStatusMemory, MEMORY_CELL softKeysClickableMemory, ref List softKeys) { softKeys = new List(); - List readedValues = new List(); + List readValue = new List(); - int memorySize = (MEMORY_ADDRESS.USER_SOFTKEYS_VALUE.Size + MEMORY_ADDRESS.USER_SOFTKEYS_CLICKABLE.Size); + int memorySizeToRead = (softKeyStatusMemory.Size + softKeysClickableMemory.Size); + // Offset between status and clicable data + int offset = softKeyStatusMemory.Size * 8; // Read on data from memory CmsError cmsError = MEM_RWIntegerList(R, 0, - MEMORY_ADDRESS.USER_SOFTKEYS_VALUE.MemType, - MEMORY_ADDRESS.USER_SOFTKEYS_VALUE.Address, - memorySize / 4, - ref readedValues); + softKeyStatusMemory.MemType, + softKeyStatusMemory.Address, + memorySizeToRead / 4, + ref readValue); if (cmsError.IsError()) return cmsError; - bool[] bits = new BitArray(readedValues.ToArray()).Cast().ToArray(); + bool[] bits = new BitArray(readValue.ToArray()).Cast().ToArray(); // Convert array into structured data for (ushort i = 0; i < bits.Count() / 2; i++) @@ -598,34 +628,70 @@ namespace CMS_CORE.Demo { Id = i, Value = bits[i], - Active = bits[i + 128] + Active = bits[i + offset] }); } return NO_ERROR; } - public override CmsError PLC_WSoftKey(uint id) + public override CmsError PLC_WNcSoftKey(uint id) { // Check id range - if (id > SOFTKEYS_NUMBER) + if (id > NC_SOFTKEYS_NUMBER) return INCORRECT_PARAMETERS_ERROR; CmsError cmsError; - bool readedValue = false; + bool readValue = false; bool writeValue = true; - int ackByte = MEMORY_ADDRESS.USER_SOFT_KEYS_ACK.Address + ((int)id / 8); - int strobeByte = MEMORY_ADDRESS.USER_SOFT_KEYS_CLICKED.Address + ((int)id / 8); - int softkeyBitId = ((int)id % 8) - 1; + int ackByte = MEMORY_ADDRESS.NC_SOFT_KEYS_ACK.Address + (((int)id - 1) / 8); + int strobeByte = MEMORY_ADDRESS.NC_SOFT_KEYS_CLICKED.Address + (((int)id - 1) / 8); + int softkeyBitId = (((int)id - 1) % 8); // Check ACK - cmsError = MEM_RWBoolean(R, 0, MEMORY_ADDRESS.USER_SOFT_KEYS_ACK.MemType, ackByte, softkeyBitId, ref readedValue); + cmsError = MEM_RWBoolean(R, 0, MEMORY_ADDRESS.NC_SOFT_KEYS_ACK.MemType, ackByte, softkeyBitId, ref readValue); if (cmsError.IsError()) return cmsError; // If PLC it's performing another request then return - if (readedValue) + if (readValue) + return NO_ERROR; + + // Write data + cmsError = MEM_RWBoolean(W, 0, MEMORY_ADDRESS.NC_SOFT_KEYS_CLICKED.MemType, strobeByte, softkeyBitId, ref writeValue); + if (cmsError.IsError()) + return cmsError; + + // Reset wait ack = 1 and reset the strobe + cmsError = ResetStrobe(softkeyBitId, strobeByte, ackByte, MEMORY_ADDRESS.NC_SOFT_KEYS_CLICKED.MemType); + if (cmsError.IsError()) + return cmsError; + + return NO_ERROR; + } + + public override CmsError PLC_WUserSoftKey(uint id) + { + // Check id range + if (id > USER_SOFTKEYS_NUMBER) + return INCORRECT_PARAMETERS_ERROR; + + CmsError cmsError; + bool readValue = false; + bool writeValue = true; + + int ackByte = MEMORY_ADDRESS.USER_SOFT_KEYS_ACK.Address + (((int)id - 1) / 8); + int strobeByte = MEMORY_ADDRESS.USER_SOFT_KEYS_CLICKED.Address + (((int)id - 1) / 8); + int softkeyBitId = (((int)id - 1) % 8); + + // Check ACK + cmsError = MEM_RWBoolean(R, 0, MEMORY_ADDRESS.USER_SOFT_KEYS_ACK.MemType, ackByte, softkeyBitId, ref readValue); + if (cmsError.IsError()) + return cmsError; + + // If PLC it's performing another request then return + if (readValue) return NO_ERROR; // Write data @@ -648,12 +714,12 @@ namespace CMS_CORE.Demo return INCORRECT_PARAMETERS_ERROR; heads.Clear(); - List readedValues = new List(); + List readValues = new List(); // Find the size of a single head int headsByte = (MEMORY_ADDRESS.HEADS_DATA.Size / HEADS_NUMBER); // Read data for N heads - CmsError cmsError = MEM_RWByteList(R, 0, MEMORY_ADDRESS.HEADS_DATA.MemType, MEMORY_ADDRESS.HEADS_DATA.Address, 0, headsByte * number, ref readedValues); + CmsError cmsError = MEM_RWByteList(R, 0, MEMORY_ADDRESS.HEADS_DATA.MemType, MEMORY_ADDRESS.HEADS_DATA.Address, 0, headsByte * number, ref readValues); if (cmsError.IsError()) return cmsError; @@ -665,14 +731,14 @@ namespace CMS_CORE.Demo heads.Add(new HeadDataModel() { Id = (uint)i, - Process = readedValues[headOffset], - Override = readedValues[headOffset + 1], - Load_Abrasive = BitConverter.ToUInt16(readedValues.ToArray(), headOffset + 2), // Uint 16 = 2byte - ActualSpeed_Pressure = BitConverter.ToInt32(readedValues.ToArray(), headOffset + 4), // Int32 = 4byte - MountedTool_Vacum = BitConverter.ToUInt16(readedValues.ToArray(), headOffset + 8), // Uint 16 = 2byte - isActive = (readedValues[headOffset + 10] & 1) != 0, // bit 0 - isSelected = (readedValues[headOffset + 10] & 2) != 0, // bit 1 - OverrideEditable = (readedValues[headOffset + 10] & 4) != 0 // bit 2 + Process = readValues[headOffset], + Override = readValues[headOffset + 1], + Load_Abrasive = BitConverter.ToUInt16(readValues.ToArray(), headOffset + 2), // Uint 16 = 2byte + ActualSpeed_Pressure = BitConverter.ToInt32(readValues.ToArray(), headOffset + 4), // Int32 = 4byte + MountedTool_Vacum = BitConverter.ToUInt16(readValues.ToArray(), headOffset + 8), // Uint 16 = 2byte + isActive = (readValues[headOffset + 10] & 1) != 0, // bit 0 + isSelected = (readValues[headOffset + 10] & 2) != 0, // bit 1 + OverrideEditable = (readValues[headOffset + 10] & 4) != 0 // bit 2 }); } @@ -685,22 +751,22 @@ namespace CMS_CORE.Demo return INCORRECT_PARAMETERS_ERROR; CmsError cmsError; - bool readedValue = false; + bool readValue = false; bool writeValue = true; MEMORY_CELL currentMemoryCell = sign == HEAD_OVERRIDE_SIGN.PLUS ? MEMORY_ADDRESS.HEADS_STROBE_INCREMENT : MEMORY_ADDRESS.HEADS_STROBE_DECREMENT; - int ackByte = MEMORY_ADDRESS.HEADS_ACK.Address + ((int)id / 8); - int strobeByte = currentMemoryCell.Address + ((int)id / 8); - int headBit = ((int)id % 8) - 1; + int ackByte = MEMORY_ADDRESS.HEADS_ACK.Address + (((int)id - 1) / 8); + int strobeByte = currentMemoryCell.Address + (((int)id - 1) / 8); + int headBit = (((int)id - 1) % 8); // Check ACK - cmsError = MEM_RWBoolean(R, 0, MEMORY_ADDRESS.HEADS_ACK.MemType, ackByte, headBit, ref readedValue); + cmsError = MEM_RWBoolean(R, 0, MEMORY_ADDRESS.HEADS_ACK.MemType, ackByte, headBit, ref readValue); if (cmsError.IsError()) return cmsError; // If PLC it's performing another request then return - if (readedValue) + if (readValue) return NO_ERROR; // Write strobe data @@ -719,18 +785,18 @@ namespace CMS_CORE.Demo private CmsError ResetStrobe(int bitId, int strobeByte, int ackByte, MEMORY_TYPE memType) { int n = 5; - bool readedValue = false; + bool readValue = false; bool writeValue = false; CmsError cmsError; do { // Check ACK - cmsError = MEM_RWBoolean(R, 0, memType, ackByte, bitId, ref readedValue); + cmsError = MEM_RWBoolean(R, 0, memType, ackByte, bitId, ref readValue); if (cmsError.IsError()) return cmsError; // If true reset strobe - if (readedValue == true) + if (readValue == true) { // Reset strobe cmsError = MEM_RWBoolean(W, 0, memType, strobeByte, bitId, ref writeValue); @@ -887,7 +953,7 @@ namespace CMS_CORE.Demo return cmsError; // Return value - procNumber = processNum; + procNumber = processNum == 0 ? (ushort)1 : processNum; return NO_ERROR; } @@ -952,7 +1018,7 @@ namespace CMS_CORE.Demo { // Get Axes Position from server serverService.GetAxesPosition(ProcNumber.ToString(), out List demoAxes); - // Parse server response and get programmed position + // Parse server response and retrieve programmed position foreach (NcAxisModel demoAxis in demoAxes) { Axes.Add(demoAxis.name, demoAxis.programmed); @@ -966,7 +1032,7 @@ namespace CMS_CORE.Demo return NO_ERROR; } - public override CmsError AXES_RMachinePosition(ushort ProcNumber, ref Dictionary Axes) + public override CmsError AXES_RMachinePosition(ushort procNumber, ref Dictionary Axes) { // Check if the NC Demo is Connected CmsError cmsError = CheckConnection(); @@ -975,9 +1041,9 @@ namespace CMS_CORE.Demo try { // Get Axes Position from server - serverService.GetAxesPosition(ProcNumber.ToString(), out List demoAxes); + serverService.GetAxesPosition(procNumber.ToString(), out List demoAxes); - // Parse Server response and get machine position + // Parse Server response and retrieve machine position foreach (NcAxisModel demoAxis in demoAxes) { Axes.Add(demoAxis.name, demoAxis.machinePosition); @@ -991,7 +1057,7 @@ namespace CMS_CORE.Demo return NO_ERROR; } - public override CmsError AXES_RFollowingError(ushort ProcNumber, ref Dictionary Axes) + public override CmsError AXES_RFollowingError(ushort procNumber, ref Dictionary Axes) { // Check if the NC Demo is Connected CmsError cmsError = CheckConnection(); @@ -1001,8 +1067,8 @@ namespace CMS_CORE.Demo try { // Get Axes position from Demo server - serverService.GetAxesPosition(ProcNumber.ToString(), out List demoAxes); - // Parse response get distance to go + serverService.GetAxesPosition(procNumber.ToString(), out List demoAxes); + // Parse response retrieve following error foreach (NcAxisModel demoAxis in demoAxes) { Axes.Add(demoAxis.name, demoAxis.distanceToGo); @@ -1016,7 +1082,7 @@ namespace CMS_CORE.Demo return NO_ERROR; } - public override CmsError AXES_RDistanceToGo(ushort ProcNumber, ref Dictionary Axes) + public override CmsError AXES_RDistanceToGo(ushort procNumber, ref Dictionary Axes) { // Check if the NC Demo is Connected CmsError cmsError = CheckConnection(); @@ -1025,8 +1091,8 @@ namespace CMS_CORE.Demo try { - serverService.GetAxesPosition(ProcNumber.ToString(), out List demoAxes); - // Parse response get distance to go + serverService.GetAxesPosition(procNumber.ToString(), out List demoAxes); + // Parse response and retrieve distance to go foreach (NcAxisModel demoAxis in demoAxes) { Axes.Add(demoAxis.name, demoAxis.distanceToGo); @@ -1040,6 +1106,55 @@ namespace CMS_CORE.Demo return NO_ERROR; } + public override CmsError AXES_RAxesNames(ushort process, ref List axesData) + { + // Check if the NC Demo is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.IsError()) + return cmsError; + + try + { + serverService.GetAxesPosition(process.ToString(), out List demoAxes); + int i = 1; + // Parse response get distance to go + foreach (NcAxisModel demoAxis in demoAxes) + { + axesData.Add(new AxisModel() + { + Id = i++, + Name = demoAxis.name + }); + } + } + catch (Exception ex) + { + return ManageException(ex); + } + + return NO_ERROR; + } + + public override CmsError AXES_RSelectedAxis(ref byte axisId) + { + // Read byte from memory + CmsError cmsError = MEM_RWByte(R, 0, MEMORY_ADDRESS.SELECTED_AXIS.MemType, MEMORY_ADDRESS.SELECTED_AXIS.Address, 1, ref axisId); + if (cmsError.IsError()) + return cmsError; + + return NO_ERROR; + } + + public override CmsError AXES_WSelectAxis(byte axisId) + { + // Write byte from memory + CmsError cmsError = MEM_RWByte(W, 0, MEMORY_ADDRESS.SELECT_AXIS.MemType, MEMORY_ADDRESS.SELECT_AXIS.Address, 1, ref axisId); + if (cmsError.IsError()) + return cmsError; + + return NO_ERROR; + } + #endregion PROCESS-AXES (PATH) High-level data /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1662,6 +1777,14 @@ namespace CMS_CORE.Demo internal static MEMORY_CELL COUNTERS = new MEMORY_CELL(MEMORY_TYPE.Demo, 43, 0, 40); + internal static MEMORY_CELL SELECTED_AXIS = new MEMORY_CELL(MEMORY_TYPE.Demo, 83, 0, 1); + internal static MEMORY_CELL SELECT_AXIS = new MEMORY_CELL(MEMORY_TYPE.Demo, 84, 0, 1); + + internal static MEMORY_CELL NC_SOFTKEYS_VALUE = new MEMORY_CELL(MEMORY_TYPE.Demo, 85, 0, 4); + internal static MEMORY_CELL NC_SOFTKEYS_CLICKABLE = new MEMORY_CELL(MEMORY_TYPE.Demo, 89, 0, 4); + internal static MEMORY_CELL NC_SOFT_KEYS_CLICKED = new MEMORY_CELL(MEMORY_TYPE.Demo, 93, 4); + internal static MEMORY_CELL NC_SOFT_KEYS_ACK = new MEMORY_CELL(MEMORY_TYPE.Demo, 97, 4); + internal static MEMORY_CELL USER_SOFTKEYS_VALUE = new MEMORY_CELL(MEMORY_TYPE.Demo, 101, 0, 16); internal static MEMORY_CELL USER_SOFTKEYS_CLICKABLE = new MEMORY_CELL(MEMORY_TYPE.Demo, 117, 0, 16); internal static MEMORY_CELL USER_SOFT_KEYS_CLICKED = new MEMORY_CELL(MEMORY_TYPE.Demo, 133, 16); @@ -1673,7 +1796,6 @@ namespace CMS_CORE.Demo internal static MEMORY_CELL ALARM_ACK = new MEMORY_CELL(MEMORY_TYPE.Demo, 201, 4); internal static MEMORY_CELL ALARM_REFRESH_STROBE = new MEMORY_CELL(MEMORY_TYPE.Demo, 205, 4); - internal static MEMORY_CELL HEADS_DATA = new MEMORY_CELL(MEMORY_TYPE.Demo, 209, 240); internal static MEMORY_CELL HEADS_ACK = new MEMORY_CELL(MEMORY_TYPE.Demo, 449, 4); diff --git a/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs b/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs index 9728bb2..b74873b 100644 --- a/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs +++ b/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs @@ -371,6 +371,11 @@ namespace CMS_CORE.Fanuc return NO_ERROR; } + public override CmsError PLC_WRestoreMessage(uint id) + { + return NO_ERROR; + } + // Get pre and post power on data public override CmsError PLC_RPowerOnData(ref PreAndPostPowerOnModel powerOnModel) { @@ -402,12 +407,22 @@ namespace CMS_CORE.Fanuc return NO_ERROR; } - public override CmsError PLC_RSoftKeys(ref List softKeys) + public override CmsError PLC_RNcSoftKeys(ref List ncSoftKeys) { return NO_ERROR; } - public override CmsError PLC_WSoftKey(uint id) + public override CmsError PLC_RUserSoftKeys(ref List softKeys) + { + return NO_ERROR; + } + + public override CmsError PLC_WNcSoftKey(uint id) + { + return NO_ERROR; + } + + public override CmsError PLC_WUserSoftKey(uint id) { return NO_ERROR; } @@ -893,6 +908,21 @@ namespace CMS_CORE.Fanuc return FUNCTION_NOT_ALLOWED_ERROR; } + public override CmsError AXES_RAxesNames(ushort process, ref List axesData) + { + return NO_ERROR; + } + + public override CmsError AXES_RSelectedAxis(ref byte axisId) + { + return NO_ERROR; + } + + public override CmsError AXES_WSelectAxis(byte axisId) + { + return NO_ERROR; + } + #endregion PROCESS-AXES (PATH) High-level data /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/CMS_CORE_Library/Nc.cs b/CMS_CORE_Library/Nc.cs index 4a19abd..6e7f0d8 100644 --- a/CMS_CORE_Library/Nc.cs +++ b/CMS_CORE_Library/Nc.cs @@ -1,5 +1,4 @@ -using CMS_CORE_Library; -using System; +using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; @@ -7,13 +6,13 @@ using System.IO; using System.Reflection; using static CMS_CORE_Library.DataStructures; - namespace CMS_CORE { public abstract partial class Nc { //Private Global Variables internal Boolean Connected; + internal String Ip; internal ushort Port; internal Boolean UseProxy; @@ -21,21 +20,26 @@ namespace CMS_CORE //Osai Variable internal string OSAI_PlcMessagesPath = @"C:\CMS\OSAI\"; + internal string OSAI_WinNbiPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + @"\OSAI\WinNBI\"; /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region LIB Methods /** * * Get the NC IP-Address * - * Compatibility: Fanuc | Osai | Demo + * Compatibility: Fanuc | Osai | Demo * * * */ - public String LIB_GetIpAddress() { return Ip; } + public String LIB_GetIpAddress() + { + return Ip; + } /** * @@ -45,8 +49,11 @@ namespace CMS_CORE * * * */ - public void LIB_SetIpAddress(String ip) { Ip = ip; } + public void LIB_SetIpAddress(String ip) + { + Ip = ip; + } /** * @@ -56,8 +63,11 @@ namespace CMS_CORE * * * */ - public ushort LIB_GetPort() { return Port; } + public ushort LIB_GetPort() + { + return Port; + } /** * @@ -67,8 +77,11 @@ namespace CMS_CORE * * * */ - public void LIB_SetPort(ushort port) { Port = port; } + public void LIB_SetPort(ushort port) + { + Port = port; + } /** * @@ -78,9 +91,13 @@ namespace CMS_CORE * * * */ - public String LIB_GetLibraryVersion() { return FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion.ToString(); } - #endregion + public String LIB_GetLibraryVersion() + { + return FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion.ToString(); + } + + #endregion LIB Methods #region LIB Methods (OSAI) @@ -92,8 +109,11 @@ namespace CMS_CORE * * * */ - public Boolean LIB_GetWindowsProxy() { return UseProxy; } + public Boolean LIB_GetWindowsProxy() + { + return UseProxy; + } /** * @@ -103,8 +123,11 @@ namespace CMS_CORE * * * */ - public void LIB_SetWindowsProxy(Boolean proxy) { UseProxy = proxy; } + public void LIB_SetWindowsProxy(Boolean proxy) + { + UseProxy = proxy; + } /** * @@ -114,8 +137,11 @@ namespace CMS_CORE * * * */ - public string LIB_GetPlcMsgsPath() { return OSAI_PlcMessagesPath; } + public string LIB_GetPlcMsgsPath() + { + return OSAI_PlcMessagesPath; + } /** * @@ -125,8 +151,11 @@ namespace CMS_CORE * * * */ - public void LIB_SetPlcMsgsPath(string folder) { OSAI_PlcMessagesPath = folder; } + public void LIB_SetPlcMsgsPath(string folder) + { + OSAI_PlcMessagesPath = folder; + } /** * @@ -136,8 +165,11 @@ namespace CMS_CORE * * * */ - public string LIB_GetWinNbiPath() { return OSAI_WinNbiPath; } + public string LIB_GetWinNbiPath() + { + return OSAI_WinNbiPath; + } /** * @@ -147,12 +179,16 @@ namespace CMS_CORE * * * */ - public void LIB_SetWinNbiPath(string folder) { OSAI_WinNbiPath = folder; } + public void LIB_SetWinNbiPath(string folder) + { + OSAI_WinNbiPath = folder; + } - #endregion + #endregion LIB Methods (OSAI) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region NC High-level data (to override) /** @@ -164,8 +200,8 @@ namespace CMS_CORE * Returns an error when an internal or a library error occours * * */ - public abstract CmsError NC_Connect(); + public abstract CmsError NC_Connect(); /** * @@ -176,8 +212,8 @@ namespace CMS_CORE * Returns an error when an internal or a library error occours * * */ - public abstract CmsError NC_Disconnect(); + public abstract CmsError NC_Disconnect(); /** * @@ -188,8 +224,11 @@ namespace CMS_CORE * * Returns an error when an internal or a library error occours * */ - public Boolean NC_IsConnected() { return Connected; } + public Boolean NC_IsConnected() + { + return Connected; + } /** * @@ -201,8 +240,8 @@ namespace CMS_CORE * Returns an error when an internal or a library error occours * Reference of a DateTime Variable where data will be saved * */ - public abstract CmsError NC_RDateTime(ref DateTime ActualTime); + public abstract CmsError NC_RDateTime(ref DateTime ActualTime); /** * @@ -214,6 +253,7 @@ namespace CMS_CORE * Returns an error when an internal or a library error occours * Reference of a String Variable where data will be saved * */ + public abstract CmsError NC_RSerialNumber(ref String SN); /** @@ -226,6 +266,7 @@ namespace CMS_CORE * Returns an error when an internal or a library error occours * Reference of a String Variable where data will be saved * */ + public abstract CmsError NC_RModelName(ref String ModelName); /** @@ -238,6 +279,7 @@ namespace CMS_CORE * Returns an error when an internal or a library error occours * Reference of a String Variable where data will be saved * */ + public abstract CmsError NC_RSoftwareVersion(ref String SWV); /** @@ -250,6 +292,7 @@ namespace CMS_CORE * Returns an error when an internal or a library error occours * Reference of a String Variable where data will be saved * */ + public abstract CmsError NC_RMachineNumber(ref String MachNumber); /** @@ -262,6 +305,7 @@ namespace CMS_CORE * Returns an error when an internal or a library error occours * Reference of a ushort Variable where data will be saved * */ + public abstract CmsError NC_RProcessesNum(ref ushort ProcNumber); /** @@ -274,12 +318,12 @@ namespace CMS_CORE * Returns an error when an internal or a library error occours * Reference of a CultureInfo Variable where data will be saved * */ - public abstract CmsError NC_RLanguage(ref CultureInfo Language); + public abstract CmsError NC_RLanguage(ref CultureInfo Language); /** * - * Read active alarms of the NC (Nc-Process indipendent). For OSAI Nc the list can contain only one Message + * Read active alarms of the NC (Nc-Process indipendent). For OSAI Nc the list can contain only one Message * * Compatibility: Fanuc | Osai | Demo | Siemens * @@ -288,6 +332,7 @@ namespace CMS_CORE * Process to execute the action * Reference of a List of String Variables where data will be saved * */ + public abstract CmsError NC_RActiveAlarms(ref List alarms); /** @@ -300,13 +345,15 @@ namespace CMS_CORE * Returns an error when an internal or a library error occours * Reference to boolean where running state will be saved * */ + public abstract CmsError NC_RIsRunning(ref bool running); public abstract CmsError NC_GetTranslatedPlcMessages(string language, ref Dictionary messages); - - #endregion + + #endregion NC High-level data (to override) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region NC Low-level data (to override) /** @@ -320,6 +367,7 @@ namespace CMS_CORE * Set the Bit to Read. (0..7) * Reference of a variable with Param values * */ + public abstract CmsError NC_RParam(short Index, short Bit, ref Boolean Value); /** @@ -332,6 +380,7 @@ namespace CMS_CORE * Index of the parameter * Reference of a variable with Param values * */ + public abstract CmsError NC_RParam(short Index, ref byte Value); /** @@ -344,6 +393,7 @@ namespace CMS_CORE * Index of the parameter * Reference of a variable with Param values * */ + public abstract CmsError NC_RParam(short Index, ref short Value); /** @@ -356,6 +406,7 @@ namespace CMS_CORE * Index of the parameter * Reference of a variable with Param values * */ + public abstract CmsError NC_RParam(short Index, ref int Value); /** @@ -368,10 +419,13 @@ namespace CMS_CORE * Index of the parameter * Reference of a variable with Param values * */ + public abstract CmsError NC_RParam(short Index, ref double Value); - #endregion + + #endregion NC Low-level data (to override) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region PLC High-level data (to override) /** @@ -384,20 +438,36 @@ namespace CMS_CORE * Returns an error when an internal or a library error occours * Reference of a List of String Variables where data will be saved * */ + public abstract CmsError PLC_RActiveMessages(ref List Alarms); /** * - * Start refresh message + * Start refresh message procedure * * Compatibility: Fanuc | Osai | Demo | Siemens * * * Returns an error when an internal or a library error occours - * Alarm id to refresh + * Alarm id to refresh * * */ + public abstract CmsError PLC_WRefreshMessage(uint id); + /** + * + * Start restore message procedure + * + * Compatibility: Fanuc | Osai | Demo | Siemens + * + * + * Returns an error when an internal or a library error occours + * Alarm id to restore + * + * */ + + public abstract CmsError PLC_WRestoreMessage(uint id); + /** * * Read the status of the Power on data ( Pre-Power-On / Post-Power-On ) @@ -408,6 +478,7 @@ namespace CMS_CORE * * Reference to the structure where the power on data will be saved **/ + public abstract CmsError PLC_RPowerOnData(ref PreAndPostPowerOnModel powerOnModel); /** @@ -421,17 +492,19 @@ namespace CMS_CORE * Id of the edited power on data * Reference to the value of the power on data **/ + public abstract CmsError PLC_WPowerOnData(uint id, bool value); /** * - * Read the status of the UI functions from PLC + * Read the status of the UI functionality from PLC * * Compatibility: Fanuc | Osai | Demo | Siemens * * Returns an error when an internal or a library error occours * **/ + public abstract CmsError PLC_RFunctionAccess(ref List functions); /** @@ -444,6 +517,7 @@ namespace CMS_CORE * Reference to the axes reset procedure data * **/ + public abstract CmsError PLC_RAxesResetData(ref AxisResetDataModel axisResetData); /** @@ -456,8 +530,22 @@ namespace CMS_CORE * Reference to the counters data * **/ + public abstract CmsError PLC_RMachineCounters(ref List counters); + /** + * + * Read nc softkeys values from PLC + * + * Compatibility: Fanuc | Osai | Demo | Siemens + * + * Returns an error when an internal or a library error occours + * Reference to the nc softkey data + * + **/ + + public abstract CmsError PLC_RNcSoftKeys(ref List ncSoftKeys); + /** * * Read user softkeys values from PLC @@ -468,11 +556,25 @@ namespace CMS_CORE * Reference to the softkey data * **/ - public abstract CmsError PLC_RSoftKeys(ref List softKeys); + + public abstract CmsError PLC_RUserSoftKeys(ref List softKeys); /** * - * Write user softkey click into PLC + * Write Nc softkey interaction into PLC + * + * Compatibility: Fanuc | Osai | Demo | Siemens + * + * Returns an when an internal or a library error occours + * Nc softkey id + * + **/ + + public abstract CmsError PLC_WNcSoftKey(uint id); + + /** + * + * Write user softkey interaction into PLC * * Compatibility: Fanuc | Osai | Demo | Siemens * @@ -480,19 +582,46 @@ namespace CMS_CORE * User softkey id * **/ - public abstract CmsError PLC_WSoftKey(uint id); + + public abstract CmsError PLC_WUserSoftKey(uint id); + + /** + * + * Read heads data from PLC + * + * Compatibility: Fanuc | Osai | Demo | Siemens + * + * Returns an error when an internal or a library error occours + * Recerence to the heads data + * Number of heads data that are read + * + **/ public abstract CmsError PLC_RHeadsData(List heads, int number); + /** + * + * Write head override sign into PLC + * + * Compatibility: Fanuc | Osai | Demo | Siemens + * + * Returns an error when an internal or a library error occours + * Head id + * Type of increment of the override + * + **/ + public abstract CmsError PLC_WHeadOverride(uint id, HEAD_OVERRIDE_SIGN sign); - #endregion + + #endregion PLC High-level data (to override) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region PROCESS (PATH, CHANNEL) data (to override) /** * - * Read the actual status of the Process "ProcNumber" + * Read the actual status of the Process "ProcNumber" * See for information about the PROC_Status type * * Compatibility: Fanuc | Osai | Demo | Siemens @@ -502,11 +631,12 @@ namespace CMS_CORE * Process number which the data refer * Reference of a PROC_Status Variable where data will be saved * */ + public abstract CmsError PROC_RStatus(ushort ProcNumber, ref PROC_STATUS Status); /** * - * Read the selected Mode Process "ProcNumber" + * Read the selected Mode Process "ProcNumber" * See for information about the PROC_Status type * * Compatibility: Fanuc | Osai | Demo | Siemens @@ -516,12 +646,12 @@ namespace CMS_CORE * Process number which the data refer * Reference of a PROC_Mode Variable where data will be saved * */ - public abstract CmsError PROC_RMode(ushort ProcNumber, ref PROC_MODE Mode); + public abstract CmsError PROC_RMode(ushort ProcNumber, ref PROC_MODE Mode); /** * - * Read active alarms of the process "ProcNumber". For OSAI Nc the list can contain only one Message + * Read active alarms of the process "ProcNumber". For OSAI Nc the list can contain only one Message * * Compatibility: Fanuc | Osai | Demo | Siemens * @@ -530,8 +660,8 @@ namespace CMS_CORE * Process number which the data refer * Reference of a List of String Variables where data will be saved * */ - public abstract CmsError PROC_RActiveAlarms(ushort procNumber, ref List alarms); + public abstract CmsError PROC_RActiveAlarms(ushort procNumber, ref List alarms); /** * @@ -544,8 +674,8 @@ namespace CMS_CORE * Process number which the data refer * Reference of a List of String Variables where data will be saved * */ - public abstract CmsError PROC_RPPLines(ushort procNumber, ref List Lines); + public abstract CmsError PROC_RPPLines(ushort procNumber, ref List Lines); /** * @@ -558,6 +688,7 @@ namespace CMS_CORE * Process number which the data refer * Reference of a String Variables where data will be saved * */ + public abstract CmsError PROC_RPPName(ushort procNumber, ref String Name); /** @@ -568,10 +699,10 @@ namespace CMS_CORE * * Process number which the data refer * Reference to part program data structure - * + * **/ - public abstract CmsError PROC_RStatusAndData(ushort procNumber, ref ProcessDataModel processData); + public abstract CmsError PROC_RStatusAndData(ushort procNumber, ref ProcessDataModel processData); /** * @@ -580,8 +711,9 @@ namespace CMS_CORE * Compatibility: Fanuc | Osai | Siemens * * Reference to the process number selected - * + * **/ + public abstract CmsError PROC_RSelectedProcess(ref ushort procNumber); /** @@ -591,12 +723,15 @@ namespace CMS_CORE * Compatibility: Fanuc | Osai | Siemens * * New selected process number - * + * **/ + public abstract CmsError PROC_WSelectProcess(ushort procNumber); - #endregion + + #endregion PROCESS (PATH, CHANNEL) data (to override) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region AXES data (to override) /** @@ -610,12 +745,13 @@ namespace CMS_CORE * Process to execute the action * Reference of Dictionary "Key,Value" with: Key: Axis Name, Value: Position * */ + public abstract CmsError AXES_RInterpPosition(ushort ProcNumber, ref Dictionary Axes); /** * - * Read the Programmed position of all axes in Process "ProcNumber". - * For Fanuc-Nc there's not "Programmed position" variables. Si it is calculated from Machine-Pos and Distance-to-go + * Read the Programmed position of all axes in Process "ProcNumber". + * For Fanuc-Nc there's not "Programmed position" variables. Si it is calculated from Machine-Pos and Distance-to-go * * Compatibility: Fanuc | Osai | Demo * @@ -624,6 +760,7 @@ namespace CMS_CORE * Process to execute the action * Reference of Dictionary "Key,Value" with: Key: Axis Name, Value: Position * */ + public abstract CmsError AXES_RProgrPosition(ushort ProcNumber, ref Dictionary Axes); /** @@ -637,6 +774,7 @@ namespace CMS_CORE * Process to execute the action * Reference of Dictionary "Key,Value" with: Key: Axis Name, Value: Position * */ + public abstract CmsError AXES_RMachinePosition(ushort ProcNumber, ref Dictionary Axes); /** @@ -650,6 +788,7 @@ namespace CMS_CORE * Process to execute the action * Reference of Dictionary "Key,Value" with: Key: Axis Name, Value: Position * */ + public abstract CmsError AXES_RFollowingError(ushort ProcNumber, ref Dictionary Axes); /** @@ -663,12 +802,19 @@ namespace CMS_CORE * Process to execute the action * Reference of Dictionary "Key,Value" with: Key: Axis Name, Value: Position * */ + public abstract CmsError AXES_RDistanceToGo(ushort ProcNumber, ref Dictionary Axes); + public abstract CmsError AXES_RAxesNames(ushort process, ref List axesData); - #endregion + public abstract CmsError AXES_RSelectedAxis(ref byte axisId); + + public abstract CmsError AXES_WSelectAxis(byte axisId); + + #endregion AXES data (to override) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region MEMORY Low-level function: single valiable in memory (to override) /** @@ -685,6 +831,7 @@ namespace CMS_CORE * Set the Bit to Read-Write. (0..7) * Reference to variable to read/Write * */ + public abstract CmsError MEM_RWBoolean(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int MemBit, ref Boolean Value); /** @@ -702,10 +849,9 @@ namespace CMS_CORE * Set the Bit to Read-Write. (0..7) * Reference to variable to read/Write * */ + public abstract CmsError MEM_RWBoolean(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int MemBit, ref Boolean Value); - - /** * Read/Write Byte variable from/into NC Memory Area * @@ -720,6 +866,7 @@ namespace CMS_CORE * Set to 1 if the Byte is the second of a WORD (only for OSAI Nc) * Reference to variable to read/Write * */ + public abstract CmsError MEM_RWByte(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int MemByte, ref Byte Value); /** @@ -737,10 +884,9 @@ namespace CMS_CORE * Set to 1 if the Byte is the second of a WORD (only for OSAI Nc) * Reference to variable to read/Write * */ + public abstract CmsError MEM_RWByte(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int MemByte, ref Byte Value); - - /** * Read/Write unsigned 2 Byte (NC: Word:, .NET: ushort) variable from/into NC Memory Area * @@ -755,6 +901,7 @@ namespace CMS_CORE * Number of sequential data Read/Write. (Used only in Reading Operation) * List of values to read/Write * */ + public abstract CmsError MEM_RWWord(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, ref ushort Value); /** @@ -772,10 +919,9 @@ namespace CMS_CORE * Number of sequential data Read/Write. (Used only in Reading Operation) * List of values to read/Write * */ + public abstract CmsError MEM_RWWord(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, ref ushort Value); - - /** * Read/Write signed 2 Byte (NC: Word:, .NET: short) variable from/into NC Memory Area * @@ -790,6 +936,7 @@ namespace CMS_CORE * Number of sequential data Read/Write. (Used only in Reading Operation) * List of values to read/Write * */ + public abstract CmsError MEM_RWShort(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, ref short Value); /** @@ -807,10 +954,9 @@ namespace CMS_CORE * Number of sequential data Read/Write. (Used only in Reading Operation) * List of values to read/Write * */ + public abstract CmsError MEM_RWShort(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, ref short Value); - - /** * Read/Write signed 4 Byte (NC: DWord:, .NET: uint) variable from/into NC Memory Area * @@ -825,6 +971,7 @@ namespace CMS_CORE * Number of sequential data Read/Write. (Used only in Reading Operation) * List of values to read/Write * */ + public abstract CmsError MEM_RWDWord(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, ref uint Value); /** @@ -842,10 +989,9 @@ namespace CMS_CORE * Number of sequential data Read/Write. (Used only in Reading Operation) * List of values to read/Write * */ + public abstract CmsError MEM_RWDWord(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, ref uint Value); - - /** * Read/Write signed 4 Byte (NC: DWord:, .NET: int) variable from/into NC Memory Area * @@ -860,6 +1006,7 @@ namespace CMS_CORE * Number of sequential data Read/Write. (Used only in Reading Operation) * List of values to read/Write * */ + public abstract CmsError MEM_RWInteger(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, ref int Value); /** @@ -877,11 +1024,13 @@ namespace CMS_CORE * Number of sequential data Read/Write. (Used only in Reading Operation) * List of values to read/Write * */ + public abstract CmsError MEM_RWInteger(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, ref int Value); - #endregion + #endregion MEMORY Low-level function: single valiable in memory (to override) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region NC Low-level function: variables List in memory (to override) /** @@ -899,6 +1048,7 @@ namespace CMS_CORE * Number of sequential data Read/Write. (Used only in Reading Operation) * List of values to read/Write * */ + public abstract CmsError MEM_RWByteList(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int MemByteStart, int Number, ref List Value); /** @@ -917,10 +1067,9 @@ namespace CMS_CORE * Number of sequential data Read/Write. (Used only in Reading Operation) * List of values to read/Write * */ + public abstract CmsError MEM_RWByteList(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int MemByteStart, int Number, ref List Value); - - /** * Read/Write List of unsigned 2 Byte (NC: Word:, .NET: ushort) from/into NC Memory Area * @@ -935,6 +1084,7 @@ namespace CMS_CORE * Number of sequential data Read/Write. (Used only in Reading Operation) * List of values to read/Write * */ + public abstract CmsError MEM_RWWordList(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int Number, ref List Value); /** @@ -952,10 +1102,9 @@ namespace CMS_CORE * Number of sequential data Read/Write. (Used only in Reading Operation) * List of values to read/Write * */ + public abstract CmsError MEM_RWWordList(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int Number, ref List Value); - - /** * Read/Write List of signed 2 Byte (NC: Word:, .NET: short) from/into NC Memory Area * @@ -972,6 +1121,7 @@ namespace CMS_CORE * */ public abstract CmsError MEM_RWShortList(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int Number, ref List Value); + /** * Read/Write List of signed 2 Byte (NC: Word:, .NET: short) from/into NC Memory Area (including Siemens Nc) * @@ -987,10 +1137,9 @@ namespace CMS_CORE * Number of sequential data Read/Write. (Used only in Reading Operation) * List of values to read/Write * */ + public abstract CmsError MEM_RWShortList(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int Number, ref List Value); - - /** * Read/Write List of unsigned 4 Byte (NC: DWord:, .NET: uint) from/into NC Memory Area * @@ -1005,6 +1154,7 @@ namespace CMS_CORE * Number of sequential data Read/Write. (Used only in Reading Operation) * List of values to read/Write * */ + public abstract CmsError MEM_RWDWordList(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int Number, ref List Value); /** @@ -1022,10 +1172,9 @@ namespace CMS_CORE * Number of sequential data Read/Write. (Used only in Reading Operation) * List of values to read/Write * */ + public abstract CmsError MEM_RWDWordList(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int Number, ref List Value); - - /** * Read/Write List of signed 4 Byte (NC: DWord:, .NET: int) from/into NC Memory Area * @@ -1040,6 +1189,7 @@ namespace CMS_CORE * Number of sequential data Read/Write. (Used only in Reading Operation) * List of values to read/Write * */ + public abstract CmsError MEM_RWIntegerList(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int Number, ref List Value); /** @@ -1057,11 +1207,13 @@ namespace CMS_CORE * Number of sequential data Read/Write. (Used only in Reading Operation) * List of values to read/Write * */ + public abstract CmsError MEM_RWIntegerList(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int Number, ref List Value); - #endregion + #endregion NC Low-level function: variables List in memory (to override) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region File Management (To override) /** @@ -1075,6 +1227,7 @@ namespace CMS_CORE * Name of the Part Program and name of new local file * Reference to the new local file where the NC Part Program data will be saved * */ + public abstract CmsError FILES_RProgramToFile(string partProgramPath, FileStream localFile); /** @@ -1087,6 +1240,7 @@ namespace CMS_CORE * Path of the Part Program stored in the Nc * Reference to the local Part Program file * */ + public abstract CmsError FILES_WProgramFromFile(string partProgramPath, FileStream localFile); /** @@ -1095,15 +1249,16 @@ namespace CMS_CORE * Compatibility: Fanuc | Osai | Demo | Siemens * * - * Returns an error when an internal or a library error occours + * Returns an error when an internal or a library error occours * Path where the Part Program is saved in the NC * Path of the copy Part Program destination * * */ + public abstract CmsError FILES_CopyProgram(string partProgramPath, string newPartProgramPath, bool failIfExist); /** - * Delete a Nc Part Program + * Delete a Nc Part Program * * Compatibility: Fanuc | Osai | Demo | Siemens * @@ -1112,11 +1267,13 @@ namespace CMS_CORE * Path where the Nc Part Program is saved in the NC * Name of the Part Program file * */ + public abstract CmsError FILES_DeleteProgram(string partProgramPath, string partProgramName); - #endregion + #endregion File Management (To override) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region CONSTANTS (Struct and Enum are Static for definition) // Read Write type @@ -1130,6 +1287,7 @@ namespace CMS_CORE // R-W MEMORY Type /** Nc Memory Type (Table) */ + public enum MEMORY_TYPE { /** Null Type */ @@ -1207,7 +1365,6 @@ namespace CMS_CORE /** Osai SYMO Area */ Osai_SYMO = 102, - /////////////////////////////////////////////////////////////////// //Siemens Memory Type, /** Siemens DB */ @@ -1221,6 +1378,7 @@ namespace CMS_CORE // NC Memory Type Name internal const String FANUC_MEMTYPE = "Fanuc_"; + internal const String SIEMENS_MEMTYPE = "Siemens_"; internal const String OSAI_MEMTYPE = "Osai_"; internal const String DEMO_MEMTYPE = "Demo_"; @@ -1231,6 +1389,7 @@ namespace CMS_CORE //Fanuc Variable & Const internal const short FANUC_MAXNVAR = 5; + internal const short FANUC_MAXMSGCNC = 10; internal const short FANUC_MAXMSGPMC = 5; internal const short FANUC_ABSOLUTEPOS = 0; @@ -1238,6 +1397,7 @@ namespace CMS_CORE internal const short FANUC_RELATIVEPOS = 2; internal const short FANUC_DISTTOGO = 3; internal const short FANUC_ALLPOS = -1; + internal enum FANUC_DType : short { BYTE = 0, WORD = 1, LONG = 2 }; internal const ushort OSAI_PROGRAMMEDPOS = 1; @@ -1247,9 +1407,10 @@ namespace CMS_CORE internal const ushort OSAI_DISTTOGO = 5; internal const ushort OSAI_MACHINEPOS = 6; - #endregion + #endregion CONSTANTS (Struct and Enum are Static for definition) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region Fixed memory area //Lingua CN @@ -1257,17 +1418,19 @@ namespace CMS_CORE //Matricola Macchina internal MEMORY_CELL MATR_MACCH_OSAI = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 3403, 0, 1); + internal MEMORY_CELL MATR_MACCH_FANUC = new MEMORY_CELL(MEMORY_TYPE.Fanuc_D, 4018, 0, 1); internal MEMORY_CELL MATR_MACCH_SIEMENS = new MEMORY_CELL(MEMORY_TYPE.Siemens_DB, 255, 0, 1); //Messaggi PLC internal MEMORY_CELL PLC_MESS_OSAI = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 12000, 0, 64); - - #endregion + #endregion Fixed memory area /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region Helper Function + internal void AddNcAlarmToList(uint id, string message, List alarms) { alarms.Add(new AlarmModel() @@ -1300,6 +1463,7 @@ namespace CMS_CORE Process = processes }); } - #endregion + + #endregion Helper Function } -} +} \ No newline at end of file diff --git a/CMS_CORE_Library/Osai/Nc_Osai.cs b/CMS_CORE_Library/Osai/Nc_Osai.cs index fe16831..9b7b3bb 100644 --- a/CMS_CORE_Library/Osai/Nc_Osai.cs +++ b/CMS_CORE_Library/Osai/Nc_Osai.cs @@ -352,16 +352,6 @@ namespace CMS_CORE.Osai #region PLC High-level data - public override CmsError PLC_RPowerOnData(ref PreAndPostPowerOnModel powerOnModel) - { - return NO_ERROR; - } - - public override CmsError PLC_WPowerOnData(uint id, bool value) - { - return NO_ERROR; - } - //Get the PLC Active Alarms //public override CmsError PLC_RActiveMessages(ref List alarms) //{ @@ -407,19 +397,19 @@ namespace CMS_CORE.Osai try { alarms.Clear(); - List readedValues = new List(); + List readValues = new List(); // Read on data from memory CmsError cmsError = MEM_RWIntegerList(R, 0, MEMORY_ADDRESS.ALARMS_STATUS.MemType, MEMORY_ADDRESS.ALARMS_STATUS.Address, (MEMORY_ADDRESS.ALARMS_STATUS.Size + MEMORY_ADDRESS.ALARMS_DATA.Size) / 4, - ref readedValues); + ref readValues); if (cmsError.IsError()) return cmsError; // Convert integer array into bit array - bool[] statusBits = new BitArray(readedValues.ToArray()).Cast().ToArray(); + bool[] statusBits = new BitArray(readValues.ToArray()).Cast().ToArray(); for (int i = 0; i < MEMORY_ADDRESS.ALARMS_STATUS.Size * 8; i++) { @@ -461,6 +451,21 @@ namespace CMS_CORE.Osai return NO_ERROR; } + public override CmsError PLC_WRestoreMessage(uint id) + { + return NO_ERROR; + } + + public override CmsError PLC_RPowerOnData(ref PreAndPostPowerOnModel powerOnModel) + { + return NO_ERROR; + } + + public override CmsError PLC_WPowerOnData(uint id, bool value) + { + return NO_ERROR; + } + public override CmsError PLC_RFunctionAccess(ref List functions) { functions = new List(); @@ -477,12 +482,22 @@ namespace CMS_CORE.Osai return NO_ERROR; } - public override CmsError PLC_RSoftKeys(ref List softKeys) + public override CmsError PLC_WNcSoftKey(uint id) { return NO_ERROR; } - public override CmsError PLC_WSoftKey(uint id) + public override CmsError PLC_RNcSoftKeys(ref List ncSoftKeys) + { + return NO_ERROR; + } + + public override CmsError PLC_RUserSoftKeys(ref List softKeys) + { + return NO_ERROR; + } + + public override CmsError PLC_WUserSoftKey(uint id) { return NO_ERROR; } @@ -759,7 +774,7 @@ namespace CMS_CORE.Osai #region PROCESS-AXES (PATH) High-level data //Get a dictionary with the Actual position of the axes in Process - public override CmsError AXES_RInterpPosition(ushort Process, ref Dictionary Axes) + public override CmsError AXES_RInterpPosition(ushort process, ref Dictionary Axes) { //Check if the NC is Connected CmsError cmsError = CheckConnection(); @@ -776,7 +791,7 @@ namespace CMS_CORE.Osai //Try to get information try { - nReturn = OpenNC.GetAxesPosition(Process, 0, OSAI_INTERPOLPOS, ref nAxis, out Pos, out errorClass, out errorNum); + nReturn = OpenNC.GetAxesPosition(process, 0, OSAI_INTERPOLPOS, ref nAxis, out Pos, out errorClass, out errorNum); //If there's an error launch exception if (errorClass != 0 || errorNum != 0 || nReturn == 0) @@ -811,7 +826,7 @@ namespace CMS_CORE.Osai } //Get a dictionary with the Programmed position of the axes in Process - public override CmsError AXES_RProgrPosition(ushort Process, ref Dictionary Axes) + public override CmsError AXES_RProgrPosition(ushort process, ref Dictionary Axes) { //Check if the NC is Connected CmsError cmsError = CheckConnection(); @@ -828,7 +843,7 @@ namespace CMS_CORE.Osai //Try to get information try { - nReturn = OpenNC.GetAxesPosition(Process, 0, OSAI_PROGRAMMEDPOS, ref nAxis, out Pos, out errorClass, out errorNum); + nReturn = OpenNC.GetAxesPosition(process, 0, OSAI_PROGRAMMEDPOS, ref nAxis, out Pos, out errorClass, out errorNum); //If there's an error launch exception if (errorClass != 0 || errorNum != 0 || nReturn == 0) @@ -863,7 +878,7 @@ namespace CMS_CORE.Osai } //Get a dictionary with the Machine position of the axes in Process - public override CmsError AXES_RMachinePosition(ushort Process, ref Dictionary Axes) + public override CmsError AXES_RMachinePosition(ushort process, ref Dictionary Axes) { //Check if the NC is Connected CmsError cmsError = CheckConnection(); @@ -880,7 +895,7 @@ namespace CMS_CORE.Osai //Try to get information try { - nReturn = OpenNC.GetAxesPosition(Process, 0, OSAI_MACHINEPOS, ref nAxis, out Pos, out errorClass, out errorNum); + nReturn = OpenNC.GetAxesPosition(process, 0, OSAI_MACHINEPOS, ref nAxis, out Pos, out errorClass, out errorNum); //If there's an error launch exception if (errorClass != 0 || errorNum != 0 || nReturn == 0) @@ -915,7 +930,7 @@ namespace CMS_CORE.Osai } //Get a dictionary with the Following Error of the axes in Process - public override CmsError AXES_RFollowingError(ushort Process, ref Dictionary Axes) + public override CmsError AXES_RFollowingError(ushort process, ref Dictionary Axes) { //Check if the NC is Connected CmsError cmsError = CheckConnection(); @@ -932,7 +947,7 @@ namespace CMS_CORE.Osai //Try to get information try { - nReturn = OpenNC.GetAxesPosition(Process, 0, OSAI_FOLLERROR, ref nAxis, out Pos, out errorClass, out errorNum); + nReturn = OpenNC.GetAxesPosition(process, 0, OSAI_FOLLERROR, ref nAxis, out Pos, out errorClass, out errorNum); //If there's an error launch exception if (errorClass != 0 || errorNum != 0 || nReturn == 0) @@ -967,7 +982,7 @@ namespace CMS_CORE.Osai } //Get a dictionary with the Distance To Go of the axes in Process - public override CmsError AXES_RDistanceToGo(ushort Process, ref Dictionary Axes) + public override CmsError AXES_RDistanceToGo(ushort process, ref Dictionary Axes) { //Check if the NC is Connected CmsError cmsError = CheckConnection(); @@ -984,7 +999,7 @@ namespace CMS_CORE.Osai //Try to get information try { - nReturn = OpenNC.GetAxesPosition(Process, 0, OSAI_FOLLERROR, ref nAxis, out Pos, out errorClass, out errorNum); + nReturn = OpenNC.GetAxesPosition(process, 0, OSAI_FOLLERROR, ref nAxis, out Pos, out errorClass, out errorNum); //If there's an error launch exception if (errorClass != 0 || errorNum != 0 || nReturn == 0) @@ -1018,6 +1033,61 @@ namespace CMS_CORE.Osai return NO_ERROR; } + public override CmsError AXES_RAxesNames(ushort process, ref List axesData) + { + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.IsError()) + return cmsError; + + axesData.Clear(); + + ushort nReturn, axesNumber = 64; + uint errorClass, errorNum; + unsignedshortarray axesProcess; + unsignedshortarray axesType; + unsignedshortarray axesInterface; + byte[] axesName; + + //Try to get information + try + { + // Read axes info from NC + nReturn = OpenNC.GetAxesInfo3(ushort.MaxValue, ref axesNumber, out axesProcess, out axesName, out axesType, out axesInterface, out errorClass, out errorNum); + + for (int i = 0; i < axesNumber; i++) + { + var charName = Convert.ToChar(axesName[i]); + // Filter per master axes and process + if((charName < 'a' || charName > 'z') && charName != 'S' && charName != '\0' && axesProcess[i] == process) + { + // Add to returned value + axesData.Add(new AxisModel() + { + Id = i + 1, + Name = charName.ToString() + }); + } + } + + return NO_ERROR; + } + catch (Exception ex) + { + return ManageException(ex); + } + } + + public override CmsError AXES_RSelectedAxis(ref byte axisId) + { + return NO_ERROR; + } + + public override CmsError AXES_WSelectAxis(byte axisId) + { + return NO_ERROR; + } + #endregion PROCESS-AXES (PATH) High-level data /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/CMS_CORE_Library/Siemens/Nc_Siemens.cs b/CMS_CORE_Library/Siemens/Nc_Siemens.cs index 3764d71..a9a849c 100644 --- a/CMS_CORE_Library/Siemens/Nc_Siemens.cs +++ b/CMS_CORE_Library/Siemens/Nc_Siemens.cs @@ -298,6 +298,11 @@ namespace CMS_CORE.Siemens return NO_ERROR; } + public override CmsError PLC_WRestoreMessage(uint id) + { + return NO_ERROR; + } + public override CmsError PLC_RFunctionAccess(ref List functions) { functions = new List(); @@ -324,12 +329,22 @@ namespace CMS_CORE.Siemens return NO_ERROR; } - public override CmsError PLC_RSoftKeys(ref List softKeys) + public override CmsError PLC_RNcSoftKeys(ref List ncSoftKeys) { return NO_ERROR; } - public override CmsError PLC_WSoftKey(uint id) + public override CmsError PLC_RUserSoftKeys(ref List softKeys) + { + return NO_ERROR; + } + + public override CmsError PLC_WNcSoftKey(uint id) + { + return NO_ERROR; + } + + public override CmsError PLC_WUserSoftKey(uint id) { return NO_ERROR; } @@ -598,6 +613,20 @@ namespace CMS_CORE.Siemens return FUNCTION_NOT_ALLOWED_ERROR; } + public override CmsError AXES_RAxesNames(ushort process, ref List axesData) + { + return NO_ERROR; + } + + public override CmsError AXES_RSelectedAxis(ref byte axisId) + { + return NO_ERROR; + } + + public override CmsError AXES_WSelectAxis(byte axisId) + { + return NO_ERROR; + } #endregion PROCESS-AXES (PATH) High-level data /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Database/DatabaseController.cs b/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Database/DatabaseController.cs index 6c9c47f..da5bf95 100644 --- a/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Database/DatabaseController.cs +++ b/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Database/DatabaseController.cs @@ -325,13 +325,20 @@ namespace Nc_Demo_Application.Database public List GetNcAxes() { + int lastId = 0; List axes = new List(); foreach (DataRow row in ncAxesDataTable.Rows) { + + if (Convert.IsDBNull(row["id"])) + lastId = lastId + 1; + else + lastId = Convert.ToInt32(row["id"]); + // Convert DataTable.row into axis model NcAxisModel tmpAxis = new NcAxisModel { - id = Convert.ToInt32(row["id"]), + id = lastId, name = row["name"].ToString(), actual = Convert.ToDouble(row["actual"]), programmed = Convert.ToDouble(row["programmed"]),