diff --git a/CMS_CORE_Application/Form1.cs b/CMS_CORE_Application/Form1.cs index 9878101..565691a 100644 --- a/CMS_CORE_Application/Form1.cs +++ b/CMS_CORE_Application/Form1.cs @@ -71,6 +71,7 @@ namespace CMS_CORE_Application List ncAlarms = new List(); List Lines = new List(); PostPowerOnModel postPowerOn = new PostPowerOnModel(); + AxisResetDataModel axisResetDataModel = new AxisResetDataModel(); N = SetNcByType(); @@ -118,23 +119,6 @@ namespace CMS_CORE_Application error = true; SetError(Lines, cmsError); } - - //cmsError = N.PROC_RPPLines(1, ref Lines); - //if (cmsError.IsError()) - //{ - // error = true; - // SetError(Lines, cmsError); - //} - - //cmsError = N.PROC_RPPName(1, ref PPName); - //if (cmsError.IsError()) - //{ - // error = true; - // SetError(Lines, cmsError); - //} - ProcessData process = new ProcessData(); - sw.Restart(); - cmsError = N.PROC_RStatus(1, ref process); sw.Stop(); cmsError = N.NC_RDateTime(ref NcTime); if (cmsError.IsError()) @@ -142,16 +126,14 @@ namespace CMS_CORE_Application error = true; SetError(Lines, cmsError); } + List a = null; + cmsError = N.PLC_RFunctionAccess(ref a); - PreAndPostPowerOnModel preAndPostPowerOnModel = new PreAndPostPowerOnModel(); - cmsError = N.Nc_RPowerOnData(ref preAndPostPowerOnModel); - if (cmsError.IsError()) - { - error = true; - SetError(Lines, cmsError); - } + PreAndPostPowerOnModel preAndPostPowerOnModel = new PreAndPostPowerOnModel(); - cmsError = N.Nc_WPowerOnData(10, true); + N.PLC_RAxesResetData(ref axisResetDataModel); + + cmsError = N.PLC_RPowerOnData(ref preAndPostPowerOnModel); if (cmsError.IsError()) { error = true; @@ -169,9 +151,9 @@ namespace CMS_CORE_Application TXTMachNum.Text = MachNumber; TXTSft.Text = SFTVersion; TXTTime.Text = sw.ElapsedMilliseconds.ToString() + " mS"; - TXTAlm.Text = String.Join(Environment.NewLine, procAlarms.Select(x => x.message)); - TXTAlmNc.Text = String.Join(Environment.NewLine, ncAlarms.Select(x => x.message)); - TXTMsg.Text = String.Join(Environment.NewLine, Msg.Select(x => x.message)); + TXTAlm.Text = String.Join(Environment.NewLine, procAlarms.Select(x => x.Message)); + TXTAlmNc.Text = String.Join(Environment.NewLine, ncAlarms.Select(x => x.Message)); + TXTMsg.Text = String.Join(Environment.NewLine, Msg.Select(x => x.Message)); TXTPPName.Text = PPName; TXTNow.Text = NcTime.ToString(); @@ -207,16 +189,16 @@ namespace CMS_CORE_Application { stopwatch.Restart(); // Read next tool area - N.MEM_RWByte(Nc.R, 0, Nc.MEMORY_Type.Fanuc_R, 8000, 1, ref id); + N.MEM_RWByte(Nc.R, 0, Nc.MEMORY_TYPE.Fanuc_R, 8000, 1, ref id); // if not empty if (id != 0) { ToolModel tool = RicercaPerManina(id); List list = new List() { id, tool.FamilyId, tool.ShankId}; - N.MEM_RWIntegerList(Nc.W, 0, Nc.MEMORY_Type.Fanuc_R, 8001, 0, ref list); + N.MEM_RWIntegerList(Nc.W, 0, Nc.MEMORY_TYPE.Fanuc_R, 8001, 0, ref list); id = 0; - N.MEM_RWByte(Nc.W, 0, Nc.MEMORY_Type.Fanuc_R, 8000, 1, ref id); + N.MEM_RWByte(Nc.W, 0, Nc.MEMORY_TYPE.Fanuc_R, 8000, 1, ref id); stopwatch.Stop(); Debug.WriteLine(stopwatch.ElapsedMilliseconds.ToString()); } diff --git a/CMS_CORE_Library/DataStructures.cs b/CMS_CORE_Library/DataStructures.cs index 9e9c12b..e9f3f2e 100644 --- a/CMS_CORE_Library/DataStructures.cs +++ b/CMS_CORE_Library/DataStructures.cs @@ -9,6 +9,76 @@ namespace CMS_CORE_Library { public static class DataStructures { + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region Data structor models + + public struct PreAndPostPowerOnModel + { + public PrePowerOnModel prePowerOn; + public PostPowerOnModel postPowerOn; + } + public struct PowerOnDataModel + { + public uint Id; + public bool Active; + public bool Clickable; + } + + public class PrePowerOnModel + { + public PowerOnDataModel PowerOn; + public PowerOnDataModel AirPressure; + public PowerOnDataModel ProtectionStatus; + public PowerOnDataModel EmergencyButtons; + public PowerOnDataModel SettingMode; + public PowerOnDataModel StartingKey; + } + + public class PostPowerOnModel + { + public PowerOnDataModel AxisReset; + public PowerOnDataModel WaterjetPump; + } + + public class AlarmModel + { + public uint Id; + public string Message; + public bool IsWarning; + public int Process; + } + + public class ProcessDataModel + { + public ushort Id; + public string Type; + public bool IsInAlarm; + public string PartProgramName; + public string Status; + public bool Visible; + public byte Reps; + } + + public struct FunctionalityModel + { + public uint Id; + public bool IsActive; + } + + public struct StrobeModel + { + public uint Id; + public bool IsActive; + } + + public struct AxisResetDataModel + { + public bool IsActive; + public int Percentage; + } + + #endregion + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #region Cms Errors Codes @@ -71,57 +141,5 @@ namespace CMS_CORE_Library internal static CmsError SIEMENS_HMI_NOT_RUNNING_ERROR = new CmsError(CMS_ERROR_CODES.SIEMENS_HMI_NOT_RUNNING, "CMS-Core-Error: Siemens HMI is not Running / Ready"); #endregion - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - #region Data structor models - - public struct PreAndPostPowerOnModel - { - public PrePowerOnModel prePowerOn; - public PostPowerOnModel postPowerOn; - } - public struct PowerOnDataModel - { - public uint Id; - public bool Active; - public bool Clickable; - } - - public class PrePowerOnModel - { - public PowerOnDataModel PowerOn; - public PowerOnDataModel AirPressure; - public PowerOnDataModel ProtectionStatus; - public PowerOnDataModel EmergencyButtons; - public PowerOnDataModel SettingMode; - public PowerOnDataModel StartingKey; - } - - public class PostPowerOnModel - { - public PowerOnDataModel AxisReset; - public PowerOnDataModel WaterjetPump; - } - - public class AlarmModel - { - public uint id; - public string message; - public bool isWarning; - public int process; - } - - public class ProcessData - { - public ushort Id; - public string Type; - public bool IsInAlarm; - public string PartProgramName; - public string Status; - public bool Visible; - public byte Reps; - } - - #endregion } } diff --git a/CMS_CORE_Library/Demo/Nc_Demo.cs b/CMS_CORE_Library/Demo/Nc_Demo.cs index 0f4ce85..bd19cc3 100644 --- a/CMS_CORE_Library/Demo/Nc_Demo.cs +++ b/CMS_CORE_Library/Demo/Nc_Demo.cs @@ -1,28 +1,27 @@ -using System; +using CMS_CORE.Demo.Models; +using CMS_CORE.Utils; +using CMS_CORE_Library.Demo.Models; +using Nc_Demo_Application.Server.Service; +using System; +using System.Collections; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using System.ServiceModel; using System.ServiceModel.Description; -using CMS_CORE.Demo.Models; -using CMS_CORE_Library.Demo.Models; -using Nc_Demo_Application.Server.Service; -using CMS_CORE.Utils; using static CMS_CORE_Library.DataStructures; -using System.Collections; -using static CMS_CORE.Nc; namespace CMS_CORE.Demo { public class Nc_Demo : Nc { - private EndpointAddress serverAddress; private ChannelFactory cf; private ILibraryService serverService; /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region Contructor & global methods public Nc_Demo(String IpAddress, ushort RemotePort) @@ -65,9 +64,10 @@ namespace CMS_CORE.Demo return NO_ERROR; } - #endregion + #endregion Contructor & global methods /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region High level methods public override CmsError NC_RDateTime(ref DateTime ActualTime) @@ -201,7 +201,7 @@ namespace CMS_CORE.Demo try { - // Get language from Demo server + // Get language from Demo server string demoLanguage = ""; serverService.GetLanguage(out demoLanguage); @@ -222,7 +222,69 @@ namespace CMS_CORE.Demo return NO_ERROR; } - public override CmsError Nc_RPowerOnData(ref PreAndPostPowerOnModel powerOnModel) + // Check if the NC is in running state + public override CmsError NC_RIsRunning(ref bool running) + { + ushort nProcess = 0; + // Get the number of processes + CmsError cmsError = NC_RProcessesNum(ref nProcess); + if (cmsError.IsError()) + return cmsError; + + ushort i = 1; + running = false; + do + { + PROC_STATUS procStatus = PROC_STATUS.IDLE; + + // Read process status + cmsError = PROC_RStatus(i, ref procStatus); + if (cmsError.IsError()) + return cmsError; + // If one process is runninc, nc is running + if (procStatus == PROC_STATUS.RUN) + running = true; + i++; + } while (!running || i <= nProcess); + + return NO_ERROR; + } + + #endregion High level methods + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + #region PLC High-level data + + public override CmsError PLC_RActiveMessages(ref List alarms) + { + // Check if the NC Demo is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.IsError()) + return cmsError; + + try + { + alarms.Clear(); + + List demoAlarms; + // Get Alarms from server + serverService.GetProcessesAlarms(out demoAlarms); + // Parse response + foreach (NcAlarmModel demoAlarm in demoAlarms) + { + AddAlarmToList((uint)demoAlarm.code, demoAlarm.text, alarms); + } + } + catch (Exception ex) + { + return ManageException(ex); + } + + return NO_ERROR; + } + + public override CmsError PLC_RPowerOnData(ref PreAndPostPowerOnModel powerOnModel) { try { @@ -267,7 +329,7 @@ namespace CMS_CORE.Demo return NO_ERROR; } - public override CmsError Nc_WPowerOnData(uint id, bool value) + public override CmsError PLC_WPowerOnData(uint id, bool value) { try { @@ -276,72 +338,15 @@ namespace CMS_CORE.Demo if (id > 16) return INCORRECT_PARAMETERS_ERROR; // Choose Pre-Power-On or Post-Power-Om - if (id <= 8) + if (id < 8) // Pre: memory bit = id cmsError = MEM_RWBoolean(W, 0, MEMORY_ADDRESS.PRE_POWER_ON_CLICKED.MemType, MEMORY_ADDRESS.PRE_POWER_ON_CLICKED.Address, (int)id, ref value); else // Post: memory bit = id - 8 cmsError = MEM_RWBoolean(W, 0, MEMORY_ADDRESS.POST_POWER_ON_CLICKED.MemType, MEMORY_ADDRESS.POST_POWER_ON_CLICKED.Address, (int)id - 8, ref value); - } - catch (Exception ex) - { - return ManageException(ex); - } - return NO_ERROR; - } - // Check if the NC is in running state - public override CmsError NC_RIsRunning(ref bool running) - { - ushort nProcess = 0; - // Get the number of processes - CmsError cmsError = NC_RProcessesNum(ref nProcess); - if (cmsError.IsError()) - return cmsError; - - ushort i = 1; - running = false; - do - { - PROC_STATUS procStatus = PROC_STATUS.IDLE; - - // Read process status - cmsError = PROC_RStatus(i, ref procStatus); if (cmsError.IsError()) return cmsError; - // If one process is runninc, nc is running - if (procStatus == PROC_STATUS.RUN) - running = true; - i++; - } while (!running || i <= nProcess); - - - return NO_ERROR; - } - #endregion - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - #region PLC High-level data - - public override CmsError PLC_RActiveMessages(ref List alarms) - { - // Check if the NC Demo is Connected - CmsError cmsError = CheckConnection(); - if (cmsError.IsError()) - return cmsError; - - try - { - alarms.Clear(); - - List demoAlarms; - // Get Alarms from server - serverService.GetProcessesAlarms(out demoAlarms); - // Parse response - foreach (NcAlarmModel demoAlarm in demoAlarms) - { - AddAlarmToList((uint)demoAlarm.code, demoAlarm.text, alarms); - } } catch (Exception ex) { @@ -351,9 +356,80 @@ namespace CMS_CORE.Demo return NO_ERROR; } - #endregion + public override CmsError PLC_RFunctionAccess(ref List functions) + { + List readValue = 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 readValue); + if (cmsError.IsError()) + return cmsError; + + functions = new List(); + // Convert int into to true/false array + bool[] bits = new BitArray(readValue.ToArray()).Cast().ToArray(); + // Convert array into structured data + for (int i = 0; i < bits.Count(); i++) + { + functions.Add(new FunctionalityModel() + { + Id = (uint)i, + IsActive = bits[i] + }); + } + + return NO_ERROR; + } + + public override CmsError PLC_RAxesResetData(ref AxisResetDataModel axisResetData) + { + byte value = 0; + // Read byte from memory + CmsError cmsError = MEM_RWByte(R, 0, MEMORY_ADDRESS.AXIS_RESET_PROCEDURE.MemType, MEMORY_ADDRESS.AXIS_RESET_PROCEDURE.Address, 1, ref value); + if (cmsError.IsError()) + return cmsError; + + // Check last bit + if ((value & 128) == 128) + { + // Set to 0 last bit and 7 bit percentage and check if is higher than 100 + byte percentage = value - 128 > 100 ? (byte)100 : (byte)(value - 128); + axisResetData = new AxisResetDataModel() + { + IsActive = true, + Percentage = percentage + }; + } + + return NO_ERROR; + } + + //public override CmsError PLC_RStrobe(ref List functions) + //{ + // List readValue = 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 readValue); + // if (cmsError.IsError()) + // return cmsError; + + // functions = new List(); + // // Convert int into to true/false array + // bool[] bits = new BitArray(readValue.ToArray()).Cast().ToArray(); + // // Convert array into structured data + // for (int i = 0; i < bits.Count(); i++) + // { + // functions.Add(new StrobeModel() + // { + // id = (uint)i, + // isActive = bits[i] + // }); + // } + // return NO_ERROR; + //} + + #endregion PLC High-level data /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region PROCESS (PATH) High-level data public override CmsError PROC_RStatus(ushort ProcNumber, ref PROC_STATUS Status) @@ -432,7 +508,7 @@ namespace CMS_CORE.Demo } // Get process part program data - public override CmsError PROC_RStatus(ushort procNumber, ref ProcessData processData) + public override CmsError PROC_RStatusAndData(ushort procNumber, ref ProcessDataModel processData) { processData.Id = procNumber; // Read part program name @@ -449,7 +525,7 @@ namespace CMS_CORE.Demo byte[] bytes = BitConverter.GetBytes(readValue); // Convert Byte into true/false array - BitArray bits = new BitArray(new byte[] { bytes[0] }); //1st byte -> 0 : Proccess type (AUX-WORK), 1: Process in alarm status, 2: Run, 3: Hold, 4: Read, 5: PartProgramVisible + BitArray bits = new BitArray(new byte[] { bytes[0] }); //1st byte -> 0 : Proccess type (AUX-WORK), 1: Process in alarm status, 2: Run, 3: Hold, 4: Read, 5: PartProgramVisible // Populate response structure processData.Type = bits[0] ? "WORK" : "AUX"; processData.IsInAlarm = bits[1]; @@ -463,20 +539,21 @@ namespace CMS_CORE.Demo processData.Status = "HOLD"; else processData.Status = "READY"; - } - + } + // Get Reps from 2nd byte processData.Reps = bytes[1]; // Get part program info visibility - processData.Visible = bits[5]; + processData.Visible = bits[4]; return NO_ERROR; } - #endregion + #endregion PROCESS (PATH) High-level data /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region PROCESS-AXES (PATH) High-level data public override CmsError AXES_RInterpPosition(ushort ProcNumber, ref Dictionary Axes) @@ -604,12 +681,13 @@ namespace CMS_CORE.Demo return NO_ERROR; } - #endregion + #endregion PROCESS-AXES (PATH) High-level data /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region NC Low-level function: single valiable in memory - public override CmsError MEM_RWBoolean(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, int MemBit, ref bool Value) + public override CmsError MEM_RWBoolean(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int MemBit, ref bool Value) { // Check if the NC Demo is Connected CmsError cmsError = CheckConnection(); @@ -643,7 +721,7 @@ namespace CMS_CORE.Demo return NO_ERROR; } - public override CmsError MEM_RWByte(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, int MemByte, ref byte Value) + public override CmsError MEM_RWByte(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int MemByte, ref byte Value) { // Check if the NC Demo is Connected CmsError cmsError = CheckConnection(); @@ -672,7 +750,7 @@ namespace CMS_CORE.Demo return NO_ERROR; } - public override CmsError MEM_RWWord(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, ref ushort Value) + public override CmsError MEM_RWWord(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, ref ushort Value) { // Check if the NC Demo is Connected CmsError cmsError = CheckConnection(); @@ -701,7 +779,7 @@ namespace CMS_CORE.Demo return NO_ERROR; } - public override CmsError MEM_RWShort(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, ref short Value) + public override CmsError MEM_RWShort(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, ref short Value) { // Check if the NC Demo is Connected CmsError cmsError = CheckConnection(); @@ -730,7 +808,7 @@ namespace CMS_CORE.Demo return NO_ERROR; } - public override CmsError MEM_RWDWord(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, ref uint Value) + public override CmsError MEM_RWDWord(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, ref uint Value) { // Check if the NC Demo is Connected CmsError cmsError = CheckConnection(); @@ -759,7 +837,7 @@ namespace CMS_CORE.Demo return NO_ERROR; } - public override CmsError MEM_RWInteger(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, ref int Value) + public override CmsError MEM_RWInteger(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, ref int Value) { // Check if the NC Demo is Connected CmsError cmsError = CheckConnection(); @@ -788,71 +866,71 @@ namespace CMS_CORE.Demo return NO_ERROR; } - - //-------------------------------------------------------------------------------------------------------------------------- // Siemens Version of Memory-Access Methods - public override CmsError MEM_RWBoolean(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, int MemBit, ref bool Value) + public override CmsError MEM_RWBoolean(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int MemBit, ref bool Value) { return MEM_RWBoolean(bWrite, Process, MemType, MemIndex, MemBit, ref Value); } - public override CmsError MEM_RWByte(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, int MemByte, ref byte Value) + + public override CmsError MEM_RWByte(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int MemByte, ref byte Value) { return MEM_RWByte(bWrite, Process, MemType, MemIndex, MemByte, ref Value); } - public override CmsError MEM_RWWord(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, ref ushort Value) + public override CmsError MEM_RWWord(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, ref ushort Value) { return MEM_RWWord(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); } - public override CmsError MEM_RWShort(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, ref short Value) + public override CmsError MEM_RWShort(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, ref short Value) { return MEM_RWShort(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); } - public override CmsError MEM_RWDWord(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, ref uint Value) + public override CmsError MEM_RWDWord(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, ref uint Value) { return MEM_RWDWord(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); } - public override CmsError MEM_RWInteger(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, ref int Value) + public override CmsError MEM_RWInteger(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, ref int Value) { return MEM_RWInteger(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); } - public override CmsError MEM_RWByteList(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, int MemByteStart, int Number, ref List Value) + public override CmsError MEM_RWByteList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int MemByteStart, int Number, ref List Value) { return MEM_RWByteList(bWrite, Process, MemType, MemIndex, MemByteStart, Number, ref Value); } - public override CmsError MEM_RWWordList(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, int Number, ref List Value) + public override CmsError MEM_RWWordList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int Number, ref List Value) { return MEM_RWWordList(bWrite, Process, MemType, MemIndex, Number, ref Value); } - public override CmsError MEM_RWShortList(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, int Number, ref List Value) + public override CmsError MEM_RWShortList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int Number, ref List Value) { return MEM_RWShortList(bWrite, Process, MemType, MemIndex, Number, ref Value); } - public override CmsError MEM_RWDWordList(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, int Number, ref List Value) + public override CmsError MEM_RWDWordList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int Number, ref List Value) { return MEM_RWDWordList(bWrite, Process, MemType, MemIndex, Number, ref Value); } - public override CmsError MEM_RWIntegerList(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, int Number, ref List Value) + public override CmsError MEM_RWIntegerList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int Number, ref List Value) { return MEM_RWIntegerList(bWrite, Process, MemType, MemIndex, Number, ref Value); } - #endregion + #endregion NC Low-level function: single valiable in memory /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region NC Low-level function: variables List in memory - public override CmsError MEM_RWByteList(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, int MemByteStart, int Number, ref List Value) + public override CmsError MEM_RWByteList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int MemByteStart, int Number, ref List Value) { // Check if the NC Demo is Connected CmsError cmsError = CheckConnection(); @@ -881,7 +959,7 @@ namespace CMS_CORE.Demo return NO_ERROR; } - public override CmsError MEM_RWWordList(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, int Number, ref List Value) + public override CmsError MEM_RWWordList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int Number, ref List Value) { // Check if the NC Demo is Connected CmsError cmsError = CheckConnection(); @@ -910,7 +988,7 @@ namespace CMS_CORE.Demo return NO_ERROR; } - public override CmsError MEM_RWShortList(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, int Number, ref List Value) + public override CmsError MEM_RWShortList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int Number, ref List Value) { // Check if the NC Demo is Connected CmsError cmsError = CheckConnection(); @@ -939,7 +1017,7 @@ namespace CMS_CORE.Demo return NO_ERROR; } - public override CmsError MEM_RWIntegerList(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, int Number, ref List Value) + public override CmsError MEM_RWIntegerList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int Number, ref List Value) { // Check if the NC Demo is Connected CmsError cmsError = CheckConnection(); @@ -968,7 +1046,7 @@ namespace CMS_CORE.Demo return NO_ERROR; } - public override CmsError MEM_RWDWordList(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, int Number, ref List Value) + public override CmsError MEM_RWDWordList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int Number, ref List Value) { // Check if the NC Demo is Connected CmsError cmsError = CheckConnection(); @@ -996,11 +1074,12 @@ namespace CMS_CORE.Demo return NO_ERROR; } - #endregion + + #endregion NC Low-level function: variables List in memory /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - #region NC Low-level function: Parameters + #region NC Low-level function: Parameters public override CmsError NC_RParam(short Index, short Bit, ref bool Value) { @@ -1026,9 +1105,11 @@ namespace CMS_CORE.Demo { return FUNCTION_NOT_ALLOWED_ERROR; } - #endregion + + #endregion NC Low-level function: Parameters /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region File Management public override CmsError FILES_RProgramToFile(string partProgramPath, FileStream localFile) @@ -1118,9 +1199,11 @@ namespace CMS_CORE.Demo return NO_ERROR; } - #endregion + + #endregion File Management /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region Subordinate Private Functions //Check if NC is connected @@ -1190,23 +1273,33 @@ namespace CMS_CORE.Demo return CmsError.NcError(message); } - #endregion + #endregion Subordinate Private Functions + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + #region Memory addresses + + internal static class MEMORY_ADDRESS + { + internal const int STARTING_ADDRESS = 0; + + internal static MEMORY_CELL FUNCTION_ACCESS = new MEMORY_CELL(MEMORY_TYPE.Demo, 13, 16); + internal static MEMORY_CELL STROBE = new MEMORY_CELL(MEMORY_TYPE.Demo, 29, 16); + + internal static MEMORY_CELL PRE_POWER_ON = new MEMORY_CELL(MEMORY_TYPE.Demo, 45, 1); + internal static MEMORY_CELL PRE_POWER_ON_CLICKABLE = new MEMORY_CELL(MEMORY_TYPE.Demo, 46, 1); + + internal static MEMORY_CELL POST_POWER_ON = new MEMORY_CELL(MEMORY_TYPE.Demo, 47, 1); + internal static MEMORY_CELL POST_POWER_ON_CLICKABLE = new MEMORY_CELL(MEMORY_TYPE.Demo, 48, 1); + + internal static MEMORY_CELL PRE_POWER_ON_CLICKED = new MEMORY_CELL(MEMORY_TYPE.Demo, 49, 1); + internal static MEMORY_CELL POST_POWER_ON_CLICKED = new MEMORY_CELL(MEMORY_TYPE.Demo, 50, 1); + + internal static MEMORY_CELL AXIS_RESET_PROCEDURE = new MEMORY_CELL(MEMORY_TYPE.Demo, 51, 7, 2); + + internal static MEMORY_CELL PROCESS_STATUS = new MEMORY_CELL(MEMORY_TYPE.Demo, 55, 0, 16); + } + + #endregion Memory addresses } - - internal static class MEMORY_ADDRESS - { - internal const int STARTING_ADDRESS = 0; - - internal static MEMORY_CELL PRE_POWER_ON = new MEMORY_CELL(MEMORY_Type.Demo, 29, 0, 1); - internal static MEMORY_CELL PRE_POWER_ON_CLICKABLE = new MEMORY_CELL(MEMORY_Type.Demo, 30, 0, 1); - - internal static MEMORY_CELL POST_POWER_ON = new MEMORY_CELL(MEMORY_Type.Demo, 31, 0, 1); - internal static MEMORY_CELL POST_POWER_ON_CLICKABLE = new MEMORY_CELL(MEMORY_Type.Demo, 32, 0, 1); - - internal static MEMORY_CELL PRE_POWER_ON_CLICKED = new MEMORY_CELL(MEMORY_Type.Demo, 33, 0, 1); - internal static MEMORY_CELL POST_POWER_ON_CLICKED = new MEMORY_CELL(MEMORY_Type.Demo, 34, 0, 1); - - internal static MEMORY_CELL PROCESS_STATUS = new MEMORY_CELL(MEMORY_Type.Demo, 37, 0, 1); - - } -} +} \ No newline at end of file diff --git a/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs b/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs index 606a732..11839e4 100644 --- a/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs +++ b/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs @@ -1,16 +1,11 @@ -using CMS_CORE.Exceptions; +using CMS_CORE.Utils; using System; using System.Collections.Generic; -using System.Diagnostics; using System.Globalization; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; using System.IO; -using CMS_CORE.Utils; +using System.Linq; +using System.Threading; using static CMS_CORE_Library.DataStructures; -using CMS_CORE_Library; #pragma warning disable 1591 @@ -27,10 +22,10 @@ namespace CMS_CORE.Fanuc private short Cnc_NumPath; private byte FanucLanguage; private DateTime Last_Static_Read; - Dictionary, ushort> test = new Dictionary, ushort>(); - + private Dictionary, ushort> test = new Dictionary, ushort>(); /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region Contructor & global methods /** @@ -41,6 +36,7 @@ namespace CMS_CORE.Fanuc * Remote Port of the Nc * Send/Recieve timeout connection [mS] * */ + public Nc_Fanuc(String IpAddress, ushort RemotePort, ushort ConnectionTimeOut) { //Set internal valiables @@ -54,8 +50,6 @@ namespace CMS_CORE.Fanuc nLibHandle = new List(); } - - //Connect Method public override CmsError NC_Connect() { @@ -91,7 +85,6 @@ namespace CMS_CORE.Fanuc nReturn = Focas1.cnc_setpath(nLibHandle[i], (short)(i + 1)); if (nReturn != 0) return GetNcError(nReturn); - } //Setup the "Connected" value to TRUE @@ -100,8 +93,6 @@ namespace CMS_CORE.Fanuc return NO_ERROR; } - - //Disconnect Method public override CmsError NC_Disconnect() { @@ -122,11 +113,10 @@ namespace CMS_CORE.Fanuc return NO_ERROR; } - - - #endregion + #endregion Contructor & global methods /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region High level methods //Get the NC Language @@ -142,8 +132,6 @@ namespace CMS_CORE.Fanuc return NO_ERROR; } - - //Get the NC Serial Number public override CmsError NC_RSerialNumber(ref string SN) { @@ -157,8 +145,6 @@ namespace CMS_CORE.Fanuc return NO_ERROR; } - - //Get the NC Software Version public override CmsError NC_RSoftwareVersion(ref string SWV) { @@ -172,8 +158,6 @@ namespace CMS_CORE.Fanuc return NO_ERROR; } - - //Get the NC model Name public override CmsError NC_RModelName(ref string ModelName) { @@ -187,8 +171,6 @@ namespace CMS_CORE.Fanuc return NO_ERROR; } - - //Get the processes-count configurated public override CmsError NC_RProcessesNum(ref ushort ProcNumber) { @@ -202,8 +184,6 @@ namespace CMS_CORE.Fanuc return NO_ERROR; } - - //Get the NC Time public override CmsError NC_RDateTime(ref DateTime ActualTime) { @@ -212,7 +192,6 @@ namespace CMS_CORE.Fanuc if (cmsError.IsError()) return cmsError; - Focas1.IODBTIMER TimerDate = new Focas1.IODBTIMER(); Focas1.IODBTIMER TimerTime = new Focas1.IODBTIMER(); short nReturn = 0; @@ -224,14 +203,14 @@ namespace CMS_CORE.Fanuc //Execute the method nReturn = Focas1.cnc_gettimer(nLibHandle[0], TimerDate); - //Throw Exception if there's an error + //Throw Exception if there's an error if (nReturn != 0) return GetNcError(nReturn); //Execute the method nReturn = Focas1.cnc_gettimer(nLibHandle[0], TimerTime); - //Throw Exception if there's an error + //Throw Exception if there's an error if (nReturn != 0) return GetNcError(nReturn); @@ -241,8 +220,6 @@ namespace CMS_CORE.Fanuc return NO_ERROR; } - - //Get the Machine Number public override CmsError NC_RMachineNumber(ref string MachNumber) { @@ -258,82 +235,6 @@ namespace CMS_CORE.Fanuc return NO_ERROR; } - - - public override CmsError Nc_RPowerOnData(ref PreAndPostPowerOnModel powerOnModel) - { - return NO_ERROR; - } - - - - public override CmsError Nc_WPowerOnData(uint id, bool value) - { - return NO_ERROR; - } - - - - //Get the process status - public override CmsError PROC_RStatus(ushort Number, ref PROC_STATUS Status) - { - Focas1.ODBST StatInfo = new Focas1.ODBST(); - short nReturn; - - //Check if the NC is Connected - CmsError cmsError = CheckConnection(); - if (cmsError.IsError()) - return cmsError; - - // Get path index - short path = GetHandleIndexFromPath(Number); - if (path < 0) - return PROC_NOT_FOUND_ERROR; - - //Execute the method - nReturn = Focas1.cnc_statinfo(nLibHandle[path], StatInfo); - - //Throw Exception if there's an error - if (nReturn != 0) - return GetNcError(nReturn); - - Status = ConverToSTEPStatus(StatInfo); - - return NO_ERROR; - } - - - - //Get the process Mode - public override CmsError PROC_RMode(ushort Number, ref PROC_MODE Mode) - { - Focas1.ODBST StatInfo = new Focas1.ODBST(); - short nReturn = 0; - - //Check if the NC is Connected - CmsError cmsError = CheckConnection(); - if (cmsError.IsError()) - return cmsError; - - // Get path index - short path = GetHandleIndexFromPath(Number); - if (path < 0) - return PROC_NOT_FOUND_ERROR; - - //Execute the method - nReturn = Focas1.cnc_statinfo(nLibHandle[path], StatInfo); - - //Throw Exception if there's an error - if (nReturn != 0) - return GetNcError(nReturn); - - Mode = ConverToSTEPMode(StatInfo); - - return NO_ERROR; - } - - - //Get the NC Alarms public override CmsError NC_RActiveAlarms(ref List alarms) { @@ -356,7 +257,7 @@ namespace CMS_CORE.Fanuc //Execute the method nReturn = Focas1.cnc_rdalmmsg2(nLibHandle[path], -1, ref count, Messg); - //Throw Exception if there's an error + //Throw Exception if there's an error if (nReturn != 0) return GetNcError(nReturn); @@ -386,97 +287,6 @@ namespace CMS_CORE.Fanuc return NO_ERROR; } - - - //Get the process Alarms - public override CmsError PROC_RActiveAlarms(ushort ProcNumber, ref List Alarms) - { - Alarms.Clear(); - - return NO_ERROR; - } - - - - //Get PP Lines - public override CmsError PROC_RPPLines(ushort ProcNumber, ref List Lines) - { - - //Check if the NC is Connected - CmsError cmsError = CheckConnection(); - if (cmsError.IsError()) - return cmsError; - - short nReturn = 0; - int linN; - ushort Lenght = 256; - short ReturnIndex = 1; - Char[] Chars = new Char[255]; - String[] newLines; - - short path = GetHandleIndexFromPath(ProcNumber); - if (path < 0) - return PROC_NOT_FOUND_ERROR; - - //Execute the method - nReturn = Focas1.cnc_rdblkcount(nLibHandle[path], out linN); - ReturnIndex = (short)linN; - - //Throw Exception if there's an error - if (nReturn != 0) - return GetNcError(nReturn); - - path = GetHandleIndexFromPath(ProcNumber); - if (path < 0) - return PROC_NOT_FOUND_ERROR; - - //Execute the method - nReturn = Focas1.cnc_rdexecprog(nLibHandle[path], ref Lenght, out ReturnIndex, Chars); - newLines = new String(Chars).Replace("\0", String.Empty).Split('\n'); - - //Throw Exception if there's an error - if (nReturn != 0) - return GetNcError(nReturn); - - //Setup the return values - Lines.Clear(); - foreach (String Line in newLines) - Lines.Add(Line); - - return NO_ERROR; - } - - - - //Get Active PP Name - public override CmsError PROC_RPPName(ushort ProcNumber, ref string Name) - { - - //Check if the NC is Connected - CmsError cmsError = CheckConnection(); - if (cmsError.IsError()) - return cmsError; - - short nReturn = 0; - Focas1.ODBEXEPRG Prg = new Focas1.ODBEXEPRG(); ; - - // Get path index - short path = GetHandleIndexFromPath(ProcNumber); - if (path < 0) - return PROC_NOT_FOUND_ERROR; - - //Execute the method - nReturn = Focas1.cnc_exeprgname(nLibHandle[path], Prg); - - //Throw Exception if there's an error - if (nReturn != 0) - return GetNcError(nReturn); - - Name = new String(Prg.name).Replace("\0", String.Empty); - - return NO_ERROR; - } - // Check if the NC is in running state public override CmsError NC_RIsRunning(ref bool running) { @@ -502,12 +312,84 @@ namespace CMS_CORE.Fanuc i++; } while (!running || i <= nProcess); + return NO_ERROR; + } + + #endregion High level methods + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + #region PLC High-level data + + //Get the PMC Messages + public override CmsError PLC_RActiveMessages(ref List alarms) + { + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.IsError()) + return cmsError; + + Focas1.OPMSG3 Messg = new Focas1.OPMSG3(); + short nReturn = 0; + short count = FANUC_MAXMSGPMC; + + //Execute the method + nReturn = Focas1.cnc_rdopmsg3(nLibHandle[0], -1, ref count, Messg); + + //Throw Exception if there's an error + if (nReturn != 0) + return GetNcError(nReturn); + + // Add Alarm in List + alarms.Clear(); + + if (count >= 1 && Messg.msg1.datano >= 0) + AddAlarmToList((uint)Messg.msg1.datano, Messg.msg1.data, alarms); + + if (count >= 2 && Messg.msg2.datano >= 0) + AddAlarmToList((uint)Messg.msg2.datano, Messg.msg2.data, alarms); + + if (count >= 3 && Messg.msg3.datano >= 0) + AddAlarmToList((uint)Messg.msg3.datano, Messg.msg3.data, alarms); + + if (count >= 4 && Messg.msg4.datano >= 0) + AddAlarmToList((uint)Messg.msg4.datano, Messg.msg4.data, alarms); + + if (count >= 5 && Messg.msg5.datano >= 0) + AddAlarmToList((uint)Messg.msg5.datano, Messg.msg5.data, alarms); 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(); + return NO_ERROR; + } + + public override CmsError PLC_RAxesResetData(ref AxisResetDataModel axisResetData) + { + return NO_ERROR; + } + + #endregion PLC High-level data + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + #region PROCESS (PATH) High-level data + // Get process part program data - public override CmsError PROC_RStatus(ushort procNumber, ref ProcessData processData) + public override CmsError PROC_RStatusAndData(ushort procNumber, ref ProcessDataModel processData) { //processData.Id = procNumber; //// Read part program name @@ -524,7 +406,7 @@ namespace CMS_CORE.Fanuc //byte[] bytes = BitConverter.GetBytes(readValue); //// Convert Byte into true/false array - //BitArray bits = new BitArray(new byte[] { bytes[0] }); //1st byte -> 0 : Proccess type (AUX-WORK), 1: Process in alarm status, 2: Run, 3: Hold, 4: Read, 5: PartProgramVisible + //BitArray bits = new BitArray(new byte[] { bytes[0] }); //1st byte -> 0 : Proccess type (AUX-WORK), 1: Process in alarm status, 2: Run, 3: Hold, 4: Read, 5: PartProgramVisible //// Populate response structure //processData.Type = bits[0] ? "WORK" : "AUX"; //processData.IsInAlarm = bits[1]; @@ -548,48 +430,150 @@ namespace CMS_CORE.Fanuc return NO_ERROR; } - //Get the PMC Messages - public override CmsError PLC_RActiveMessages(ref List alarms) + //Get the process Alarms + public override CmsError PROC_RActiveAlarms(ushort ProcNumber, ref List Alarms) + { + Alarms.Clear(); + + return NO_ERROR; + } + + //Get PP Lines + public override CmsError PROC_RPPLines(ushort ProcNumber, ref List Lines) { //Check if the NC is Connected CmsError cmsError = CheckConnection(); if (cmsError.IsError()) return cmsError; - Focas1.OPMSG3 Messg = new Focas1.OPMSG3(); short nReturn = 0; - short count = FANUC_MAXMSGPMC; + int linN; + ushort Lenght = 256; + short ReturnIndex = 1; + Char[] Chars = new Char[255]; + String[] newLines; + + short path = GetHandleIndexFromPath(ProcNumber); + if (path < 0) + return PROC_NOT_FOUND_ERROR; //Execute the method - nReturn = Focas1.cnc_rdopmsg3(nLibHandle[0], -1, ref count, Messg); + nReturn = Focas1.cnc_rdblkcount(nLibHandle[path], out linN); + ReturnIndex = (short)linN; - //Throw Exception if there's an error + //Throw Exception if there's an error if (nReturn != 0) return GetNcError(nReturn); - //Add Alarm in List - alarms.Clear(); + path = GetHandleIndexFromPath(ProcNumber); + if (path < 0) + return PROC_NOT_FOUND_ERROR; - if (count >= 1 && Messg.msg1.datano >= 0) - AddAlarmToList((uint)Messg.msg1.datano, Messg.msg1.data, alarms); + //Execute the method + nReturn = Focas1.cnc_rdexecprog(nLibHandle[path], ref Lenght, out ReturnIndex, Chars); + newLines = new String(Chars).Replace("\0", String.Empty).Split('\n'); - if (count >= 2 && Messg.msg2.datano >= 0) - AddAlarmToList((uint)Messg.msg2.datano, Messg.msg2.data, alarms); - - if (count >= 3 && Messg.msg3.datano >= 0) - AddAlarmToList((uint)Messg.msg3.datano, Messg.msg3.data, alarms); - - if (count >= 4 && Messg.msg4.datano >= 0) - AddAlarmToList((uint)Messg.msg4.datano, Messg.msg4.data, alarms); - - if (count >= 5 && Messg.msg5.datano >= 0) - AddAlarmToList((uint)Messg.msg5.datano, Messg.msg5.data, alarms); + //Throw Exception if there's an error + if (nReturn != 0) + return GetNcError(nReturn); + //Setup the return values + Lines.Clear(); + foreach (String Line in newLines) + Lines.Add(Line); return NO_ERROR; } + //Get Active PP Name + public override CmsError PROC_RPPName(ushort ProcNumber, ref string Name) + { + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.IsError()) + return cmsError; + short nReturn = 0; + Focas1.ODBEXEPRG Prg = new Focas1.ODBEXEPRG(); ; + + // Get path index + short path = GetHandleIndexFromPath(ProcNumber); + if (path < 0) + return PROC_NOT_FOUND_ERROR; + + //Execute the method + nReturn = Focas1.cnc_exeprgname(nLibHandle[path], Prg); + + //Throw Exception if there's an error + if (nReturn != 0) + return GetNcError(nReturn); + + Name = new String(Prg.name).Replace("\0", String.Empty); + + return NO_ERROR; + } + + //Get the process status + public override CmsError PROC_RStatus(ushort Number, ref PROC_STATUS Status) + { + Focas1.ODBST StatInfo = new Focas1.ODBST(); + short nReturn; + + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.IsError()) + return cmsError; + + // Get path index + short path = GetHandleIndexFromPath(Number); + if (path < 0) + return PROC_NOT_FOUND_ERROR; + + //Execute the method + nReturn = Focas1.cnc_statinfo(nLibHandle[path], StatInfo); + + //Throw Exception if there's an error + if (nReturn != 0) + return GetNcError(nReturn); + + Status = ConverToSTEPStatus(StatInfo); + + return NO_ERROR; + } + + //Get the process Mode + public override CmsError PROC_RMode(ushort Number, ref PROC_MODE Mode) + { + Focas1.ODBST StatInfo = new Focas1.ODBST(); + short nReturn = 0; + + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.IsError()) + return cmsError; + + // Get path index + short path = GetHandleIndexFromPath(Number); + if (path < 0) + return PROC_NOT_FOUND_ERROR; + + //Execute the method + nReturn = Focas1.cnc_statinfo(nLibHandle[path], StatInfo); + + //Throw Exception if there's an error + if (nReturn != 0) + return GetNcError(nReturn); + + Mode = ConverToSTEPMode(StatInfo); + + return NO_ERROR; + } + + #endregion PROCESS (PATH) High-level data + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + #region PROCESS-AXES (PATH) High-level data //Get the Inrpolated position public override CmsError AXES_RInterpPosition(ushort ProcNumber, ref Dictionary Axes) @@ -612,7 +596,7 @@ namespace CMS_CORE.Fanuc //Execute the method nReturn = Focas1.cnc_rdposition(nLibHandle[path], FANUC_RELATIVEPOS, ref NumAxes, axisFan); - //Throw Exception if there's an error + //Throw Exception if there's an error if (nReturn != 0) return GetNcError(nReturn); @@ -665,8 +649,6 @@ namespace CMS_CORE.Fanuc return NO_ERROR; } - - //Get the Machine position public override CmsError AXES_RMachinePosition(ushort ProcNumber, ref Dictionary Axes) { @@ -688,7 +670,7 @@ namespace CMS_CORE.Fanuc //Execute the method nReturn = Focas1.cnc_rdposition(nLibHandle[path], FANUC_MACHINEPOS, ref NumAxes, axisFan); - //Throw Exception if there's an error + //Throw Exception if there's an error if (nReturn != 0) return GetNcError(nReturn); @@ -740,8 +722,6 @@ namespace CMS_CORE.Fanuc return NO_ERROR; } - - //Get the Distance To Go public override CmsError AXES_RDistanceToGo(ushort ProcNumber, ref Dictionary Axes) { @@ -763,7 +743,7 @@ namespace CMS_CORE.Fanuc //Execute the method nReturn = Focas1.cnc_rdposition(nLibHandle[GetHandleIndexFromPath(ProcNumber)], FANUC_DISTTOGO, ref NumAxes, axisFan); - //Throw Exception if there's an error + //Throw Exception if there's an error if (nReturn != 0) return GetNcError(nReturn); @@ -816,8 +796,6 @@ namespace CMS_CORE.Fanuc return NO_ERROR; } - - //Get the Programmed Position public override CmsError AXES_RProgrPosition(ushort ProcNumber, ref Dictionary Axes) { @@ -864,167 +842,14 @@ namespace CMS_CORE.Fanuc return FUNCTION_NOT_ALLOWED_ERROR; } - - - #endregion + #endregion PROCESS-AXES (PATH) High-level data /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - #region Low level methods - - //-------------------------------------------------------------------------------------------------------------------------- - // PARAMS - - //Get NC Bit Parameter - public override CmsError NC_RParam(short Index, short Bit, ref Boolean Value) - { - //Check if the NC is Connected - CmsError cmsError = CheckConnection(); - if (cmsError.IsError()) - return cmsError; - - Focas1.IODBPSD_1 outpar = new Focas1.IODBPSD_1(); - short nReturn; - short axes_num = 0; - short size = 5; - byte mask = (byte)Math.Pow(2, Bit); - - - //Check if the Bit Number is Correct - cmsError = CheckBitRange(Bit); - if (cmsError.IsError()) - return cmsError; - - //Execute the method - nReturn = Focas1.cnc_rdparam(nLibHandle[0], Index, axes_num, size, outpar); - - //Throw Exception if there's an error - if (nReturn != 0) - return GetNcError(nReturn); - - Value = ((outpar.cdata & mask) == mask) ? true : false; - - return NO_ERROR; - } - - - - //Get NC Byte Parameter - public override CmsError NC_RParam(short Index, ref byte Value) - { - //Check if the NC is Connected - CmsError cmsError = CheckConnection(); - if (cmsError.IsError()) - return cmsError; - - Focas1.IODBPSD_1 outpar = new Focas1.IODBPSD_1(); - short nReturn; - short axes_num = 0; - short size = 5; - - //Execute the method - nReturn = Focas1.cnc_rdparam(nLibHandle[0], Index, axes_num, size, outpar); - - //Throw Exception if there's an error - if (nReturn != 0) - return GetNcError(nReturn); - - Value = outpar.cdata; - - return NO_ERROR; - } - - - - //Get NC Word Parameter - public override CmsError NC_RParam(short Index, ref short Value) - { - //Check if the NC is Connected - CmsError cmsError = CheckConnection(); - if (cmsError.IsError()) - return cmsError; - - Focas1.IODBPSD_1 outpar = new Focas1.IODBPSD_1(); - short nReturn; - short axes_num = 0; - short size = 6; - - //Execute the method - nReturn = Focas1.cnc_rdparam(nLibHandle[0], Index, axes_num, size, outpar); - - //Throw Exception if there's an error - if (nReturn != 0) - return GetNcError(nReturn); - - Value = outpar.idata; - - return NO_ERROR; - } - - - - //Get NC DWord Parameter - public override CmsError NC_RParam(short Index, ref int Value) - { - //Check if the NC is Connected - CmsError cmsError = CheckConnection(); - if (cmsError.IsError()) - return cmsError; - - Focas1.IODBPSD_1 outpar = new Focas1.IODBPSD_1(); - short nReturn; - short axes_num = 0; - short size = 8; - - //Execute the method - nReturn = Focas1.cnc_rdparam(nLibHandle[0], Index, axes_num, size, outpar); - - //Throw Exception if there's an error - if (nReturn != 0) - return GetNcError(nReturn); - - Value = outpar.ldata; - - return NO_ERROR; - } - - - - //Get NC Real Parameter - public override CmsError NC_RParam(short Index, ref double Value) - { - //Check if the NC is Connected - CmsError cmsError = CheckConnection(); - if (cmsError.IsError()) - return cmsError; - - Focas1.IODBPSD_2 outpar = new Focas1.IODBPSD_2(); - short nReturn; - short axes_num = 0; - short size = 12; - double Divider = 1; - - //Execute the method - nReturn = Focas1.cnc_rdparam(nLibHandle[0], Index, axes_num, size, outpar); - - //Throw Exception if there's an error - if (nReturn != 0) - return GetNcError(nReturn); - - Divider = Math.Pow(10, outpar.rdata.dec_val); - - Value = outpar.rdata.prm_val / Divider; - - return NO_ERROR; - } - - - - //-------------------------------------------------------------------------------------------------------------------------- - // BOOL (NC) <-> BOOL (.NET) ToDo + #region NC Low-level function: single valiable in memory //Read-Write a Boolean-Value inside the NC. - public override CmsError MEM_RWBoolean(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, int MemBit, ref bool Value) + public override CmsError MEM_RWBoolean(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int MemBit, ref bool Value) { //Check if the Bit Number is Correct CmsError cmsError = CheckBitRange(MemBit); @@ -1051,19 +876,16 @@ namespace CMS_CORE.Fanuc else ReadValue = (byte)(ReadValue & ~(1 << MemBit)); - MEM_RWByte(W, Process, MemType, MemIndex, 0, ref ReadValue); + cmsError = MEM_RWByte(W, Process, MemType, MemIndex, 0, ref ReadValue); + if (cmsError.IsError()) + return cmsError; } return NO_ERROR; } - - - //-------------------------------------------------------------------------------------------------------------------------- - // BYTE (NC) <-> BYTE (.NET) - //Read-Write a Byte-Value inside the NC. In writing-mode the field "Number" is not required - public override CmsError MEM_RWByte(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, int MemByte, ref byte Value) + public override CmsError MEM_RWByte(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int MemByte, ref byte Value) { List Values = new List() { Value }; @@ -1077,10 +899,131 @@ namespace CMS_CORE.Fanuc return NO_ERROR; } + //Write a Int-Value inside the NC. In writing-mode the field "Number" is not required + public override CmsError MEM_RWInteger(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, ref int Value) + { + List ListValue = new List() { Value }; + //uses the List method with one-element list + CmsError cmsError = MEM_RWIntegerList(bWrite, Process, MemType, MemIndex, 1, ref ListValue); + if (cmsError.IsError()) + return cmsError; + + Value = ListValue.First(); + + return NO_ERROR; + } + + public override CmsError MEM_RWDWord(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, ref uint Value) + { + List ListValue = new List() { Value }; + + //uses the List method with one-element list + CmsError cmsError = MEM_RWDWordList(bWrite, Process, MemType, MemIndex, 1, ref ListValue); + if (cmsError.IsError()) + return cmsError; + + Value = ListValue.First(); + + return NO_ERROR; + } + + //Write a Short-Value inside the NC. In writing-mode the field "Number" is not required + public override CmsError MEM_RWShort(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, ref short Value) + { + List ListValue = new List() { Value }; + + //uses the List method with one-element list + CmsError cmsError = MEM_RWShortList(bWrite, Process, MemType, MemIndex, 1, ref ListValue); + if (cmsError.IsError()) + return cmsError; + + Value = ListValue.First(); + + return NO_ERROR; + } + + //Write a Word-Value inside the NC. In writing-mode the field "Number" is not required + public override CmsError MEM_RWWord(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, ref ushort Value) + { + List ListValue = new List() { Value }; + + //uses the List method with one-element list + CmsError cmsError = MEM_RWWordList(bWrite, Process, MemType, MemIndex, 1, ref ListValue); + if (cmsError.IsError()) + return cmsError; + + Value = ListValue.First(); + + return NO_ERROR; + } + + //-------------------------------------------------------------------------------------------------------------------------- + // Siemens Version of Memory-Access Methods + + public override CmsError MEM_RWBoolean(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int MemBit, ref bool Value) + { + return MEM_RWBoolean(bWrite, Process, MemType, MemIndex, MemBit, ref Value); + } + + public override CmsError MEM_RWByte(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int MemByte, ref byte Value) + { + return MEM_RWByte(bWrite, Process, MemType, MemIndex, MemByte, ref Value); + } + + public override CmsError MEM_RWWord(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, ref ushort Value) + { + return MEM_RWWord(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); + } + + public override CmsError MEM_RWShort(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, ref short Value) + { + return MEM_RWShort(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); + } + + public override CmsError MEM_RWDWord(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, ref uint Value) + { + return MEM_RWDWord(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); + } + + public override CmsError MEM_RWInteger(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, ref int Value) + { + return MEM_RWInteger(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); + } + + public override CmsError MEM_RWByteList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int MemByteStart, int Number, ref List Value) + { + return MEM_RWByteList(bWrite, Process, MemType, MemIndex, MemByteStart, Number, ref Value); + } + + public override CmsError MEM_RWWordList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int Number, ref List Value) + { + return MEM_RWWordList(bWrite, Process, MemType, MemIndex, Number, ref Value); + } + + public override CmsError MEM_RWShortList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int Number, ref List Value) + { + return MEM_RWShortList(bWrite, Process, MemType, MemIndex, Number, ref Value); + } + + public override CmsError MEM_RWDWordList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int Number, ref List Value) + { + return MEM_RWDWordList(bWrite, Process, MemType, MemIndex, Number, ref Value); + } + + public override CmsError MEM_RWIntegerList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int Number, ref List Value) + { + return MEM_RWIntegerList(bWrite, Process, MemType, MemIndex, Number, ref Value); + } + + #endregion NC Low-level function: single valiable in memory + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + #region NC Low-level function: variables List in memory //Read-Write a Byte-Value-List inside the NC. In writing-mode the field "Number" is not required - public override CmsError MEM_RWByteList(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, int MemByteStart, int Number, ref List Value) + public override CmsError MEM_RWByteList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int MemByteStart, int Number, ref List Value) { //Check if the NC is Connected CmsError cmsError = CheckConnection(); @@ -1106,17 +1049,16 @@ namespace CMS_CORE.Fanuc int j = 0; int k = 0; - //Setup the 'Value' variable + //Setup the 'Value' variable if (bWrite) Number = Value.Count(); else Value.Clear(); - //Setup the iterations + //Setup the iterations LastNumber = (Number % FANUC_MAXNVAR); Iterat = Number / FANUC_MAXNVAR; - //Iterates for (int i = 0; i <= Iterat; i++) { @@ -1153,7 +1095,7 @@ namespace CMS_CORE.Fanuc else nReturn = Focas1.pmc_wrpmcrng(nLibHandle[0], (ushort)FanucNumber, Io); - //Throw Exception if there's an error + //Throw Exception if there's an error if (nReturn != 0) return GetNcError(nReturn); @@ -1163,32 +1105,10 @@ namespace CMS_CORE.Fanuc } return NO_ERROR; - } - - - //-------------------------------------------------------------------------------------------------------------------------- - // DWORD (NC) <-> INT (.NET) - - //Write a Int-Value inside the NC. In writing-mode the field "Number" is not required - public override CmsError MEM_RWInteger(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, ref int Value) - { - List ListValue = new List() { Value }; - - //uses the List method with one-element list - CmsError cmsError = MEM_RWIntegerList(bWrite, Process, MemType, MemIndex, 1, ref ListValue); - if (cmsError.IsError()) - return cmsError; - - Value = ListValue.First(); - - return NO_ERROR; - } - - //Write a Int-Value-List inside the NC. In writing-mode the field "Number" is not required - public override CmsError MEM_RWIntegerList(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, int Number, ref List Value) + public override CmsError MEM_RWIntegerList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int Number, ref List Value) { //The maximum number of variables readed/writed at the same time is 5 //I have to iterate it @@ -1214,17 +1134,16 @@ namespace CMS_CORE.Fanuc if (cmsError.IsError()) return cmsError; - //Setup the 'Value' variable + //Setup the 'Value' variable if (bWrite) Number = Value.Count(); else Value.Clear(); - //Setup the iterations + //Setup the iterations LastNumber = (Number % FANUC_MAXNVAR); Iterat = Number / FANUC_MAXNVAR; - //Iterates for (int i = 0; i <= Iterat; i++) { @@ -1237,7 +1156,6 @@ namespace CMS_CORE.Fanuc else ActualEndIndex = ActualStartIndex + (FANUC_MAXNVAR * 4) - 1; - //Set the variables-numbers to iterate ActualNumber = (ActualEndIndex - ActualStartIndex + 1) / 4; //Set the variables-number Fanuc @@ -1262,7 +1180,7 @@ namespace CMS_CORE.Fanuc else nReturn = Focas1.pmc_wrpmcrng(nLibHandle[0], (ushort)FanucNumber, Io); - //Throw Exception if there's an error + //Throw Exception if there's an error if (nReturn != 0) return GetNcError(nReturn); @@ -1274,34 +1192,12 @@ namespace CMS_CORE.Fanuc return NO_ERROR; } - - - //-------------------------------------------------------------------------------------------------------------------------- - // DWORD (NC) <-> UINT (.NET) - - //Write a DWord-Value inside the NC. In writing-mode the field "Number" is not required - public override CmsError MEM_RWDWord(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, ref uint Value) - { - List ListValue = new List() { Value }; - - //uses the List method with one-element list - CmsError cmsError = MEM_RWDWordList(bWrite, Process, MemType, MemIndex, 1, ref ListValue); - if (cmsError.IsError()) - return cmsError; - - Value = ListValue.First(); - - return NO_ERROR; - } - - - //Write a DWord-Value-List inside the NC. In writing-mode the field "Number" is not required - public override CmsError MEM_RWDWordList(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, int Number, ref List Values) + public override CmsError MEM_RWDWordList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int Number, ref List Values) { List WordValues = new List(); - //If i have to write convert the INT list into (2x) WORD + //If i have to write convert the INT list into (2x) WORD if (bWrite) WordValues = Values.Select(i => (int)i).ToList(); @@ -1317,30 +1213,8 @@ namespace CMS_CORE.Fanuc return NO_ERROR; } - - - //-------------------------------------------------------------------------------------------------------------------------- - // WORD (NC) <-> SHORT (.NET) - - //Write a Short-Value inside the NC. In writing-mode the field "Number" is not required - public override CmsError MEM_RWShort(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, ref short Value) - { - List ListValue = new List() { Value }; - - //uses the List method with one-element list - CmsError cmsError = MEM_RWShortList(bWrite, Process, MemType, MemIndex, 1, ref ListValue); - if (cmsError.IsError()) - return cmsError; - - Value = ListValue.First(); - - return NO_ERROR; - } - - - //Write a Short-Value-List inside the NC. In writing-mode the field "Number" is not required - public override CmsError MEM_RWShortList(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, int Number, ref List Value) + public override CmsError MEM_RWShortList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int Number, ref List Value) { //Check if the NC is Connected CmsError cmsError = CheckConnection(); @@ -1366,17 +1240,16 @@ namespace CMS_CORE.Fanuc int j = 0; int k = 0; - //Setup the 'Value' variable + //Setup the 'Value' variable if (bWrite) Number = Value.Count(); else Value.Clear(); - //Setup the iterations + //Setup the iterations LastNumber = (Number % FANUC_MAXNVAR); Iterat = Number / FANUC_MAXNVAR; - //Iterates for (int i = 0; i <= Iterat; i++) { @@ -1389,7 +1262,6 @@ namespace CMS_CORE.Fanuc else ActualEndIndex = ActualStartIndex + (FANUC_MAXNVAR * 2) - 1; - //Set the variables-numbers to iterate ActualNumber = (ActualEndIndex - ActualStartIndex + 1) / 2; //Set the variables-number Fanuc @@ -1414,7 +1286,7 @@ namespace CMS_CORE.Fanuc else nReturn = Focas1.pmc_wrpmcrng(nLibHandle[0], (ushort)FanucNumber, Io); - //Throw Exception if there's an error + //Throw Exception if there's an error if (nReturn != 0) return GetNcError(nReturn); @@ -1426,34 +1298,12 @@ namespace CMS_CORE.Fanuc return NO_ERROR; } - - - //-------------------------------------------------------------------------------------------------------------------------- - // WORD (NC) <-> SHORT (.NET) - - //Write a Word-Value inside the NC. In writing-mode the field "Number" is not required - public override CmsError MEM_RWWord(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, ref ushort Value) - { - List ListValue = new List() { Value }; - - //uses the List method with one-element list - CmsError cmsError = MEM_RWWordList(bWrite, Process, MemType, MemIndex, 1, ref ListValue); - if (cmsError.IsError()) - return cmsError; - - Value = ListValue.First(); - - return NO_ERROR; - } - - - //Write a Word-Value-List inside the NC. In writing-mode the field "Number" is not required - public override CmsError MEM_RWWordList(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, int Number, ref List Values) + public override CmsError MEM_RWWordList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int Number, ref List Values) { List WordValues = new List(); - //If i have to write convert the INT list into (2x) WORD + //If i have to write convert the INT list into (2x) WORD if (bWrite) WordValues = Values.Select(i => (short)i).ToList(); @@ -1469,70 +1319,150 @@ namespace CMS_CORE.Fanuc return NO_ERROR; } - - - //-------------------------------------------------------------------------------------------------------------------------- - // Siemens Version of Memory-Access Methods - - public override CmsError MEM_RWBoolean(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, int MemBit, ref bool Value) - { - return MEM_RWBoolean(bWrite, Process, MemType, MemIndex, MemBit, ref Value); - } - public override CmsError MEM_RWByte(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, int MemByte, ref byte Value) - { - return MEM_RWByte(bWrite, Process, MemType, MemIndex, MemByte, ref Value); - } - - public override CmsError MEM_RWWord(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, ref ushort Value) - { - return MEM_RWWord(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); - } - - public override CmsError MEM_RWShort(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, ref short Value) - { - return MEM_RWShort(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); - } - - public override CmsError MEM_RWDWord(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, ref uint Value) - { - return MEM_RWDWord(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); - } - - public override CmsError MEM_RWInteger(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, ref int Value) - { - return MEM_RWInteger(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); - } - - public override CmsError MEM_RWByteList(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, int MemByteStart, int Number, ref List Value) - { - return MEM_RWByteList(bWrite, Process, MemType, MemIndex, MemByteStart, Number, ref Value); - } - - public override CmsError MEM_RWWordList(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, int Number, ref List Value) - { - return MEM_RWWordList(bWrite, Process, MemType, MemIndex, Number, ref Value); - } - - public override CmsError MEM_RWShortList(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, int Number, ref List Value) - { - return MEM_RWShortList(bWrite, Process, MemType, MemIndex, Number, ref Value); - } - - public override CmsError MEM_RWDWordList(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, int Number, ref List Value) - { - return MEM_RWDWordList(bWrite, Process, MemType, MemIndex, Number, ref Value); - } - - public override CmsError MEM_RWIntegerList(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, int Number, ref List Value) - { - return MEM_RWIntegerList(bWrite, Process, MemType, MemIndex, Number, ref Value); - } - - - - #endregion + #endregion NC Low-level function: variables List in memory /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + #region NC Low-level function: Parameters + + //Get NC Bit Parameter + public override CmsError NC_RParam(short Index, short Bit, ref Boolean Value) + { + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.IsError()) + return cmsError; + + Focas1.IODBPSD_1 outpar = new Focas1.IODBPSD_1(); + short nReturn; + short axes_num = 0; + short size = 5; + byte mask = (byte)Math.Pow(2, Bit); + + //Check if the Bit Number is Correct + cmsError = CheckBitRange(Bit); + if (cmsError.IsError()) + return cmsError; + + //Execute the method + nReturn = Focas1.cnc_rdparam(nLibHandle[0], Index, axes_num, size, outpar); + + //Throw Exception if there's an error + if (nReturn != 0) + return GetNcError(nReturn); + + Value = ((outpar.cdata & mask) == mask) ? true : false; + + return NO_ERROR; + } + + //Get NC Byte Parameter + public override CmsError NC_RParam(short Index, ref byte Value) + { + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.IsError()) + return cmsError; + + Focas1.IODBPSD_1 outpar = new Focas1.IODBPSD_1(); + short nReturn; + short axes_num = 0; + short size = 5; + + //Execute the method + nReturn = Focas1.cnc_rdparam(nLibHandle[0], Index, axes_num, size, outpar); + + //Throw Exception if there's an error + if (nReturn != 0) + return GetNcError(nReturn); + + Value = outpar.cdata; + + return NO_ERROR; + } + + //Get NC Word Parameter + public override CmsError NC_RParam(short Index, ref short Value) + { + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.IsError()) + return cmsError; + + Focas1.IODBPSD_1 outpar = new Focas1.IODBPSD_1(); + short nReturn; + short axes_num = 0; + short size = 6; + + //Execute the method + nReturn = Focas1.cnc_rdparam(nLibHandle[0], Index, axes_num, size, outpar); + + //Throw Exception if there's an error + if (nReturn != 0) + return GetNcError(nReturn); + + Value = outpar.idata; + + return NO_ERROR; + } + + //Get NC DWord Parameter + public override CmsError NC_RParam(short Index, ref int Value) + { + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.IsError()) + return cmsError; + + Focas1.IODBPSD_1 outpar = new Focas1.IODBPSD_1(); + short nReturn; + short axes_num = 0; + short size = 8; + + //Execute the method + nReturn = Focas1.cnc_rdparam(nLibHandle[0], Index, axes_num, size, outpar); + + //Throw Exception if there's an error + if (nReturn != 0) + return GetNcError(nReturn); + + Value = outpar.ldata; + + return NO_ERROR; + } + + //Get NC Real Parameter + public override CmsError NC_RParam(short Index, ref double Value) + { + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.IsError()) + return cmsError; + + Focas1.IODBPSD_2 outpar = new Focas1.IODBPSD_2(); + short nReturn; + short axes_num = 0; + short size = 12; + double Divider = 1; + + //Execute the method + nReturn = Focas1.cnc_rdparam(nLibHandle[0], Index, axes_num, size, outpar); + + //Throw Exception if there's an error + if (nReturn != 0) + return GetNcError(nReturn); + + Divider = Math.Pow(10, outpar.rdata.dec_val); + + Value = outpar.rdata.prm_val / Divider; + + return NO_ERROR; + } + + #endregion NC Low-level function: Parameters + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region File Management public override CmsError FILES_RProgramToFile(string partProgramPath, FileStream localFile) @@ -1557,8 +1487,6 @@ namespace CMS_CORE.Fanuc return NO_ERROR; } - - public override CmsError FILES_WProgramFromFile(string partProgramPath, FileStream localFile) { string partProgramContent = ""; @@ -1576,7 +1504,6 @@ namespace CMS_CORE.Fanuc return WritePartProgramContent(partProgramPath, partProgramContent); } - public override CmsError FILES_CopyProgram(string partProgramPath, string newPartProgramPath, bool failIfExist) { //Check if the NC is Connected @@ -1595,7 +1522,7 @@ namespace CMS_CORE.Fanuc // Copy Nc part program to the new path nReturn = Focas1.cnc_pdf_copy(nLibHandle[0], partProgramPath, newPartProgramPath); - //Throw Exception if there's an error + //Throw Exception if there's an error ErrorHandler(nReturn); } else @@ -1604,7 +1531,7 @@ namespace CMS_CORE.Fanuc // Find a function to check if file exist, delete and copy. // Read and put file // TODO - // + // nReturn = Focas1.cnc_pdf_copy(nLibHandle[0], partProgramPath, newPartProgramPath); if (nReturn == 5) @@ -1645,9 +1572,11 @@ namespace CMS_CORE.Fanuc return NO_ERROR; } - #endregion + + #endregion File Management /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region Subordinate Private Functions private CmsError ErrorHandler(short exNum) @@ -1680,8 +1609,6 @@ namespace CMS_CORE.Fanuc } } - - //Convert to Step Language private CultureInfo ConvertToSTEPLanguage(byte language) { @@ -1711,10 +1638,8 @@ namespace CMS_CORE.Fanuc case 21: return new CultureInfo("fi"); default: return new CultureInfo("en"); } - } - //Manage the Status Process private PROC_STATUS ConverToSTEPStatus(Focas1.ODBST status) { @@ -1738,7 +1663,6 @@ namespace CMS_CORE.Fanuc return PROC_STATUS.ERROR; } - //Manage the Status Mode private PROC_MODE ConverToSTEPMode(Focas1.ODBST status) { @@ -1759,8 +1683,6 @@ namespace CMS_CORE.Fanuc return PROC_MODE.ERROR; } - - //Get the Right Process private short GetHandleIndexFromPath(ushort Path) { @@ -1776,8 +1698,6 @@ namespace CMS_CORE.Fanuc return (short)(Path - 1); } - - //Read Static Data private CmsError ReadStaticNCData() { @@ -1794,7 +1714,6 @@ namespace CMS_CORE.Fanuc //Read oly one time every 10 seconds if (DateTime.Now - Last_Static_Read > new TimeSpan(NC_MIN_SEC_READ_STATIC_DATA * TimeSpan.TicksPerSecond)) { - //Read Language from NC PARAM cmsError = NC_RParam((short)PARAM_LING_FANUC.Address, ref FanucLanguage); if (cmsError.IsError()) @@ -1804,7 +1723,7 @@ namespace CMS_CORE.Fanuc nReturn1 = Focas1.cnc_sysinfo(nLibHandle[0], node); nReturn2 = Focas1.cnc_rdcncid(nLibHandle[0], out SerialNumber); - //Throw Exception if there's an error + //Throw Exception if there's an error if (nReturn1 != 0) return GetNcError(nReturn1); else if (nReturn2 != 0 && nReturn2 != 1) @@ -1827,7 +1746,6 @@ namespace CMS_CORE.Fanuc return NO_ERROR; } - //Manage the Exception Launch private CmsError GetNcError(short exNum) { @@ -1840,8 +1758,6 @@ namespace CMS_CORE.Fanuc return CmsError.NcError(GetErrorMessage(exNum)); } - - //Check if NC is connected private CmsError CheckConnection() { @@ -1851,8 +1767,6 @@ namespace CMS_CORE.Fanuc return NO_ERROR; } - - //Check if Memory Area is corrected private CmsError CheckMemoryArea(String AreaName) { @@ -1862,8 +1776,6 @@ namespace CMS_CORE.Fanuc return NO_ERROR; } - - //Check if NC is connected private CmsError CheckBitRange(int bitnum) { @@ -1873,8 +1785,6 @@ namespace CMS_CORE.Fanuc return NO_ERROR; } - - // Convert the internal Name var in Readable STEP Name private String getName(char[] Cnc_Type, char[] Mt_Type) { @@ -1895,8 +1805,6 @@ namespace CMS_CORE.Fanuc return name; } - - // Write Part program content private CmsError WritePartProgramContent(string partProgramPath, string partProgramContent) { @@ -1910,7 +1818,7 @@ namespace CMS_CORE.Fanuc // Start write nReturn = Focas1.cnc_dwnstart4(nLibHandle[0], 0, partProgramPath); - //Throw Exception if there's an error + //Throw Exception if there's an error ErrorHandler(nReturn); //int lenghtMax = fileData.Length; @@ -1919,19 +1827,17 @@ namespace CMS_CORE.Fanuc // Write program nReturn = Focas1.cnc_download4(nLibHandle[0], ref lenght, partProgramContent); - //Throw Exception if there's an error + //Throw Exception if there's an error ErrorHandler(nReturn); nReturn = Focas1.cnc_dwnend4(nLibHandle[0]); - //Throw Exception if there's an error + //Throw Exception if there's an error ErrorHandler(nReturn); return NO_ERROR; } - - // Read Part program content private CmsError ReadPartProgramContent(string partProgramPath, ref string partProgramContent) { @@ -1947,7 +1853,7 @@ namespace CMS_CORE.Fanuc // Start read process nReturn = Focas1.cnc_upstart4(nLibHandle[0], 0, partProgramPath); - //Throw Exception if there's an error + //Throw Exception if there's an error ErrorHandler(nReturn); do @@ -1966,17 +1872,20 @@ namespace CMS_CORE.Fanuc fileEnded = true; } break; + case (short)Focas1.EW_OK: { // Add the characters into string with all the content partProgramContent += new string(tmpContentBuffer); } break; + case (short)Focas1.focas_ret.EW_BUFFER: { continue; } break; + default: { return GetNcError(nReturn); @@ -2046,9 +1955,6 @@ namespace CMS_CORE.Fanuc return ErrororOwner + "Generic Error On Function"; } - - - #endregion - + #endregion Subordinate Private Functions } } \ No newline at end of file diff --git a/CMS_CORE_Library/Nc.cs b/CMS_CORE_Library/Nc.cs index a3fa9c7..fb211fc 100644 --- a/CMS_CORE_Library/Nc.cs +++ b/CMS_CORE_Library/Nc.cs @@ -394,7 +394,7 @@ namespace CMS_CORE * * Reference to the structure where the power on data will be saved **/ - public abstract CmsError Nc_RPowerOnData(ref PreAndPostPowerOnModel powerOnModel); + public abstract CmsError PLC_RPowerOnData(ref PreAndPostPowerOnModel powerOnModel); /** * @@ -407,7 +407,30 @@ namespace CMS_CORE * Id of the edited power on data * New value of the power on data **/ - public abstract CmsError Nc_WPowerOnData(uint id, bool value); + public abstract CmsError PLC_WPowerOnData(uint id, bool value); + + /** + * + * Read the status of the functions of the UI + * + * Compatibility: Fanuc | Osai | Demo | Siemens + * + * Returns an error when an internal or a library error occours + * + **/ + public abstract CmsError PLC_RFunctionAccess(ref List functions); + + /** + * + * Read axes reset procedure data + * + * Compatibility: Fanuc | Osai | Demo | Siemens + * + * Returns an error when an internal or a library error occours + * Reference of the data of axes reset procedure + * + **/ + public abstract CmsError PLC_RAxesResetData(ref AxisResetDataModel axisResetData); #endregion @@ -494,7 +517,7 @@ namespace CMS_CORE * Reference to part program data structure * **/ - public abstract CmsError PROC_RStatus(ushort procNumber, ref ProcessData processData); + public abstract CmsError PROC_RStatusAndData(ushort procNumber, ref ProcessDataModel processData); #endregion /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -581,12 +604,12 @@ namespace CMS_CORE * Returns an error when an internal or a library error occours * Set True to Write-operation (Also Allowed /) * Process to perform operation (If the area is process-indipendent use 0 or ) - * Nc Memory Area. See + * Nc Memory Area. See * Starting Index of Memory Area * 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); + public abstract CmsError MEM_RWBoolean(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int MemBit, ref Boolean Value); /** * Read/Write Boolean variable from/into NC Memory Area (including Siemens Nc) @@ -597,13 +620,13 @@ namespace CMS_CORE * Returns an error when an internal or a library error occours * Set True to Write-operation (Also Allowed /) * Process to perform operation (If the area is process-indipendent use 0 or ) - * Nc Memory Area. See + * Nc Memory Area. See * Siemens Memory Table (Used only in Siemens-Nc) * Starting Index of Memory Area * 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); + public abstract CmsError MEM_RWBoolean(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int MemBit, ref Boolean Value); @@ -616,12 +639,12 @@ namespace CMS_CORE * Returns an error when an internal or a library error occours * Set True to Write-operation (Also Allowed /) * Process to perform operation (If the area is process-indipendent use 0 or ) - * Nc Memory Area. See + * Nc Memory Area. See * Starting Index of Memory Area * 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); + public abstract CmsError MEM_RWByte(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int MemByte, ref Byte Value); /** * Read/Write Byte variable from/into NC Memory Area (including Siemens Nc) @@ -632,13 +655,13 @@ namespace CMS_CORE * Returns an error when an internal or a library error occours * Set True to Write-operation (Also Allowed /) * Process to perform operation (If the area is process-indipendent use 0 or ) - * Nc Memory Area. See + * Nc Memory Area. See * Siemens Memory Table (Used only in Siemens-Nc) * Starting Index of Memory Area * 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); + public abstract CmsError MEM_RWByte(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int MemByte, ref Byte Value); @@ -651,12 +674,12 @@ namespace CMS_CORE * Returns an error when an internal or a library error occours * Set True to Write-operation (Also Allowed /) * Process to perform operation (If the area is process-indipendent use 0 or ) - * Nc Memory Area. See + * Nc Memory Area. See * Starting Index of Memory Area * 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); + public abstract CmsError MEM_RWWord(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, ref ushort Value); /** * Read/Write unsigned 2 Byte (NC: Word:, .NET: ushort) variable from/into NC Memory Area (including Siemens Nc) @@ -667,13 +690,13 @@ namespace CMS_CORE * Returns an error when an internal or a library error occours * Set True to Write-operation (Also Allowed /) * Process to perform operation (If the area is process-indipendent use 0 or ) - * Nc Memory Area. See + * Nc Memory Area. See * Siemens Memory Table (Used only in Siemens-Nc) * Starting Index of Memory Area * 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); + public abstract CmsError MEM_RWWord(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, ref ushort Value); @@ -686,12 +709,12 @@ namespace CMS_CORE * Returns an error when an internal or a library error occours * Set True to Write-operation (Also Allowed /) * Process to perform operation (If the area is process-indipendent use 0 or ) - * Nc Memory Area. See + * Nc Memory Area. See * Starting Index of Memory Area * 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); + public abstract CmsError MEM_RWShort(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, ref short Value); /** * Read/Write signed 2 Byte (NC: Word:, .NET: short) variable from/into NC Memory Area (including Siemens Nc) @@ -702,13 +725,13 @@ namespace CMS_CORE * Returns an error when an internal or a library error occours * Set True to Write-operation (Also Allowed /) * Process to perform operation (If the area is process-indipendent use 0 or ) - * Nc Memory Area. See + * Nc Memory Area. See * Siemens Memory Table (Used only in Siemens-Nc) * Starting Index of Memory Area * 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); + public abstract CmsError MEM_RWShort(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, ref short Value); @@ -721,12 +744,12 @@ namespace CMS_CORE * Returns an error when an internal or a library error occours * Set True to Write-operation (Also Allowed /) * Process to perform operation (If the area is process-indipendent use 0 or ) - * Nc Memory Area. See + * Nc Memory Area. See * Starting Index of Memory Area * 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); + public abstract CmsError MEM_RWDWord(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, ref uint Value); /** * Read/Write signed 4 Byte (NC: DWord:, .NET: uint) variable from/into NC Memory Area (including Siemens Nc) @@ -737,13 +760,13 @@ namespace CMS_CORE * Returns an error when an internal or a library error occours * Set True to Write-operation (Also Allowed /) * Process to perform operation (If the area is process-indipendent use 0 or ) - * Nc Memory Area. See + * Nc Memory Area. See * Siemens Memory Table (Used only in Siemens-Nc) * Starting Index of Memory Area * 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); + public abstract CmsError MEM_RWDWord(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, ref uint Value); @@ -756,12 +779,12 @@ namespace CMS_CORE * Returns an error when an internal or a library error occours * Set True to Write-operation (Also Allowed /) * Process to perform operation (If the area is process-indipendent use 0 or ) - * Nc Memory Area. See + * Nc Memory Area. See * Starting Index of Memory Area * 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); + public abstract CmsError MEM_RWInteger(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, ref int Value); /** * Read/Write signed 4 Byte (NC: DWord:, .NET: int) variable from/into NC Memory Area (including Siemens Nc) @@ -772,13 +795,13 @@ namespace CMS_CORE * Returns an error when an internal or a library error occours * Set True to Write-operation (Also Allowed /) * Process to perform operation (If the area is process-indipendent use 0 or ) - * Nc Memory Area. See + * Nc Memory Area. See * Siemens Memory Table (Used only in Siemens-Nc) * Starting Index of Memory Area * 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); + public abstract CmsError MEM_RWInteger(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, ref int Value); #endregion @@ -794,13 +817,13 @@ namespace CMS_CORE * Returns an error when an internal or a library error occours * Set True to Write-operation (Also Allowed /) * Process to perform operation (If the area is process-indipendent use 0 or ) - * Nc Memory Area. See + * Nc Memory Area. See * Starting Index of Memory Area * Set to 1 if the starting Byte is the second of a WORD (only for OSAI Nc) * 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); + public abstract CmsError MEM_RWByteList(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int MemByteStart, int Number, ref List Value); /** * Read/Write List of Byte from/into NC Memory Area (including Siemens Nc) @@ -811,14 +834,14 @@ namespace CMS_CORE * Returns an error when an internal or a library error occours * Set True to Write-operation (Also Allowed /) * Process to perform operation (If the area is process-indipendent use 0 or ) - * Nc Memory Area. See + * Nc Memory Area. See * Siemens Memory Table (Used only in Siemens-Nc) * Starting Index of Memory Area * Set to 1 if the starting Byte is the second of a WORD (only for OSAI Nc) * 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); + public abstract CmsError MEM_RWByteList(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int MemByteStart, int Number, ref List Value); @@ -831,12 +854,12 @@ namespace CMS_CORE * Returns an error when an internal or a library error occours * Set True to Write-operation (Also Allowed /) * Process to perform operation (If the area is process-indipendent use 0 or ) - * Nc Memory Area. See + * Nc Memory Area. See * Starting Index of Memory Area * 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); + public abstract CmsError MEM_RWWordList(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int Number, ref List Value); /** * Read/Write List of unsigned 2 Byte (NC: Word:, .NET: ushort) from/into NC Memory Area (including Siemens Nc) @@ -847,13 +870,13 @@ namespace CMS_CORE * Returns an error when an internal or a library error occours * Set True to Write-operation (Also Allowed /) * Process to perform operation (If the area is process-indipendent use 0 or ) - * Nc Memory Area. See + * Nc Memory Area. See * Siemens Memory Table (Used only in Siemens-Nc) * Starting Index of Memory Area * 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); + public abstract CmsError MEM_RWWordList(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int Number, ref List Value); @@ -866,13 +889,13 @@ namespace CMS_CORE * Returns an error when an internal or a library error occours * Set True to Write-operation (Also Allowed /) * Process to perform operation (If the area is process-indipendent use 0 or ) - * Nc Memory Area. See + * Nc Memory Area. See * Starting Index of Memory Area * 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 MemIndex, int Number, ref List Value); + 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) * @@ -882,13 +905,13 @@ namespace CMS_CORE * Returns an error when an internal or a library error occours * Set True to Write-operation (Also Allowed /) * Process to perform operation (If the area is process-indipendent use 0 or ) - * Nc Memory Area. See + * Nc Memory Area. See * Siemens Memory Table (Used only in Siemens-Nc) * Starting Index of Memory Area * 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); + public abstract CmsError MEM_RWShortList(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int Number, ref List Value); @@ -901,12 +924,12 @@ namespace CMS_CORE * Returns an error when an internal or a library error occours * Set True to Write-operation (Also Allowed /) * Process to perform operation (If the area is process-indipendent use 0 or ) - * Nc Memory Area. See + * Nc Memory Area. See * Starting Index of Memory Area * 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); + public abstract CmsError MEM_RWDWordList(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int Number, ref List Value); /** * Read/Write List of unsigned 4 Byte (NC: DWord:, .NET: uint) from/into NC Memory Area (including Siemens Nc) @@ -917,13 +940,13 @@ namespace CMS_CORE * Returns an error when an internal or a library error occours * Set True to Write-operation (Also Allowed /) * Process to perform operation (If the area is process-indipendent use 0 or ) - * Nc Memory Area. See + * Nc Memory Area. See * Siemens Memory Table (Used only in Siemens-Nc) * Starting Index of Memory Area * 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); + public abstract CmsError MEM_RWDWordList(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int Number, ref List Value); @@ -936,12 +959,12 @@ namespace CMS_CORE * Returns an error when an internal or a library error occours * Set True to Write-operation (Also Allowed /) * Process to perform operation (If the area is process-indipendent use 0 or Nc.) - * Nc Memory Area. See + * Nc Memory Area. See * Starting Index of Memory Area * 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); + public abstract CmsError MEM_RWIntegerList(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int Number, ref List Value); /** * Read/Write List of signed 4 Byte (NC: DWord:, .NET: int) from/into NC Memory Area (including Siemens Nc) @@ -952,13 +975,13 @@ namespace CMS_CORE * Returns an error when an internal or a library error occours * Set True to Write-operation (Also Allowed /) * Process to perform operation (If the area is process-indipendent use 0 or Nc.) - * Nc Memory Area. See + * Nc Memory Area. See * Siemens Memory Table (Used only in Siemens-Nc) * Starting Index of Memory Area * 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); + public abstract CmsError MEM_RWIntegerList(Boolean bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int Number, ref List Value); #endregion @@ -1079,7 +1102,7 @@ namespace CMS_CORE // R-W MEMORY Type /** Nc Memory Type (Table) */ - public enum MEMORY_Type + public enum MEMORY_TYPE { /** Null Type */ Null = -1, @@ -1204,30 +1227,38 @@ namespace CMS_CORE // R-W MEMORY Cell internal struct MEMORY_CELL { - public readonly MEMORY_Type MemType; + public readonly MEMORY_TYPE MemType; public readonly int Address; public readonly int SubAddress; //Only for Siemens public readonly int Size; - public MEMORY_CELL(MEMORY_Type MType, int Addr, int SubAddr, int Sz) + public MEMORY_CELL(MEMORY_TYPE MType, int Addr, int SubAddr, int Sz) { MemType = MType; Address = Addr; SubAddress = SubAddr; Size = Sz; } + + public MEMORY_CELL(MEMORY_TYPE MType, int Addr, int Sz) + { + MemType = MType; + Address = Addr; + SubAddress = 0; + Size = Sz; + } } //Lingua CN - internal MEMORY_CELL PARAM_LING_FANUC = new MEMORY_CELL(MEMORY_Type.Null, 3281, 0, 1); + internal MEMORY_CELL PARAM_LING_FANUC = new MEMORY_CELL(MEMORY_TYPE.Null, 3281, 0, 1); //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); + 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); + internal MEMORY_CELL PLC_MESS_OSAI = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 12000, 0, 64); #endregion @@ -1238,10 +1269,10 @@ namespace CMS_CORE { alarms.Add(new AlarmModel() { - id = id, - message = message, - isWarning = false, - process = 0 + Id = id, + Message = message, + IsWarning = false, + Process = 0 }); } @@ -1249,10 +1280,10 @@ namespace CMS_CORE { alarms.Add(new AlarmModel() { - id = id, - message = message, - isWarning = false, - process = process + Id = id, + Message = message, + IsWarning = false, + Process = process }); } #endregion diff --git a/CMS_CORE_Library/Osai/Nc_Osai.cs b/CMS_CORE_Library/Osai/Nc_Osai.cs index d4dc5e7..6ca22e2 100644 --- a/CMS_CORE_Library/Osai/Nc_Osai.cs +++ b/CMS_CORE_Library/Osai/Nc_Osai.cs @@ -1,18 +1,17 @@ using CMS_CORE.Exceptions; using CMS_CORE.Utils; +using CMS_CORE_Library.OPENControl; using CndexLinkDotNet; using System; using System.Collections; using System.Collections.Generic; +using System.ComponentModel; using System.Globalization; using System.IO; using System.Linq; using System.ServiceModel; using System.Text; -using CMS_CORE_Library.OPENControl; -using System.ComponentModel; using static CMS_CORE_Library.DataStructures; -using CMS_CORE_Library; namespace CMS_CORE.Osai { @@ -31,10 +30,10 @@ namespace CMS_CORE.Osai private ushort timeOutConn; private EndpointAddress endPointAddress; private BasicHttpBinding HttpBinding; - private static Dictionary PlcMessages; - + private static Dictionary PlcMessages; /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region Contructor & global methods /** @@ -45,6 +44,7 @@ namespace CMS_CORE.Osai * Remote Port of the Nc * Send/Recieve timeout connection [mS] * */ + public Nc_Osai(String IpAddress, ushort RemotePort, ushort ConnectionTimeOut) { //Set internal valiables @@ -65,19 +65,16 @@ namespace CMS_CORE.Osai } } - - //Connect Method public override CmsError NC_Connect() { - uint errorClass, errorNum; ushort nReturn; //Setup Binding setupConnection(); - //Setup the Url String and the Endpoint + //Setup the Url String and the Endpoint Url = "http://" + Ip + ":" + Port; endPointAddress = new EndpointAddress(new Uri(Url)); @@ -99,7 +96,6 @@ namespace CMS_CORE.Osai Connected = true; else Connected = false; - } catch (Exception ex) { @@ -109,8 +105,6 @@ namespace CMS_CORE.Osai return NO_ERROR; } - - //Disconnect Method public override CmsError NC_Disconnect() { @@ -121,11 +115,10 @@ namespace CMS_CORE.Osai return NO_ERROR; } - - - #endregion + #endregion Contructor & global methods /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region High-level Methods //Get the NC Language @@ -154,8 +147,6 @@ namespace CMS_CORE.Osai return NO_ERROR; } - - //Get the NC Software Version public override CmsError NC_RSoftwareVersion(ref string SWV) { @@ -182,8 +173,6 @@ namespace CMS_CORE.Osai return NO_ERROR; } - - //Get the NC Time public override CmsError NC_RDateTime(ref DateTime ActualTime) { @@ -208,7 +197,6 @@ namespace CMS_CORE.Osai //Setup the out value ActualTime = new DateTime(Year, Month, Day, Hour, Minute, Second); - } catch (Exception ex) { @@ -218,8 +206,6 @@ namespace CMS_CORE.Osai return NO_ERROR; } - - //Get the Machine Number public override CmsError NC_RMachineNumber(ref string MachNumber) { @@ -235,88 +221,6 @@ namespace CMS_CORE.Osai return NO_ERROR; } - public override CmsError Nc_RPowerOnData(ref PreAndPostPowerOnModel powerOnModel) - { - return NO_ERROR; - } - - public override CmsError Nc_WPowerOnData(uint id, bool value) - { - return NO_ERROR; - } - - // Check if the NC is in running state - public override CmsError NC_RIsRunning(ref bool running) - { - ushort nProcess = 0; - // Get the number of processes - CmsError cmsError = NC_RProcessesNum(ref nProcess); - if (cmsError.IsError()) - return cmsError; - - ushort i = 1; - running = false; - do - { - PROC_STATUS procStatus = PROC_STATUS.IDLE; - - // Read process status - cmsError = PROC_RStatus(i, ref procStatus); - if (cmsError.IsError()) - return cmsError; - // If one process is runninc, nc is running - if (procStatus == PROC_STATUS.RUN) - running = true; - i++; - } while (!running || i <= nProcess); - - - return NO_ERROR; - } - - //Get the PLC Active Alarms - public override CmsError PLC_RActiveMessages(ref List alarms) - { - List list = new List(); - BitArray Bits; - int index; - alarms.Clear(); - - //Execute the method - CmsError cmsError = MEM_RWWordList(R, 0, PLC_MESS_OSAI.MemType, PLC_MESS_OSAI.Address, PLC_MESS_OSAI.Size, ref list); - if (cmsError.IsError()) - return cmsError; - - //Elaborates the Messages - for (int i = 0; i < list.Count; i++) - { - if (list[i] != 0) - { - Bits = new BitArray(BitConverter.GetBytes(list[i])); - for (int j = 0; j < Bits.Count; j++) - { - index = (i * 16) + j + 1; - string message = ""; - // If bit == true - if (Bits[j]) - { - bool messageKeyFound = PlcMessages.TryGetValue(index, out message); - if (messageKeyFound && !string.IsNullOrWhiteSpace(message)) - AddAlarmToList((uint)index, message.Trim(), alarms); // Add message to list - else - AddAlarmToList((uint)index, "MSG not found, PLC error code : " + index, alarms); // Add message not found with error code - } - // Find key - - } - } - } - - return NO_ERROR; - } - - - //Get the processes-count configurated public override CmsError NC_RProcessesNum(ref ushort ProcNumber) { @@ -354,7 +258,6 @@ namespace CMS_CORE.Osai //update the output value ProcNumber = num; - } catch (Exception ex) { @@ -364,8 +267,6 @@ namespace CMS_CORE.Osai return NO_ERROR; } - - //Get the Nc Alarm public override CmsError NC_RActiveAlarms(ref List alarms) { @@ -396,7 +297,7 @@ namespace CMS_CORE.Osai { MESSAGE_TEXT MessageEmgy = new MESSAGE_TEXT(); Cndex.MSG_EMERGENCY CndexErrorEmgy = ConverToCndexMessage(errEmgy); - + //Translate using OSAI .DLL (a new one!) OSAIErrorManagerLibrary.TranslateEmergMsg(ref CndexErrorEmgy, ref MessageEmgy); @@ -412,6 +313,107 @@ namespace CMS_CORE.Osai return NO_ERROR; } + //Check if the NC is in running state + public override CmsError NC_RIsRunning(ref bool running) + { + ushort nProcess = 0; + // Get the number of processes + CmsError cmsError = NC_RProcessesNum(ref nProcess); + if (cmsError.IsError()) + return cmsError; + + ushort i = 1; + running = false; + do + { + PROC_STATUS procStatus = PROC_STATUS.IDLE; + + // Read process status + cmsError = PROC_RStatus(i, ref procStatus); + if (cmsError.IsError()) + return cmsError; + // If one process is runninc, nc is running + if (procStatus == PROC_STATUS.RUN) + running = true; + i++; + } while (!running || i <= nProcess); + + return NO_ERROR; + } + + #endregion High-level Methods + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + #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) + { + List list = new List(); + BitArray Bits; + int index; + alarms.Clear(); + + //Execute the method + CmsError cmsError = MEM_RWWordList(R, 0, PLC_MESS_OSAI.MemType, PLC_MESS_OSAI.Address, PLC_MESS_OSAI.Size, ref list); + if (cmsError.IsError()) + return cmsError; + + //Elaborates the Messages + for (int i = 0; i < list.Count; i++) + { + if (list[i] != 0) + { + Bits = new BitArray(BitConverter.GetBytes(list[i])); + for (int j = 0; j < Bits.Count; j++) + { + index = (i * 16) + j + 1; + string message = ""; + // If bit == true + if (Bits[j]) + { + bool messageKeyFound = PlcMessages.TryGetValue(index, out message); + if (messageKeyFound && !string.IsNullOrWhiteSpace(message)) + AddAlarmToList((uint)index, message.Trim(), alarms); // Add message to list + else + AddAlarmToList((uint)index, "MSG not found, PLC error code : " + index, alarms); // Add message not found with error code + } + // Find key + } + } + } + + return NO_ERROR; + } + + public override CmsError PLC_RFunctionAccess(ref List functions) + { + functions = new List(); + return NO_ERROR; + } + + public override CmsError PLC_RAxesResetData(ref AxisResetDataModel axisResetData) + { + return NO_ERROR; + } + + #endregion PLC High-level data + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + #region PROCESS (PATH) High-level data + //Get the process status public override CmsError PROC_RStatus(ushort Number, ref PROC_STATUS Status) { @@ -420,7 +422,6 @@ namespace CMS_CORE.Osai if (cmsError.IsError()) return cmsError; - uint errorClass, errorNum; ushort nReturn; PROCDATA status; @@ -445,8 +446,6 @@ namespace CMS_CORE.Osai return NO_ERROR; } - - //Get the process mode public override CmsError PROC_RMode(ushort Number, ref PROC_MODE Mode) { @@ -479,8 +478,6 @@ namespace CMS_CORE.Osai return NO_ERROR; } - - //Get the process Alarm public override CmsError PROC_RActiveAlarms(ushort procNumber, ref List alarms) { @@ -528,8 +525,6 @@ namespace CMS_CORE.Osai return NO_ERROR; } - - //Get PP Lines public override CmsError PROC_RPPLines(ushort ProcNumber, ref List Lines) { @@ -571,7 +566,6 @@ namespace CMS_CORE.Osai Lines.Add(L6); Lines.Add(L7); Lines.Add(L8); - } catch (Exception ex) { @@ -581,8 +575,6 @@ namespace CMS_CORE.Osai return NO_ERROR; } - - //Get Active PP Name public override CmsError PROC_RPPName(ushort ProcNumber, ref string Name) { @@ -609,7 +601,6 @@ namespace CMS_CORE.Osai //Build the new String Name = MainName; - } catch (Exception ex) { @@ -619,8 +610,8 @@ namespace CMS_CORE.Osai return NO_ERROR; } - // Get process part program data - public override CmsError PROC_RStatus(ushort procNumber, ref ProcessData processData) + //Get process part program data + public override CmsError PROC_RStatusAndData(ushort procNumber, ref ProcessDataModel processData) { //processData.Id = procNumber; //// Read part program name @@ -637,7 +628,7 @@ namespace CMS_CORE.Osai //byte[] bytes = BitConverter.GetBytes(readValue); //// Convert Byte into true/false array - //BitArray bits = new BitArray(new byte[] { bytes[0] }); //1st byte -> 0 : Proccess type (AUX-WORK), 1: Process in alarm status, 2: Run, 3: Hold, 4: Read, 5: PartProgramVisible + //BitArray bits = new BitArray(new byte[] { bytes[0] }); //1st byte -> 0 : Proccess type (AUX-WORK), 1: Process in alarm status, 2: Run, 3: Hold, 4: Read, 5: PartProgramVisible //// Populate response structure //processData.Type = bits[0] ? "WORK" : "AUX"; //processData.IsInAlarm = bits[1]; @@ -661,6 +652,12 @@ namespace CMS_CORE.Osai return NO_ERROR; } + #endregion PROCESS (PATH) High-level data + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + #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) { @@ -691,7 +688,6 @@ namespace CMS_CORE.Osai Axes.Clear(); } - //Fill all the List foreach (GETINTDATA ax in Pos) { @@ -705,7 +701,6 @@ namespace CMS_CORE.Osai Axes.Add(AxName, ax.position); } } - } catch (Exception ex) { @@ -715,8 +710,6 @@ namespace CMS_CORE.Osai return NO_ERROR; } - - //Get a dictionary with the Programmed position of the axes in Process public override CmsError AXES_RProgrPosition(ushort Process, ref Dictionary Axes) { @@ -760,7 +753,6 @@ namespace CMS_CORE.Osai Axes.Add(AxName, ax.position); } } - } catch (Exception ex) { @@ -770,8 +762,6 @@ namespace CMS_CORE.Osai return NO_ERROR; } - - //Get a dictionary with the Machine position of the axes in Process public override CmsError AXES_RMachinePosition(ushort Process, ref Dictionary Axes) { @@ -815,7 +805,6 @@ namespace CMS_CORE.Osai Axes.Add(AxName, ax.position); } } - } catch (Exception ex) { @@ -825,8 +814,6 @@ namespace CMS_CORE.Osai return NO_ERROR; } - - //Get a dictionary with the Following Error of the axes in Process public override CmsError AXES_RFollowingError(ushort Process, ref Dictionary Axes) { @@ -870,7 +857,6 @@ namespace CMS_CORE.Osai Axes.Add(AxName, ax.position); } } - } catch (Exception ex) { @@ -880,8 +866,6 @@ namespace CMS_CORE.Osai return NO_ERROR; } - - //Get a dictionary with the Distance To Go of the axes in Process public override CmsError AXES_RDistanceToGo(ushort Process, ref Dictionary Axes) { @@ -925,7 +909,6 @@ namespace CMS_CORE.Osai Axes.Add(AxName, ax.position); } } - } catch (Exception ex) { @@ -935,23 +918,18 @@ namespace CMS_CORE.Osai return NO_ERROR; } - - - #endregion + #endregion PROCESS-AXES (PATH) High-level data /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - #region Low-level Methods - //-------------------------------------------------------------------------------------------------------------------------- - // BOOLEAN (NC) <-> BOOLEAN (.NET) + #region NC Low-level function: variables List in memory - //Read-Write a Boolean-Value inside the NC. - public override CmsError MEM_RWBoolean(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, int MemBit, ref bool Value) + public override CmsError MEM_RWBoolean(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int MemBit, ref bool Value) { ushort WordValue = 0; byte pow = (byte)Math.Pow(2, MemBit); - //Read the Byte where is the bit + //Read the Byte where is the bit CmsError cmsError = MEM_RWWord(R, Process, MemType, MemIndex, ref WordValue); if (cmsError.IsError()) return cmsError; @@ -977,18 +955,12 @@ namespace CMS_CORE.Osai return NO_ERROR; } - - - //-------------------------------------------------------------------------------------------------------------------------- - // BYTE (NC) <-> BYTE (.NET) ToDo - - //Read-Write a Byte-Value inside the NC. In writing-mode the field "Number" is not required - public override CmsError MEM_RWByte(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, int MemByte, ref byte Value) + public override CmsError MEM_RWByte(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int MemByte, ref byte Value) { ushort WordValue = 0; ushort WordToWrite = 0; - //Read the Byte where is the bit + //Read the Byte where is the bit CmsError cmsError = MEM_RWWord(R, Process, MemType, MemIndex, ref WordValue); if (cmsError.IsError()) return cmsError; @@ -1026,10 +998,127 @@ namespace CMS_CORE.Osai return NO_ERROR; } + public override CmsError MEM_RWWord(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, ref ushort Value) + { + List ListValue = new List() { Value }; + //uses the List method with one-element list + CmsError cmsError = MEM_RWWordList(bWrite, Process, MemType, MemIndex, 1, ref ListValue); + if (cmsError.IsError()) + return cmsError; + + Value = ListValue.First(); + + return NO_ERROR; + } + + public override CmsError MEM_RWShort(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, ref short Value) + { + List ListValue = new List() { Value }; + + //uses the List method with one-element list + CmsError cmsError = MEM_RWShortList(bWrite, Process, MemType, MemIndex, 1, ref ListValue); + if (cmsError.IsError()) + return cmsError; + + Value = ListValue.First(); + + return NO_ERROR; + } + + //Write a Word-Value inside the NC. In writing-mode the field "Number" is not required + public override CmsError MEM_RWDWord(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, ref uint Value) + { + List ListValue = new List() { Value }; + + //uses the List method with one-element list + CmsError cmsError = MEM_RWDWordList(bWrite, Process, MemType, MemIndex, 1, ref ListValue); + if (cmsError.IsError()) + return cmsError; + + Value = ListValue.First(); + + return NO_ERROR; + } + + //Write a Int-Value inside the NC. In writing-mode the field "Number" is not required + public override CmsError MEM_RWInteger(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, ref int Value) + { + List ListValue = new List() { Value }; + + //uses the List method with one-element list + CmsError cmsError = MEM_RWIntegerList(bWrite, Process, MemType, MemIndex, 1, ref ListValue); + if (cmsError.IsError()) + return cmsError; + + Value = ListValue.First(); + + return NO_ERROR; + } + + public override CmsError MEM_RWBoolean(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int MemBit, ref bool Value) + { + return MEM_RWBoolean(bWrite, Process, MemType, MemIndex, MemBit, ref Value); + } + + public override CmsError MEM_RWByte(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int MemByte, ref byte Value) + { + return MEM_RWByte(bWrite, Process, MemType, MemIndex, MemByte, ref Value); + } + + public override CmsError MEM_RWWord(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, ref ushort Value) + { + return MEM_RWWord(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); + } + + public override CmsError MEM_RWShort(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, ref short Value) + { + return MEM_RWShort(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); + } + + public override CmsError MEM_RWDWord(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, ref uint Value) + { + return MEM_RWDWord(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); + } + + public override CmsError MEM_RWInteger(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, ref int Value) + { + return MEM_RWInteger(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); + } + + public override CmsError MEM_RWByteList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int MemByteStart, int Number, ref List Value) + { + return MEM_RWByteList(bWrite, Process, MemType, MemIndex, MemByteStart, Number, ref Value); + } + + public override CmsError MEM_RWWordList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int Number, ref List Value) + { + return MEM_RWWordList(bWrite, Process, MemType, MemIndex, Number, ref Value); + } + + public override CmsError MEM_RWShortList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int Number, ref List Value) + { + return MEM_RWShortList(bWrite, Process, MemType, MemIndex, Number, ref Value); + } + + public override CmsError MEM_RWDWordList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int Number, ref List Value) + { + return MEM_RWDWordList(bWrite, Process, MemType, MemIndex, Number, ref Value); + } + + public override CmsError MEM_RWIntegerList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int Number, ref List Value) + { + return MEM_RWIntegerList(bWrite, Process, MemType, MemIndex, Number, ref Value); + } + + #endregion NC Low-level function: variables List in memory + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + #region NC Low-level function: variables List in memory //Read-Write a Byte-Value-List inside the NC. In writing-mode the field "Number" is not required - public override CmsError MEM_RWByteList(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, int MemByteStart, int Number, ref List Values) + public override CmsError MEM_RWByteList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int MemByteStart, int Number, ref List Values) { int index = 0; byte TempVal = 0; @@ -1081,35 +1170,13 @@ namespace CMS_CORE.Osai MemIndexTemp++; } } - } return NO_ERROR; } - - - //-------------------------------------------------------------------------------------------------------------------------- - // WORD (NC) <-> USHORT (.NET) - - //Write a Word-Value inside the NC. In writing-mode the field "Number" is not required - public override CmsError MEM_RWWord(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, ref ushort Value) - { - List ListValue = new List() { Value }; - - //uses the List method with one-element list - CmsError cmsError = MEM_RWWordList(bWrite, Process, MemType, MemIndex, 1, ref ListValue); - if (cmsError.IsError()) - return cmsError; - - Value = ListValue.First(); - - return NO_ERROR; - } - - //Write a Word-Value-List inside the NC. In writing-mode the field "Number" is not required - public override CmsError MEM_RWWordList(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, int Number, ref List Values) + public override CmsError MEM_RWWordList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int Number, ref List Values) { //Check if the NC is Connected CmsError cmsError = CheckConnection(); @@ -1141,7 +1208,6 @@ namespace CMS_CORE.Osai //If there's an error if (errorClass != 0 || errorNum != 0 || nReturn == 0) return GetNCError(errorClass, errorNum); - } else { @@ -1154,7 +1220,6 @@ namespace CMS_CORE.Osai // Create the array with the Values Values = values.ToList(); - } } catch (Exception ex) @@ -1165,27 +1230,7 @@ namespace CMS_CORE.Osai return NO_ERROR; } - - - //-------------------------------------------------------------------------------------------------------------------------- - // WORD (NC) <-> SHORT (.NET) - - public override CmsError MEM_RWShort(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, ref short Value) - { - List ListValue = new List() { Value }; - - //uses the List method with one-element list - CmsError cmsError = MEM_RWShortList(bWrite, Process, MemType, MemIndex, 1, ref ListValue); - if (cmsError.IsError()) - return cmsError; - - Value = ListValue.First(); - - return NO_ERROR; - } - - - public override CmsError MEM_RWShortList(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, int Number, ref List Value) + public override CmsError MEM_RWShortList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int Number, ref List Value) { List ShortValue = Value.ConvertAll(x => (ushort)x); CmsError cmsError = MEM_RWWordList(bWrite, Process, MemType, MemIndex, 1, ref ShortValue); @@ -1195,34 +1240,12 @@ namespace CMS_CORE.Osai return NO_ERROR; } - - - //-------------------------------------------------------------------------------------------------------------------------- - // DWORD (NC) <-> UINT (.NET) - - - //Write a Word-Value inside the NC. In writing-mode the field "Number" is not required - public override CmsError MEM_RWDWord(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, ref uint Value) - { - List ListValue = new List() { Value }; - - //uses the List method with one-element list - CmsError cmsError = MEM_RWDWordList(bWrite, Process, MemType, MemIndex, 1, ref ListValue); - if (cmsError.IsError()) - return cmsError; - - Value = ListValue.First(); - - return NO_ERROR; - } - - //Write a Word-Value-List inside the NC. In writing-mode the field "Number" is not required - public override CmsError MEM_RWDWordList(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, int Number, ref List Values) + public override CmsError MEM_RWDWordList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int Number, ref List Values) { List WordValues = new List(); - //If i have to write convert the UINT list into (2x) WORD + //If i have to write convert the UINT list into (2x) WORD if (bWrite) WordValues = Nc_Utils.UIntTOWordList(Values); @@ -1238,35 +1261,12 @@ namespace CMS_CORE.Osai return NO_ERROR; } - - - //-------------------------------------------------------------------------------------------------------------------------- - // DWORD (NC) <-> INT (.NET) - - - //Write a Int-Value inside the NC. In writing-mode the field "Number" is not required - public override CmsError MEM_RWInteger(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, ref int Value) - { - - List ListValue = new List() { Value }; - - //uses the List method with one-element list - CmsError cmsError = MEM_RWIntegerList(bWrite, Process, MemType, MemIndex, 1, ref ListValue); - if (cmsError.IsError()) - return cmsError; - - Value = ListValue.First(); - - return NO_ERROR; - } - - //Write a Int-Value-List inside the NC. In writing-mode the field "Number" is not required - public override CmsError MEM_RWIntegerList(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, int Number, ref List Values) + public override CmsError MEM_RWIntegerList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int Number, ref List Values) { List WordValues = new List(); - //If i have to write convert the INT list into (2x) WORD + //If i have to write convert the INT list into (2x) WORD if (bWrite) WordValues = Nc_Utils.IntTOWordList(Values); @@ -1282,70 +1282,11 @@ namespace CMS_CORE.Osai return NO_ERROR; } + #endregion NC Low-level function: variables List in memory + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - //-------------------------------------------------------------------------------------------------------------------------- - // Siemens Version of Memory-Access Methods - - public override CmsError MEM_RWBoolean(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, int MemBit, ref bool Value) - { - return MEM_RWBoolean(bWrite, Process, MemType, MemIndex, MemBit, ref Value); - - } - public override CmsError MEM_RWByte(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, int MemByte, ref byte Value) - { - return MEM_RWByte(bWrite, Process, MemType, MemIndex, MemByte, ref Value); - } - - public override CmsError MEM_RWWord(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, ref ushort Value) - { - return MEM_RWWord(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); - } - - public override CmsError MEM_RWShort(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, ref short Value) - { - return MEM_RWShort(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); - } - - public override CmsError MEM_RWDWord(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, ref uint Value) - { - return MEM_RWDWord(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); - } - - public override CmsError MEM_RWInteger(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, ref int Value) - { - return MEM_RWInteger(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); - } - - public override CmsError MEM_RWByteList(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, int MemByteStart, int Number, ref List Value) - { - return MEM_RWByteList(bWrite, Process, MemType, MemIndex, MemByteStart, Number, ref Value); - } - - public override CmsError MEM_RWWordList(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, int Number, ref List Value) - { - return MEM_RWWordList(bWrite, Process, MemType, MemIndex, Number, ref Value); - } - - public override CmsError MEM_RWShortList(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, int Number, ref List Value) - { - return MEM_RWShortList(bWrite, Process, MemType, MemIndex, Number, ref Value); - } - - public override CmsError MEM_RWDWordList(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, int Number, ref List Value) - { - return MEM_RWDWordList(bWrite, Process, MemType, MemIndex, Number, ref Value); - } - - public override CmsError MEM_RWIntegerList(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, int Number, ref List Value) - { - return MEM_RWIntegerList(bWrite, Process, MemType, MemIndex, Number, ref Value); - } - - - - //-------------------------------------------------------------------------------------------------------------------------- - // PARAMS + #region NC Low-level function: Parameters public override CmsError NC_RParam(short Index, short Bit, ref bool Value) { @@ -1372,12 +1313,11 @@ namespace CMS_CORE.Osai return FUNCTION_NOT_ALLOWED_ERROR; } - - - #endregion + #endregion NC Low-level function: Parameters /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - #region File Management + + #region File Management public override CmsError FILES_RProgramToFile(string partProgramPath, FileStream localFile) { @@ -1495,7 +1435,6 @@ namespace CMS_CORE.Osai //If there's an error launch exception if (errorClass != 0 || errorNum != 0 || nReturn == 0) return GetNCError(errorClass, errorNum); - } catch (Exception ex) { @@ -1532,17 +1471,15 @@ namespace CMS_CORE.Osai return NO_ERROR; } - - #endregion + #endregion File Management /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - #region Subordinate Private Functions + #region Subordinate Private Functions //Setup the connection Binding private void setupConnection() { - HttpBinding = new BasicHttpBinding(BasicHttpSecurityMode.None); HttpBinding.Name = "OPENcontrol"; HttpBinding.CloseTimeout = TimeSpan.Parse("00:00:10"); @@ -1561,8 +1498,6 @@ namespace CMS_CORE.Osai HttpBinding.UseDefaultWebProxy = UseProxy; } - - //Check if NC is connected private CmsError CheckConnection() { @@ -1572,8 +1507,6 @@ namespace CMS_CORE.Osai return NO_ERROR; } - - //Check if Memory Area is corrected private CmsError CheckMemoryArea(String AreaName) { @@ -1583,12 +1516,9 @@ namespace CMS_CORE.Osai return NO_ERROR; } - - //Read Static Data private CmsError ReadStaticNCData() { - uint errorClass, errorNum; ushort nReturn; @@ -1609,7 +1539,6 @@ namespace CMS_CORE.Osai Cnc_name = "OSAI - Open Control"; Last_Static_Read = DateTime.Now; - } catch (Exception ex) { @@ -1620,8 +1549,6 @@ namespace CMS_CORE.Osai return NO_ERROR; } - - //Check Bit In Range private CmsError CheckBitRange(int bitnum) { @@ -1631,8 +1558,6 @@ namespace CMS_CORE.Osai return NO_ERROR; } - - //Check Byte In Range private CmsError CheckByteRange(int bytenum) { @@ -1642,8 +1567,6 @@ namespace CMS_CORE.Osai return NO_ERROR; } - - //Convert OSAI MESSAGE to STEP Message private String OsaiToStepMessage(MESSAGE_TEXT Message) { @@ -1658,8 +1581,6 @@ namespace CMS_CORE.Osai return ActMSG; } - - //Read Language Configuration private CmsError LanguageConfig() { @@ -1679,7 +1600,6 @@ namespace CMS_CORE.Osai if (String.IsNullOrEmpty(LangLine)) throw new Nc_Exception("'ID_LANGUAGE' Line in Osai Config File not Found"); - //Split the string SPlitted = LangLine.Split('='); if (SPlitted.Length != 2) @@ -1697,8 +1617,6 @@ namespace CMS_CORE.Osai } } - - //Read Plc Messages private CmsError ReadPlcMessages() { @@ -1720,7 +1638,6 @@ namespace CMS_CORE.Osai { return ManageException(ex); } - } //Manage the Languages @@ -1734,8 +1651,6 @@ namespace CMS_CORE.Osai return new CultureInfo("en"); } - - //Manage the Status Process private PROC_STATUS ConverToSTEPStatus(ushort status) { @@ -1755,8 +1670,6 @@ namespace CMS_CORE.Osai return PROC_STATUS.ERROR; } - - //Manage the Mode Process private PROC_MODE ConverToSTEPMode(ushort status) { @@ -1773,8 +1686,6 @@ namespace CMS_CORE.Osai return PROC_MODE.ERROR; } - - //Convert error from Open To Cndex private Cndex.MSG_ERROR ConverToCndexMessage(MSGERROR OpenError) { @@ -1791,8 +1702,6 @@ namespace CMS_CORE.Osai return OsaiSerie10Err; } - - //Convert error from Open To Cndex private Cndex.MSG_EMERGENCY ConverToCndexMessage(MSGEMERGENCY OpenError) { @@ -1888,7 +1797,6 @@ namespace CMS_CORE.Osai } return ErrorOwner + szErrorClassDesc + ": " + szErrorDesc + " (" + Class + "-" + Num + ")"; - case 3: szErrorClassDesc = "NETBIOS error class"; switch (Num) @@ -1933,7 +1841,6 @@ namespace CMS_CORE.Osai } return ErrorOwner + szErrorClassDesc + ": " + szErrorDesc + " (" + Class + "-" + Num + ")"; - case 4: szErrorClassDesc = "CNC error class"; switch (Num) @@ -1993,16 +1900,13 @@ namespace CMS_CORE.Osai case 3: szErrorDesc = "A function has been called without having created the Cndex server"; break; case 4: szErrorDesc = "One or more function input parameters are not valid"; break; case 5: szErrorDesc = "Option A06 -CndexLink communication- for network communications with external applications is not enabled on the CNC you are trying to connect to"; break; - } return ErrorOwner + szErrorClassDesc + ": " + szErrorDesc + " (" + Class + "-" + Num + ")"; default: return ErrorOwner + " Generic Osai Error - Class: " + Class + " Num: " + Num; - } } - #endregion - + #endregion Subordinate Private Functions } -} +} \ No newline at end of file diff --git a/CMS_CORE_Library/Siemens/Nc_Siemens.cs b/CMS_CORE_Library/Siemens/Nc_Siemens.cs index e663340..382d8f2 100644 --- a/CMS_CORE_Library/Siemens/Nc_Siemens.cs +++ b/CMS_CORE_Library/Siemens/Nc_Siemens.cs @@ -1,47 +1,49 @@ -using System; +using CMS_CORE.Utils; +using Siemens.Sinumerik.Operate.Services; +using System; using System.Collections.Generic; -using System.Linq; using System.Globalization; using System.IO; -using Siemens.Sinumerik.Operate.Services; +using System.Linq; using System.Text.RegularExpressions; -using CMS_CORE.Utils; using static CMS_CORE_Library.DataStructures; -using CMS_CORE_Library; namespace CMS_CORE.Siemens { public class Nc_Siemens : Nc { // Global Constants - const string OptionHMINotRunning = "P66"; - const string NcNotFound = "Missing response"; - const string NcNotFound2 = "networking error"; - const string NcNotFound3 = "Nc not Connected"; - const string SinumerikEnvVar = "HMI_INSTALL_DIR"; - const int IDMinPLCMessage = 700000; - const int IDMaxPLCMessage = 799999; - const int IDMinChannel = 10000; - const int IDMaxChannel = 19999; + private const string OptionHMINotRunning = "P66"; + + private const string NcNotFound = "Missing response"; + private const string NcNotFound2 = "networking error"; + private const string NcNotFound3 = "Nc not Connected"; + private const string SinumerikEnvVar = "HMI_INSTALL_DIR"; + private const int IDMinPLCMessage = 700000; + private const int IDMaxPLCMessage = 799999; + private const int IDMinChannel = 10000; + private const int IDMaxChannel = 19999; // Siemens Path Constants - const string PathMaxChannelNo = "/Nck/Configuration/maxnumChannels"; - const string PathConfChannelNo = "/Nck/Configuration/numChannels"; - const string PathNcType = "/Nck/Configuration/nckType"; - const string PathNcVersion = "/Nck/Configuration/nckVersion"; - const string PathLanguage = "/Nck/Configuration/anLanguageOnHmi"; - const string PathSerialNumber = "/Nck/State/hwProductSerialNrL"; - const string PathNcTime = "/Nck/State/sysTimeBCD"; - const string PathGenericNcMode = "/Bag/State/opMode"; - const string PathGenericNcState = "/Channel/State/chanStatus"; - const string PathIncrJog = "/Channel/GeometricAxis/actIncrVal"; - const string PathAdvancedJog = "/Channel/State/machFunc"; - const string PathRelatPosition = "/Channel/GeometricAxis/actToolBasPosEN"; - const string PathActProgLines = "/Channel/ProgramInfo/actPartProgram"; - const string PathActProgName = "/Channel/ProgramPointer/progName"; + private const string PathMaxChannelNo = "/Nck/Configuration/maxnumChannels"; - // Global Variables + private const string PathConfChannelNo = "/Nck/Configuration/numChannels"; + private const string PathNcType = "/Nck/Configuration/nckType"; + private const string PathNcVersion = "/Nck/Configuration/nckVersion"; + private const string PathLanguage = "/Nck/Configuration/anLanguageOnHmi"; + private const string PathSerialNumber = "/Nck/State/hwProductSerialNrL"; + private const string PathNcTime = "/Nck/State/sysTimeBCD"; + private const string PathGenericNcMode = "/Bag/State/opMode"; + private const string PathGenericNcState = "/Channel/State/chanStatus"; + private const string PathIncrJog = "/Channel/GeometricAxis/actIncrVal"; + private const string PathAdvancedJog = "/Channel/State/machFunc"; + private const string PathRelatPosition = "/Channel/GeometricAxis/actToolBasPosEN"; + private const string PathActProgLines = "/Channel/ProgramInfo/actPartProgram"; + private const string PathActProgName = "/Channel/ProgramPointer/progName"; + + // Global Variables private DateTime Last_Static_Read; + private ushort TimeoutConn; private String Cnc_name; private String Cnc_SftVersion; @@ -53,11 +55,12 @@ namespace CMS_CORE.Siemens // STatic variables private AlarmSvc SiemensAlmSvc; + private Alarm[] SiemensAlarms; /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - #region Contructor & global methods + #region Contructor & global methods /** * @@ -65,6 +68,7 @@ namespace CMS_CORE.Siemens * * Send/Recieve timeout connection [mS] * */ + public Nc_Siemens(ushort ConnectionTimeOut) { //Set Connected to FALSE and close the session @@ -75,14 +79,12 @@ namespace CMS_CORE.Siemens SiemensAlarms = new Alarm[] { }; } - - //Connect Method public override CmsError NC_Connect() { //Try to get information try - { + { //Check if Siemens Environment is started CmsError cmsError = CheckSiemensEnv(); if (cmsError.IsError()) @@ -100,7 +102,6 @@ namespace CMS_CORE.Siemens SiemensAlarms = new Alarm[] { }; SiemensAlmSvc = new AlarmSvc(ConvertToSTEPLanguage(SiemensLanguage).ThreeLetterISOLanguageName); SiemensAlmSvc.Subscribe(AlarmsChanged); - } catch (Exception ex) { @@ -110,8 +111,6 @@ namespace CMS_CORE.Siemens return NO_ERROR; } - - //Disconnect Method public override CmsError NC_Disconnect() { @@ -121,9 +120,10 @@ namespace CMS_CORE.Siemens return NO_ERROR; } - #endregion + #endregion Contructor & global methods /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region High level methods //Get the processes-count configurated @@ -138,8 +138,6 @@ namespace CMS_CORE.Siemens return NO_ERROR; } - - //Get the NC model Name public override CmsError NC_RModelName(ref string ModelName) { @@ -150,11 +148,8 @@ namespace CMS_CORE.Siemens ModelName = Cnc_name; return NO_ERROR; - } - - //Get the NC Software Version public override CmsError NC_RSoftwareVersion(ref string SWV) { @@ -167,8 +162,6 @@ namespace CMS_CORE.Siemens return NO_ERROR; } - - //Get the NC Language public override CmsError NC_RLanguage(ref CultureInfo Language) { @@ -181,8 +174,6 @@ namespace CMS_CORE.Siemens return NO_ERROR; } - - //Get the NC Serial number public override CmsError NC_RSerialNumber(ref string SN) { @@ -195,8 +186,6 @@ namespace CMS_CORE.Siemens return NO_ERROR; } - - //Get CMS Machine number public override CmsError NC_RMachineNumber(ref string MachNumber) { @@ -209,8 +198,6 @@ namespace CMS_CORE.Siemens return NO_ERROR; } - - //Get the Date-Time of the NC public override CmsError NC_RDateTime(ref DateTime ActualTime) { @@ -242,17 +229,6 @@ namespace CMS_CORE.Siemens return NO_ERROR; } - public override CmsError Nc_RPowerOnData(ref PreAndPostPowerOnModel powerOnModel) - { - return NO_ERROR; - } - - public override CmsError Nc_WPowerOnData(uint id, bool value) - { - return NO_ERROR; - } - - // Check if the NC is in running state public override CmsError NC_RIsRunning(ref bool running) { @@ -278,10 +254,67 @@ namespace CMS_CORE.Siemens i++; } while (!running || i <= nProcess); + return NO_ERROR; + } + + //Get the Nc Active Alarms + public override CmsError NC_RActiveAlarms(ref List alarms) + { + if (SiemensAlarms == null) + return null; + + alarms = SiemensAlarms. + Where(x => (x.Id < IDMinPLCMessage || x.Id > IDMaxPLCMessage) && (x.Id < IDMinChannel || x.Id > IDMaxChannel)) + .Select(x => new AlarmModel() { Id = (uint)x.Id, Message = x.Message, IsWarning = false, Process = 0 }) + .ToList(); return NO_ERROR; } + #endregion High level methods + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + #region PLC High-level data + + //Get the PLC Active Messages + public override CmsError PLC_RActiveMessages(ref List alarms) + { + alarms = SiemensAlarms + .Where(x => x.Id >= IDMinPLCMessage && x.Id <= IDMaxPLCMessage) + .Select(x => new AlarmModel() { Id = (uint)x.Id, Message = x.Message, IsWarning = false, Process = 0 }) + .ToList(); + + return NO_ERROR; + } + + public override CmsError PLC_RFunctionAccess(ref List functions) + { + functions = new List(); + 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_RAxesResetData(ref AxisResetDataModel axisResetData) + { + return NO_ERROR; + } + + #endregion PLC High-level data + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + #region PROCESS (PATH) High-level data + //Get the process Mode public override CmsError PROC_RMode(ushort ProcNumber, ref PROC_MODE Mode) { @@ -308,7 +341,6 @@ namespace CMS_CORE.Siemens //Save Data Mode = ConvertToSTEPMode((uint)ReadItem.Value, (uint)ReadItemIncr.Value, (uint)ReadItemAdv.Value); - } catch (Exception ex) { @@ -318,8 +350,6 @@ namespace CMS_CORE.Siemens return NO_ERROR; } - - //Get the process status public override CmsError PROC_RStatus(ushort ProcNumber, ref PROC_STATUS Status) { @@ -342,7 +372,6 @@ namespace CMS_CORE.Siemens //Save Data Status = ConvertToSTEPStatus((uint)ReadItem.Value); - } catch (Exception ex) { @@ -352,8 +381,6 @@ namespace CMS_CORE.Siemens return NO_ERROR; } - - //Get PP Lines public override CmsError PROC_RPPLines(ushort ProcNumber, ref List Lines) { @@ -395,8 +422,6 @@ namespace CMS_CORE.Siemens return NO_ERROR; } - - //Get PP Name public override CmsError PROC_RPPName(ushort ProcNumber, ref string Name) { @@ -429,7 +454,6 @@ namespace CMS_CORE.Siemens //Save Data Name = RetString; - } catch (Exception ex) { @@ -439,49 +463,19 @@ namespace CMS_CORE.Siemens return NO_ERROR; } - - //Get the Nc Active Alarms - public override CmsError NC_RActiveAlarms(ref List alarms) - { - if (SiemensAlarms == null) - return null; - - alarms = SiemensAlarms. - Where(x => (x.Id < IDMinPLCMessage || x.Id > IDMaxPLCMessage) && (x.Id < IDMinChannel || x.Id > IDMaxChannel)) - .Select(x => new AlarmModel() { id = (uint)x.Id, message = x.Message, isWarning = false, process = 0 }) - .ToList(); - - return NO_ERROR; - } - - - - //Get the PLC Active Messages - public override CmsError PLC_RActiveMessages(ref List alarms) - { - alarms = SiemensAlarms - .Where(x => x.Id >= IDMinPLCMessage && x.Id <= IDMaxPLCMessage) - .Select(x => new AlarmModel() { id = (uint)x.Id, message = x.Message, isWarning = false, process = 0}) - .ToList(); - - return NO_ERROR; - } - - - //Get the process Active Alarms public override CmsError PROC_RActiveAlarms(ushort procNumber, ref List alarms) { alarms = SiemensAlarms .Where(x => x.Id >= IDMinChannel && x.Id <= IDMaxChannel && x.Parameters[0].Equals(procNumber.ToString())) - .Select(x => new AlarmModel() { id = (uint)x.Id, message = x.Message, isWarning = false, process = procNumber }) + .Select(x => new AlarmModel() { Id = (uint)x.Id, Message = x.Message, IsWarning = false, Process = procNumber }) .ToList(); return NO_ERROR; } // Get process part program data - public override CmsError PROC_RStatus(ushort procNumber, ref ProcessData processData) + public override CmsError PROC_RStatusAndData(ushort procNumber, ref ProcessDataModel processData) { //processData.Id = procNumber; //// Read part program name @@ -498,7 +492,7 @@ namespace CMS_CORE.Siemens //byte[] bytes = BitConverter.GetBytes(readValue); //// Convert Byte into true/false array - //BitArray bits = new BitArray(new byte[] { bytes[0] }); //1st byte -> 0 : Proccess type (AUX-WORK), 1: Process in alarm status, 2: Run, 3: Hold, 4: Read, 5: PartProgramVisible + //BitArray bits = new BitArray(new byte[] { bytes[0] }); //1st byte -> 0 : Proccess type (AUX-WORK), 1: Process in alarm status, 2: Run, 3: Hold, 4: Read, 5: PartProgramVisible //// Populate response structure //processData.Type = bits[0] ? "WORK" : "AUX"; //processData.IsInAlarm = bits[1]; @@ -522,54 +516,50 @@ namespace CMS_CORE.Siemens return NO_ERROR; } + #endregion PROCESS (PATH) High-level data + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + #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 ProcNumber, ref Dictionary Axes) { return FUNCTION_NOT_ALLOWED_ERROR; } - - //Get a dictionary with the Machine position of the axes in Process public override CmsError AXES_RMachinePosition(ushort ProcNumber, ref Dictionary Axes) { return FUNCTION_NOT_ALLOWED_ERROR; } - - //Get a dictionary with the Programmed position of the axes in Process public override CmsError AXES_RProgrPosition(ushort ProcNumber, ref Dictionary Axes) { return FUNCTION_NOT_ALLOWED_ERROR; } - - //Get a dictionary with the Following Error of the axes in Process public override CmsError AXES_RFollowingError(ushort ProcNumber, ref Dictionary Axes) { return FUNCTION_NOT_ALLOWED_ERROR; } - - //Get a dictionary with the Distance To Go of the axes in Process public override CmsError AXES_RDistanceToGo(ushort ProcNumber, ref Dictionary Axes) { return FUNCTION_NOT_ALLOWED_ERROR; } - #endregion + #endregion PROCESS-AXES (PATH) High-level data /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - #region Low level methods - //-------------------------------------------------------------------------------------------------------------------------- - // BOOLEAN (NC) <-> BOOLEAN (.NET) + #region NC Low-level function: single valiable in memory //Read-Write a Boolean-Value inside the NC. - public override CmsError MEM_RWBoolean(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, int MemBit, ref bool Value) + public override CmsError MEM_RWBoolean(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int MemBit, ref bool Value) { //Check if the NC is Connected CmsError cmsError = CheckConnection(); @@ -604,7 +594,6 @@ namespace CMS_CORE.Siemens { Data.Read(item); Value = (bool)item.Value; - } } catch (Exception ex) @@ -615,14 +604,145 @@ namespace CMS_CORE.Siemens return NO_ERROR; } + //Read-Write a Byte-Value-List inside the NC. In writing-mode the field "Number" is not required + public override CmsError MEM_RWByte(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int MemByte, ref byte Value) + { + List ListValue = new List() { Value }; + //uses the List method with one-element list + CmsError cmsError = MEM_RWByteList(bWrite, Process, MemType, MemTable, MemIndex, MemByte, 1, ref ListValue); + if (cmsError.IsError()) + return cmsError; + Value = ListValue.First(); + + return NO_ERROR; + } + + //Write a Word-Value inside the NC. In writing-mode the field "Number" is not required + public override CmsError MEM_RWWord(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, ref ushort Value) + { + List ListValue = new List() { Value }; + + //uses the List method with one-element list + CmsError cmsError = MEM_RWWordList(bWrite, Process, MemType, MemTable, MemIndex, 1, ref ListValue); + if (cmsError.IsError()) + return cmsError; + + Value = ListValue.First(); + + return NO_ERROR; + } + + public override CmsError MEM_RWShort(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, ref short Value) + { + List ListValue = new List() { Value }; + + //uses the List method with one-element list + CmsError cmsError = MEM_RWShortList(bWrite, Process, MemType, MemTable, MemIndex, 1, ref ListValue); + if (cmsError.IsError()) + return cmsError; + + Value = ListValue.First(); + + return NO_ERROR; + } + + //Write a Word-Value inside the NC. In writing-mode the field "Number" is not required + public override CmsError MEM_RWDWord(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, ref uint Value) + { + List ListValue = new List() { Value }; + + //uses the List method with one-element list + CmsError cmsError = MEM_RWDWordList(bWrite, Process, MemType, MemTable, MemIndex, 1, ref ListValue); + if (cmsError.IsError()) + return cmsError; + + Value = ListValue.First(); + + return NO_ERROR; + } + + //Write a Int-Value inside the NC. In writing-mode the field "Number" is not required + public override CmsError MEM_RWInteger(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, ref int Value) + { + List ListValue = new List() { Value }; + + //uses the List method with one-element list + CmsError cmsError = MEM_RWIntegerList(bWrite, Process, MemType, MemTable, MemIndex, 1, ref ListValue); + if (cmsError.IsError()) + return cmsError; + + Value = ListValue.First(); + + return NO_ERROR; + } //-------------------------------------------------------------------------------------------------------------------------- - // BYTE (NC) <-> BYTE (.NET) + // Other-NC Version of Memory-Access Methods - //Read-Write a Byte-Value inside the NC. In writing-mode the field "Number" is not required - public override CmsError MEM_RWByteList(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, int MemByteStart, int Number, ref List Value) + public override CmsError MEM_RWBoolean(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int MemBit, ref bool Value) + { + return FUNCTION_NOT_ALLOWED_ERROR; + } + + public override CmsError MEM_RWByte(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int MemByte, ref byte Value) + { + return FUNCTION_NOT_ALLOWED_ERROR; + } + + public override CmsError MEM_RWDWord(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, ref uint Value) + { + return FUNCTION_NOT_ALLOWED_ERROR; + } + + public override CmsError MEM_RWInteger(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, ref int Value) + { + return FUNCTION_NOT_ALLOWED_ERROR; + } + + public override CmsError MEM_RWShort(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, ref short Value) + { + return FUNCTION_NOT_ALLOWED_ERROR; + } + + public override CmsError MEM_RWWord(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, ref ushort Value) + { + return FUNCTION_NOT_ALLOWED_ERROR; + } + + public override CmsError MEM_RWDWordList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int Number, ref List Value) + { + return FUNCTION_NOT_ALLOWED_ERROR; + } + + public override CmsError MEM_RWIntegerList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int Number, ref List Value) + { + return FUNCTION_NOT_ALLOWED_ERROR; + } + + public override CmsError MEM_RWShortList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int Number, ref List Value) + { + return FUNCTION_NOT_ALLOWED_ERROR; + } + + public override CmsError MEM_RWWordList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int Number, ref List Value) + { + return FUNCTION_NOT_ALLOWED_ERROR; + } + + public override CmsError MEM_RWByteList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int MemByteStart, int Number, ref List Value) + { + return FUNCTION_NOT_ALLOWED_ERROR; + } + + #endregion NC Low-level function: single valiable in memory + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + #region Low level methods + + public override CmsError MEM_RWByteList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int MemByteStart, int Number, ref List Value) { //Check if the NC is Connected CmsError cmsError = CheckConnection(); @@ -658,7 +778,6 @@ namespace CMS_CORE.Siemens Value.Clear(); Value.Add((byte)(uint)item.Value); } - } } catch (Exception ex) @@ -669,31 +788,7 @@ namespace CMS_CORE.Siemens return NO_ERROR; } - - - //Read-Write a Byte-Value-List inside the NC. In writing-mode the field "Number" is not required - public override CmsError MEM_RWByte(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, int MemByte, ref byte Value) - { - List ListValue = new List() { Value }; - - //uses the List method with one-element list - CmsError cmsError = MEM_RWByteList(bWrite, Process, MemType, MemTable, MemIndex, MemByte, 1, ref ListValue); - if (cmsError.IsError()) - return cmsError; - - Value = ListValue.First(); - - return NO_ERROR; - } - - - - //-------------------------------------------------------------------------------------------------------------------------- - // WORD (NC) <-> USHORT (.NET) - - - //Write a Word-Value-List inside the NC. In writing-mode the field "Number" is not required - public override CmsError MEM_RWWordList(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, int Number, ref List Value) + public override CmsError MEM_RWWordList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int Number, ref List Value) { //Check if the NC is Connected CmsError cmsError = CheckConnection(); @@ -729,7 +824,6 @@ namespace CMS_CORE.Siemens Value.Clear(); Value.Add(Convert.ToUInt16((uint)item.Value)); } - } } catch (Exception ex) @@ -740,28 +834,7 @@ namespace CMS_CORE.Siemens return NO_ERROR; } - - //Write a Word-Value inside the NC. In writing-mode the field "Number" is not required - public override CmsError MEM_RWWord(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, ref ushort Value) - { - List ListValue = new List() { Value }; - - //uses the List method with one-element list - CmsError cmsError = MEM_RWWordList(bWrite, Process, MemType, MemTable, MemIndex, 1, ref ListValue); - if (cmsError.IsError()) - return cmsError; - - Value = ListValue.First(); - - return NO_ERROR; - } - - - - //-------------------------------------------------------------------------------------------------------------------------- - // WORD (NC) <-> SHORT (.NET) - - public override CmsError MEM_RWShortList(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, int Number, ref List Value) + public override CmsError MEM_RWShortList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int Number, ref List Value) { //Check if the NC is Connected CmsError cmsError = CheckConnection(); @@ -797,7 +870,6 @@ namespace CMS_CORE.Siemens Value.Clear(); Value.Add(unchecked((short)(uint)item.Value)); } - } } catch (Exception ex) @@ -808,28 +880,7 @@ namespace CMS_CORE.Siemens return NO_ERROR; } - - public override CmsError MEM_RWShort(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, ref short Value) - { - List ListValue = new List() { Value }; - - //uses the List method with one-element list - CmsError cmsError = MEM_RWShortList(bWrite, Process, MemType, MemTable, MemIndex, 1, ref ListValue); - if (cmsError.IsError()) - return cmsError; - - Value = ListValue.First(); - - return NO_ERROR; - } - - - - //-------------------------------------------------------------------------------------------------------------------------- - // DWORD (NC) <-> UINT (.NET) - - //Write a Word-Value-List inside the NC. In writing-mode the field "Number" is not required - public override CmsError MEM_RWDWordList(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, int Number, ref List Value) + public override CmsError MEM_RWDWordList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int Number, ref List Value) { //Check if the NC is Connected CmsError cmsError = CheckConnection(); @@ -864,7 +915,6 @@ namespace CMS_CORE.Siemens Value.Clear(); Value.Add((uint)item.Value); } - } } catch (Exception ex) @@ -875,29 +925,7 @@ namespace CMS_CORE.Siemens return NO_ERROR; } - //Write a Word-Value inside the NC. In writing-mode the field "Number" is not required - - public override CmsError MEM_RWDWord(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, ref uint Value) - { - List ListValue = new List() { Value }; - - //uses the List method with one-element list - CmsError cmsError = MEM_RWDWordList(bWrite, Process, MemType, MemTable, MemIndex, 1, ref ListValue); - if (cmsError.IsError()) - return cmsError; - - Value = ListValue.First(); - - return NO_ERROR; - } - - - - //-------------------------------------------------------------------------------------------------------------------------- - // DWORD (NC) <-> INT (.NET) - - //Write a Int-Value-List inside the NC. In writing-mode the field "Number" is not required - public override CmsError MEM_RWIntegerList(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, int Number, ref List Value) + public override CmsError MEM_RWIntegerList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int Number, ref List Value) { //Check if the NC is Connected CmsError cmsError = CheckConnection(); @@ -933,7 +961,6 @@ namespace CMS_CORE.Siemens Value.Clear(); Value.Add(unchecked((int)(uint)item.Value)); } - } } catch (Exception ex) @@ -944,78 +971,11 @@ namespace CMS_CORE.Siemens return NO_ERROR; } - //Write a Int-Value inside the NC. In writing-mode the field "Number" is not required - public override CmsError MEM_RWInteger(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, ref int Value) - { - List ListValue = new List() { Value }; + #endregion Low level methods - //uses the List method with one-element list - CmsError cmsError = MEM_RWIntegerList(bWrite, Process, MemType, MemTable, MemIndex, 1, ref ListValue); - if (cmsError.IsError()) - return cmsError; + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - Value = ListValue.First(); - - return NO_ERROR; - } - - - - //-------------------------------------------------------------------------------------------------------------------------- - // Other-NC Version of Memory-Access Methods - - public override CmsError MEM_RWBoolean(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, int MemBit, ref bool Value) - { - return FUNCTION_NOT_ALLOWED_ERROR; - } - public override CmsError MEM_RWByte(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, int MemByte, ref byte Value) - { - return FUNCTION_NOT_ALLOWED_ERROR; - } - public override CmsError MEM_RWDWord(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, ref uint Value) - { - return FUNCTION_NOT_ALLOWED_ERROR; - } - public override CmsError MEM_RWInteger(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, ref int Value) - { - return FUNCTION_NOT_ALLOWED_ERROR; - } - public override CmsError MEM_RWShort(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, ref short Value) - { - return FUNCTION_NOT_ALLOWED_ERROR; - } - public override CmsError MEM_RWWord(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, ref ushort Value) - { - return FUNCTION_NOT_ALLOWED_ERROR; - } - public override CmsError MEM_RWDWordList(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, int Number, ref List Value) - { - return FUNCTION_NOT_ALLOWED_ERROR; - } - - public override CmsError MEM_RWIntegerList(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, int Number, ref List Value) - { - return FUNCTION_NOT_ALLOWED_ERROR; - } - - public override CmsError MEM_RWShortList(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, int Number, ref List Value) - { - return FUNCTION_NOT_ALLOWED_ERROR; - } - - public override CmsError MEM_RWWordList(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, int Number, ref List Value) - { - return FUNCTION_NOT_ALLOWED_ERROR; - } - - public override CmsError MEM_RWByteList(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, int MemByteStart, int Number, ref List Value) - { - return FUNCTION_NOT_ALLOWED_ERROR; - } - - - //-------------------------------------------------------------------------------------------------------------------------- - // PARAMS + #region NC Low-level function: Parameters public override CmsError NC_RParam(short Index, short Bit, ref bool Value) { @@ -1042,10 +1002,11 @@ namespace CMS_CORE.Siemens return FUNCTION_NOT_ALLOWED_ERROR; } - #endregion + #endregion NC Low-level function: Parameters /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - #region File Management + + #region File Management public override CmsError FILES_CopyProgram(string partProgramPath, string newPartProgramPath, bool failIfExist) { @@ -1071,8 +1032,6 @@ namespace CMS_CORE.Siemens return NO_ERROR; } - - public override CmsError FILES_DeleteProgram(string partProgramPath, string partProgramName) { //Check if the NC is Connected @@ -1097,8 +1056,6 @@ namespace CMS_CORE.Siemens return NO_ERROR; } - - public override CmsError FILES_RProgramToFile(string partProgramPath, FileStream localFile) { //Check if the NC is Connected @@ -1122,7 +1079,6 @@ namespace CMS_CORE.Siemens //Delete temporary file File.Delete(TempFile); - } catch (Exception ex) { @@ -1132,8 +1088,6 @@ namespace CMS_CORE.Siemens return NO_ERROR; } - - public override CmsError FILES_WProgramFromFile(string partProgramPath, FileStream localFile) { //Check if the NC is Connected @@ -1150,7 +1104,6 @@ namespace CMS_CORE.Siemens //Execute Function FileData.Copy(sourceNode, destNode, true); - } catch (Exception ex) { @@ -1160,9 +1113,10 @@ namespace CMS_CORE.Siemens return NO_ERROR; } - #endregion + #endregion File Management /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region Subordinate Private Functions //Manage the Alarms - Called automatically on changes @@ -1171,8 +1125,6 @@ namespace CMS_CORE.Siemens SiemensAlarms = alarms; } - - //Manage the Mode private PROC_MODE ConvertToSTEPMode(uint mode, uint JogMode, uint AdvMode) { @@ -1195,8 +1147,6 @@ namespace CMS_CORE.Siemens return PROC_MODE.ERROR; } - - //Manage the Status private PROC_STATUS ConvertToSTEPStatus(uint status) { @@ -1209,8 +1159,6 @@ namespace CMS_CORE.Siemens return PROC_STATUS.ERROR; } - - //Check Bit In Range private CmsError CheckBitRange(int bitnum) { @@ -1220,10 +1168,8 @@ namespace CMS_CORE.Siemens return NO_ERROR; } - - //Check if Memory Area is corrected - private CmsError ConvertMemToPath(MEMORY_Type MemoryType, int Address, int SubAddress, int SubBit, int Qty, char MemAccess, out string item) + private CmsError ConvertMemToPath(MEMORY_TYPE MemoryType, int Address, int SubAddress, int SubBit, int Qty, char MemAccess, out string item) { char[] allowedAccess = { 'X', 'B', 'W', 'D' }; @@ -1245,8 +1191,6 @@ namespace CMS_CORE.Siemens } } - - //Check if NC is connected private CmsError CheckConnection() { @@ -1256,8 +1200,6 @@ namespace CMS_CORE.Siemens return NO_ERROR; } - - //Check if Siemens Environment is started private CmsError CheckSiemensEnv() { @@ -1266,12 +1208,10 @@ namespace CMS_CORE.Siemens return NO_ERROR; } - - //Manage the Exception Launch private CmsError ManageException(Exception ex) { - //Catch the Siemens exceptions + //Catch the Siemens exceptions if (ex is OperateMissingOptionException && ex.Message.Contains(OptionHMINotRunning)) { Connected = false; @@ -1342,7 +1282,6 @@ namespace CMS_CORE.Siemens //Save NOW Last_Static_Read = DateTime.Now; - } catch (Exception ex) { @@ -1353,8 +1292,6 @@ namespace CMS_CORE.Siemens return NO_ERROR; } - - // Convert the internal Name var in Readable STEP Name private String getName(uint value) { @@ -1375,8 +1312,6 @@ namespace CMS_CORE.Siemens return name; } - - //Convert to Step Language private CultureInfo ConvertToSTEPLanguage(uint language) { @@ -1414,7 +1349,7 @@ namespace CMS_CORE.Siemens default: return new CultureInfo("en"); } } - #endregion + #endregion Subordinate Private Functions } -} +} \ No newline at end of file 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 2bfd396..f8a7a9b 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 @@ -391,13 +391,14 @@ namespace Nc_Demo_Application.Database foreach (DataRow row in BinaryMemory.Rows) { // Populate binary column for each row int -> binary - row["binary"] = Convert.ToString(Convert.ToInt32(row["value"].ToString(), 10), 2).PadLeft(8, '0'); + row["binary"] = Convert.ToString(Convert.ToInt32(row["value"].ToString(), 10), 2).PadLeft(8, '0').Substring(0,8); // Add binary value to word and integer word = row["binary"] + word; integer = row["binary"] + integer; // Every 2 row set word value if (i % 2 == 0) { + Convert.ToUInt16(word, 2); row["word"] = Convert.ToInt16(word, 2); word = ""; } @@ -440,7 +441,7 @@ namespace Nc_Demo_Application.Database { ValidateIndex(index); - return Convert.ToByte(BinaryMemory.Rows[index]["value"]); + return Convert.ToByte(BinaryMemory.Rows[index]["binary"].ToString(), 2); } public string GetBinaryByteValue(int index) diff --git a/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Views/DemoApplicationForm.cs b/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Views/DemoApplicationForm.cs index 14fa45f..38a9ce7 100644 --- a/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Views/DemoApplicationForm.cs +++ b/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Views/DemoApplicationForm.cs @@ -154,6 +154,8 @@ namespace Nc_Demo_Application private void SaveNcProcessData_Click(object sender, EventArgs e) { DatabaseController.getInstance().UpdateNcProcess((DataTable)ncProcessGridView.DataSource); + FillNcProcessInput(); + } private void SaveNcAlarmsButton_Click(object sender, EventArgs e)