From 4d7ebdcc1229fe61de069be5f215c2f3eeb46d9d Mon Sep 17 00:00:00 2001 From: Lucio Maranta Date: Tue, 9 Jan 2018 15:16:49 +0000 Subject: [PATCH] --- CMS_CORE_Application/Form1.cs | 11 +- CMS_CORE_Library/Demo/Nc_Demo.cs | 458 ++++++---- CMS_CORE_Library/Fanuc/Nc_Fanuc.cs | 963 +++++++++++--------- CMS_CORE_Library/Nc.cs | 154 ++-- CMS_CORE_Library/Osai/Nc_Osai.cs | 1119 +++++++++++++----------- CMS_CORE_Library/Siemens/Nc_Siemens.cs | 779 ++++++++++------- 6 files changed, 1996 insertions(+), 1488 deletions(-) diff --git a/CMS_CORE_Application/Form1.cs b/CMS_CORE_Application/Form1.cs index 2ac8cad..727b475 100644 --- a/CMS_CORE_Application/Form1.cs +++ b/CMS_CORE_Application/Form1.cs @@ -19,6 +19,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; +using static CMS_CORE.Nc; namespace CMS_CORE_Application { @@ -55,9 +56,7 @@ namespace CMS_CORE_Application Connect.Enabled = false; Disconnect.Enabled = true; t.Start(); - } - - + } } private void test() @@ -87,9 +86,9 @@ namespace CMS_CORE_Application N = new Nc_Osai(NCIp, NCPort,500); if (NCType == "Fanuc") N = new Nc_Fanuc(NCIp, NCPort, 500); - - N.NC_Connect(); - N.NC_RModelName(ref ModelName); + + CmsError cmsError = N.NC_Connect(); + cmsError = N.NC_RModelName(ref ModelName); N.NC_RProcessesNum(ref procnum); N.NC_RMachineNumber(ref MachNumber); diff --git a/CMS_CORE_Library/Demo/Nc_Demo.cs b/CMS_CORE_Library/Demo/Nc_Demo.cs index 9491eb1..3f0928e 100644 --- a/CMS_CORE_Library/Demo/Nc_Demo.cs +++ b/CMS_CORE_Library/Demo/Nc_Demo.cs @@ -29,7 +29,7 @@ namespace CMS_CORE.Demo Port = RemotePort; } - public override void NC_Connect() + public override CmsError NC_Connect() { // Create new connection to the demo server String url = "http://" + Ip + ":" + Port + "/api"; @@ -39,25 +39,31 @@ namespace CMS_CORE.Demo cf.Endpoint.EndpointBehaviors.Add(new WebHttpBehavior()); serverService = cf.CreateChannel(); - + Connected = true; + + return NO_ERROR; } - public override void NC_Disconnect() + public override CmsError NC_Disconnect() { cf.Close(); Connected = false; + + return NO_ERROR; } #endregion - + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #region High level methods - public override void NC_RDateTime(ref DateTime ActualTime) + public override CmsError NC_RDateTime(ref DateTime ActualTime) { //Check if the NC Demo is Connected - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; try { @@ -69,14 +75,18 @@ namespace CMS_CORE.Demo } catch (Exception ex) { - ThrowNCException(ex); + return ThrowNCException(ex); } + + return NO_ERROR; } - public override void NC_RSerialNumber(ref String SN) + public override CmsError NC_RSerialNumber(ref String SN) { //Check if the NC Demo is Connected - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; try { @@ -85,15 +95,19 @@ namespace CMS_CORE.Demo } catch (Exception ex) { - ThrowNCException(ex); + return ThrowNCException(ex); } + + return NO_ERROR; } //Get the NC model Name - public override void NC_RModelName(ref string ModelName) + public override CmsError NC_RModelName(ref string ModelName) { //Check if the NC Demo is Connected - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; try { @@ -101,14 +115,18 @@ namespace CMS_CORE.Demo } catch (Exception ex) { - ThrowNCException(ex); + return ThrowNCException(ex); } + + return NO_ERROR; } - public override void NC_RSoftwareVersion(ref String SWV) + public override CmsError NC_RSoftwareVersion(ref String SWV) { //Check if the NC Demo is Connected - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; try { @@ -117,14 +135,18 @@ namespace CMS_CORE.Demo } catch (Exception ex) { - ThrowNCException(ex); + return ThrowNCException(ex); } + + return NO_ERROR; } - public override void NC_RMachineNumber(ref string MachNumber) + public override CmsError NC_RMachineNumber(ref string MachNumber) { //Check if the NC Demo is Connected - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; try { @@ -135,12 +157,16 @@ namespace CMS_CORE.Demo { ThrowNCException(ex); } + + return NO_ERROR; } - public override void NC_RProcessesNum(ref ushort ProcNumber) + public override CmsError NC_RProcessesNum(ref ushort ProcNumber) { //Check if the NC Demo is Connected - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; try { // Get Process Cout from Demo server @@ -150,12 +176,16 @@ namespace CMS_CORE.Demo { ThrowNCException(ex); } + + return NO_ERROR; } - public override void NC_RLanguage(ref CultureInfo Language) + public override CmsError NC_RLanguage(ref CultureInfo Language) { //Check if the NC Demo is Connected - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; try { @@ -167,23 +197,29 @@ namespace CMS_CORE.Demo } catch (Exception ex) { - ThrowNCException(ex); + return ThrowNCException(ex); } + + return NO_ERROR; } - public override void NC_RActiveAlarms(ref List Alarms) + public override CmsError NC_RActiveAlarms(ref List Alarms) { Alarms.Clear(); + + return NO_ERROR; } #endregion /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #region PLC High-level data - public override void PLC_RActiveMessages(ref List Alarms) + public override CmsError PLC_RActiveMessages(ref List Alarms) { // Check if the NC Demo is Connected - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; try { @@ -199,8 +235,10 @@ namespace CMS_CORE.Demo } catch (Exception ex) { - ThrowNCException(ex); + return ThrowNCException(ex); } + + return NO_ERROR; } #endregion @@ -208,10 +246,12 @@ namespace CMS_CORE.Demo /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #region PROCESS (PATH) High-level data - public override void PROC_RStatus(ushort ProcNumber, ref PROC_Status Status) + public override CmsError PROC_RStatus(ushort ProcNumber, ref PROC_Status Status) { // Check if the NC Demo is Connected - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; try { @@ -222,14 +262,18 @@ namespace CMS_CORE.Demo } catch (Exception ex) { - ThrowNCException(ex); + return ThrowNCException(ex); } + + return NO_ERROR; } - public override void PROC_RMode(ushort ProcNumber, ref PROC_Mode Mode) + public override CmsError PROC_RMode(ushort ProcNumber, ref PROC_Mode Mode) { // Check if the NC Demo is Connected - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; try { @@ -240,14 +284,18 @@ namespace CMS_CORE.Demo } catch (Exception ex) { - ThrowNCException(ex); + return ThrowNCException(ex); } + + return NO_ERROR; } - public override void PROC_RActiveAlarms(ushort ProcNumber, ref List Alarms) + public override CmsError PROC_RActiveAlarms(ushort ProcNumber, ref List Alarms) { // Check if the NC Demo is Connected - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; try { @@ -260,13 +308,15 @@ namespace CMS_CORE.Demo } catch (Exception ex) { - ThrowNCException(ex); + return ThrowNCException(ex); } + + return NO_ERROR; } - - public override void PROC_RPPLines(ushort ProcNumber, ref List Lines) + + public override CmsError PROC_RPPLines(ushort ProcNumber, ref List Lines) { - ThrowNCException(new Nc_Exception(getError(FUNC_NOTALL_NC_ERROR))); + return FUNCTION_NOT_ALLOWED_ERROR; } #endregion @@ -274,32 +324,38 @@ namespace CMS_CORE.Demo /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #region PROCESS-AXES (PATH) High-level data - public override void AXES_RInterpPosition(ushort ProcNumber, ref Dictionary Axes) + public override CmsError AXES_RInterpPosition(ushort ProcNumber, ref Dictionary Axes) { // Check if the NC Demo is Connected - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; try - { + { // Get axes position from Demo Server serverService.GetAxesPosition(ProcNumber.ToString(), out List demoAxes); // Parse server response - foreach(NcAxisModel demoAxis in demoAxes) + foreach (NcAxisModel demoAxis in demoAxes) { Axes.Add(demoAxis.name, demoAxis.actual); } } catch (Exception ex) { - ThrowNCException(ex); + return ThrowNCException(ex); } + + return NO_ERROR; } - public override void AXES_RProgrPosition(ushort ProcNumber, ref Dictionary Axes) + public override CmsError AXES_RProgrPosition(ushort ProcNumber, ref Dictionary Axes) { // Check if the NC Demo is Connected - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; try { @@ -313,15 +369,18 @@ namespace CMS_CORE.Demo } catch (Exception ex) { - ThrowNCException(ex); + return ThrowNCException(ex); } + + return NO_ERROR; } - public override void AXES_RMachinePosition(ushort ProcNumber, ref Dictionary Axes) + public override CmsError AXES_RMachinePosition(ushort ProcNumber, ref Dictionary Axes) { // Check if the NC Demo is Connected - CheckConnection(); - + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; try { // Get Axes Position from server @@ -335,14 +394,18 @@ namespace CMS_CORE.Demo } catch (Exception ex) { - ThrowNCException(ex); + return ThrowNCException(ex); } + + return NO_ERROR; } - public override void AXES_RFollowingError(ushort ProcNumber, ref Dictionary Axes) + public override CmsError AXES_RFollowingError(ushort ProcNumber, ref Dictionary Axes) { // Check if the NC Demo is Connected - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; try { @@ -356,14 +419,18 @@ namespace CMS_CORE.Demo } catch (Exception ex) { - ThrowNCException(ex); + return ThrowNCException(ex); } + + return NO_ERROR; } - public override void AXES_RDistanceToGo(ushort ProcNumber, ref Dictionary Axes) + public override CmsError AXES_RDistanceToGo(ushort ProcNumber, ref Dictionary Axes) { // Check if the NC Demo is Connected - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; try { @@ -376,8 +443,10 @@ namespace CMS_CORE.Demo } catch (Exception ex) { - ThrowNCException(ex); + return ThrowNCException(ex); } + + return NO_ERROR; } #endregion @@ -385,12 +454,16 @@ namespace CMS_CORE.Demo /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #region NC Low-level function: single valiable in memory - public override void 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 - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; - CheckBitRange(MemBit); + cmsError = CheckBitRange(MemBit); + if (cmsError.errorCode != OK) + return cmsError; try { @@ -407,14 +480,18 @@ namespace CMS_CORE.Demo } catch (Exception ex) { - ThrowNCException(ex); + return ThrowNCException(ex); } + + return NO_ERROR; } - public override void 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 - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; try { @@ -433,14 +510,18 @@ namespace CMS_CORE.Demo } catch (Exception ex) { - ThrowNCException(ex); + return ThrowNCException(ex); } + + return NO_ERROR; } - public override void 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 - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; try { @@ -458,14 +539,18 @@ namespace CMS_CORE.Demo } catch (Exception ex) { - ThrowNCException(ex); + return ThrowNCException(ex); } + + return NO_ERROR; } - public override void 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 - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; try { @@ -483,14 +568,18 @@ namespace CMS_CORE.Demo } catch (Exception ex) { - ThrowNCException(ex); + return ThrowNCException(ex); } + + return NO_ERROR; } - public override void 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 - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; try { @@ -508,14 +597,18 @@ namespace CMS_CORE.Demo } catch (Exception ex) { - ThrowNCException(ex); + return ThrowNCException(ex); } + + return NO_ERROR; } - public override void 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 - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; try { @@ -533,8 +626,10 @@ namespace CMS_CORE.Demo } catch (Exception ex) { - ThrowNCException(ex); + return ThrowNCException(ex); } + + return NO_ERROR; } @@ -542,58 +637,58 @@ namespace CMS_CORE.Demo //-------------------------------------------------------------------------------------------------------------------------- // Siemens Version of Memory-Access Methods - public override void 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) { - MEM_RWBoolean(bWrite, Process, MemType, MemIndex, MemBit, ref Value); + return MEM_RWBoolean(bWrite, Process, MemType, MemIndex, MemBit, ref Value); } - public override void 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) { - MEM_RWByte(bWrite, Process, MemType, MemIndex, MemByte, ref Value); + return MEM_RWByte(bWrite, Process, MemType, MemIndex, MemByte, ref Value); } - public override void 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) { - MEM_RWWord(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); + return MEM_RWWord(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); } - public override void 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) { - MEM_RWShort(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); + return MEM_RWShort(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); } - public override void 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) { - MEM_RWDWord(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); + return MEM_RWDWord(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); } - public override void 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) { - MEM_RWInteger(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); + return MEM_RWInteger(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); } - public override void 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) { - MEM_RWByteList(bWrite, Process, MemType, MemIndex, MemByteStart, Number, ref Value); + return MEM_RWByteList(bWrite, Process, MemType, MemIndex, MemByteStart, Number, ref Value); } - public override void 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) { - MEM_RWWordList(bWrite, Process, MemType, MemIndex, Number, ref Value); + return MEM_RWWordList(bWrite, Process, MemType, MemIndex, Number, ref Value); } - public override void 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) { - MEM_RWShortList(bWrite, Process, MemType, MemIndex, Number, ref Value); + return MEM_RWShortList(bWrite, Process, MemType, MemIndex, Number, ref Value); } - public override void 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) { - MEM_RWDWordList(bWrite, Process, MemType, MemIndex, Number, ref Value); + return MEM_RWDWordList(bWrite, Process, MemType, MemIndex, Number, ref Value); } - public override void 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) { - MEM_RWIntegerList(bWrite, Process, MemType, MemIndex, Number, ref Value); + return MEM_RWIntegerList(bWrite, Process, MemType, MemIndex, Number, ref Value); } #endregion @@ -601,10 +696,12 @@ namespace CMS_CORE.Demo /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #region NC Low-level function: variables List in memory - public override void 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 - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; try { @@ -622,14 +719,18 @@ namespace CMS_CORE.Demo } catch (Exception ex) { - ThrowNCException(ex); + return ThrowNCException(ex); } + + return NO_ERROR; } - public override void 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 - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; try { @@ -647,14 +748,18 @@ namespace CMS_CORE.Demo } catch (Exception ex) { - ThrowNCException(ex); + return ThrowNCException(ex); } + + return NO_ERROR; } - public override void 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 - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; try { @@ -672,14 +777,18 @@ namespace CMS_CORE.Demo } catch (Exception ex) { - ThrowNCException(ex); + return ThrowNCException(ex); } + + return NO_ERROR; } - public override void 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 - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; try { @@ -697,14 +806,18 @@ namespace CMS_CORE.Demo } catch (Exception ex) { - ThrowNCException(ex); + return ThrowNCException(ex); } + + return NO_ERROR; } - public override void 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 - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; try { @@ -722,8 +835,10 @@ namespace CMS_CORE.Demo } catch (Exception ex) { - ThrowNCException(ex); + return ThrowNCException(ex); } + + return NO_ERROR; } #endregion @@ -731,55 +846,61 @@ namespace CMS_CORE.Demo #region NC Low-level function: Parameters - public override void NC_RParam(short Index, short Bit, ref bool Value) + public override CmsError NC_RParam(short Index, short Bit, ref bool Value) { - throw new Nc_Exception(getError(FUNC_NOTALL_NC_ERROR)); + return FUNCTION_NOT_ALLOWED_ERROR; } - public override void NC_RParam(short Index, ref byte Value) + public override CmsError NC_RParam(short Index, ref byte Value) { - throw new Nc_Exception(getError(FUNC_NOTALL_NC_ERROR)); + return FUNCTION_NOT_ALLOWED_ERROR; } - public override void NC_RParam(short Index, ref short Value) + public override CmsError NC_RParam(short Index, ref short Value) { - throw new Nc_Exception(getError(FUNC_NOTALL_NC_ERROR)); + return FUNCTION_NOT_ALLOWED_ERROR; } - public override void NC_RParam(short Index, ref int Value) + public override CmsError NC_RParam(short Index, ref int Value) { - throw new Nc_Exception(getError(FUNC_NOTALL_NC_ERROR)); + return FUNCTION_NOT_ALLOWED_ERROR; } - public override void NC_RParam(short Index, ref double Value) + public override CmsError NC_RParam(short Index, ref double Value) { - throw new Nc_Exception(getError(FUNC_NOTALL_NC_ERROR)); + return FUNCTION_NOT_ALLOWED_ERROR; } #endregion /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #region File Management - public override void FILES_RProgramToFile(string partProgramPath, FileStream localFile) + public override CmsError FILES_RProgramToFile(string partProgramPath, FileStream localFile) { // Check if the NC Demo is Connected - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; try { serverService.GetFile(partProgramPath, out string fileContent); Nc_Utils.WriteLocalFile(fileContent, ref localFile); - } - catch(Exception ex) - { - ThrowNCException(ex); } + catch (Exception ex) + { + return ThrowNCException(ex); + } + + return NO_ERROR; } - public override void FILES_WProgramFromFile(string partProgramPath, FileStream localFile) + public override CmsError FILES_WProgramFromFile(string partProgramPath, FileStream localFile) { // Check if the NC Demo is Connected - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; try { @@ -792,14 +913,18 @@ namespace CMS_CORE.Demo } catch (Exception ex) { - ThrowNCException(ex); + return ThrowNCException(ex); } + + return NO_ERROR; } - public override void FILES_CopyProgram(string partProgramPath, string newPartProgramPath, bool failIfExist) + public override CmsError FILES_CopyProgram(string partProgramPath, string newPartProgramPath, bool failIfExist) { // Check if the NC Demo is Connected - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; try { @@ -813,14 +938,18 @@ namespace CMS_CORE.Demo } catch (Exception ex) { - ThrowNCException(ex); + return ThrowNCException(ex); } + + return NO_ERROR; } - public override void FILES_DeleteProgram(string partProgramPath, string partProgramName) + public override CmsError FILES_DeleteProgram(string partProgramPath, string partProgramName) { // Check if the NC Demo is Connected - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; try { @@ -828,19 +957,23 @@ namespace CMS_CORE.Demo } catch (Exception ex) { - ThrowNCException(ex); + return ThrowNCException(ex); } + + return NO_ERROR; } - #endregion - + #endregion + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #region Subordinate Private Functions //Check if NC is connected - private void CheckConnection() + private CmsError CheckConnection() { if (!NC_IsConnected()) - throw new Nc_Exception(getError(NOT_CONNECTED_ERROR)); + return NOT_CONNECTED_ERROR; + + return NO_ERROR; } //Manage the Languages @@ -855,50 +988,37 @@ namespace CMS_CORE.Demo } //Manage the Exception Launch - private void ThrowNCException(Exception ex) + private CmsError ThrowNCException(Exception ex) { if (!(ex is Nc_Exception)) Connected = false; //Catch the .Net exceptions if (ex is EndpointNotFoundException) - throw new Nc_Exception("NC not found: " + ex.Message); + return NOT_CONNECTED_ERROR; else - throw new Nc_Exception("NC Comunication Error: " + ex.Message); - } - - // Convert the internal error in a readable-String error - private String getError(uint CMSError) - { - String ErrororOwner = ""; - if (CMSError != 0) - { - ErrororOwner = "CMS-Core-Error: "; - switch (CMSError) - { - case NOT_CONNECTED_ERROR: return ErrororOwner + "Nc not Connected"; - case PROC_NOT_FOUND_ERROR: return ErrororOwner + "Process Id not found"; - case FUNC_NOTALL_NC_ERROR: return ErrororOwner + "Function not allowed for this type of NC"; - case BIT_NOT_IN_RANGE_ERROR: return ErrororOwner + "Bit-number must be between 0 and 7"; - case INTERNAL_ERROR: return ErrororOwner + "Internal function error"; - case INCORRECT_PARAMETERS_ERROR: return ErrororOwner + "Incorrect Parameters error"; - } - } - return ErrororOwner + "Generic Error On Function"; + return new CmsError(INTERNAL_ERROR, ex.Message); } //Check Bit In Range - private void CheckBitRange(int bitnum) + private CmsError CheckBitRange(int bitnum) { if (bitnum < 0 || bitnum > 7) - throw new Nc_Exception(getError(BIT_NOT_IN_RANGE_ERROR)); + return BIT_NOT_IN_RANGE_ERROR; + + return NO_ERROR; } - public override void PROC_RPPName(ushort ProcNumber, ref string Name) + public override CmsError PROC_RPPName(ushort ProcNumber, ref string Name) { - throw new NotImplementedException(); + return FUNCTION_NOT_ALLOWED_ERROR; } + // Create and return CmsError object + private CmsError GetError(uint CMSError, string message) + { + return new CmsError(CMSError, message); + } #endregion diff --git a/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs b/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs index e19fa04..6610e71 100644 --- a/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs +++ b/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs @@ -41,7 +41,7 @@ namespace CMS_CORE.Fanuc * Remote Port of the Nc * Send/Recieve timeout connection [mS] * */ - public Nc_Fanuc(String IpAddress, ushort RemotePort,ushort ConnectionTimeOut) + public Nc_Fanuc(String IpAddress, ushort RemotePort, ushort ConnectionTimeOut) { //Set internal valiables Connected = false; @@ -57,63 +57,69 @@ namespace CMS_CORE.Fanuc //Connect Method - public override void NC_Connect() + public override CmsError NC_Connect() { - short nReturn; - short ActivePath; - ushort TempLibHandle; - short i; + short nReturn; + short ActivePath; + ushort TempLibHandle; + short i; //Try to connect to The NC nReturn = Focas1.cnc_allclibhndl3(Ip, Port, TimeOut, out TempLibHandle); if (nReturn != 0) - ThrowNCException(NC_PROD_ERROR,nReturn); + return GetError(NC_PROD_ERROR, nReturn); else nLibHandle.Add(TempLibHandle); //Read the Actual Paths nReturn = Focas1.cnc_getpath(nLibHandle[0], out ActivePath, out Cnc_NumPath); if (nReturn != 0) - ThrowNCException(NC_PROD_ERROR, nReturn); - + return GetError(NC_PROD_ERROR, nReturn); + //Setup all Paths - for(i=0;i< Cnc_NumPath; i++) + for (i = 0; i < Cnc_NumPath; i++) { if (i > 0) { nReturn = Focas1.cnc_allclibhndl3(Ip, Port, TimeOut, out TempLibHandle); if (nReturn != 0) - ThrowNCException(NC_PROD_ERROR, nReturn); + return GetError(NC_PROD_ERROR, nReturn); else nLibHandle.Add(TempLibHandle); } - nReturn = Focas1.cnc_setpath(nLibHandle[i], (short) (i+1) ); + nReturn = Focas1.cnc_setpath(nLibHandle[i], (short)(i + 1)); if (nReturn != 0) - ThrowNCException(NC_PROD_ERROR, nReturn); + return GetError(NC_PROD_ERROR, nReturn); } //Setup the "Connected" value to TRUE Connected = true; + + return NO_ERROR; } //Disconnect Method - public override void NC_Disconnect() + public override CmsError NC_Disconnect() { - short nReturn; - - if(Connected) + if (Connected) + { + short nReturn; + //If is connected -> Disconncet foreach (ushort handle in nLibHandle) { - nReturn = Focas1.cnc_freelibhndl(handle); + nReturn = Focas1.cnc_freelibhndl(handle); } - //Setup the "Connected" value to FALSE - Connected = false; + //Setup the "Connected" value to FALSE + Connected = false; + } + + return NO_ERROR; } @@ -124,75 +130,93 @@ namespace CMS_CORE.Fanuc #region High level methods //Get the NC Language - public override void NC_RLanguage(ref CultureInfo Language) - { - //Check if the NC is Connected - CheckConnection(); - - ReadStaticNCData(); + public override CmsError NC_RLanguage(ref CultureInfo Language) + { + // Read static data + CmsError cmsError = ReadStaticNCData(); + if (cmsError.errorCode != OK) + return cmsError; + Language = ConvertToSTEPLanguage(FanucLanguage); + + return NO_ERROR; } //Get the NC Serial Number - public override void NC_RSerialNumber(ref string SN) + public override CmsError NC_RSerialNumber(ref string SN) { - //Check if the NC is Connected - CheckConnection(); + // Read static data + CmsError cmsError = ReadStaticNCData(); + if (cmsError.errorCode != OK) + return cmsError; - ReadStaticNCData(); SN = Cnc_SeriesNum; + + return NO_ERROR; } //Get the NC Software Version - public override void NC_RSoftwareVersion(ref string SWV) + public override CmsError NC_RSoftwareVersion(ref string SWV) { - //Check if the NC is Connected - CheckConnection(); + // Read static data + CmsError cmsError = ReadStaticNCData(); + if (cmsError.errorCode != OK) + return cmsError; - ReadStaticNCData(); SWV = Cnc_SftVersion; + + return NO_ERROR; } //Get the NC model Name - public override void NC_RModelName(ref string ModelName) + public override CmsError NC_RModelName(ref string ModelName) { - //Check if the NC is Connected - CheckConnection(); + // Read static data + CmsError cmsError = ReadStaticNCData(); + if (cmsError.errorCode != OK) + return cmsError; - ReadStaticNCData(); ModelName = Cnc_name; + + return NO_ERROR; } //Get the processes-count configurated - public override void NC_RProcessesNum(ref ushort ProcNumber) + public override CmsError NC_RProcessesNum(ref ushort ProcNumber) { - //Check if the NC is Connected - CheckConnection(); + //Read static data + CmsError cmsError = ReadStaticNCData(); + if (cmsError.errorCode != OK) + return cmsError; - ReadStaticNCData(); - ProcNumber = (ushort) Cnc_NumPath; + ProcNumber = (ushort)Cnc_NumPath; + + return NO_ERROR; } //Get the NC Time - public override void NC_RDateTime(ref DateTime ActualTime) + public override CmsError NC_RDateTime(ref DateTime ActualTime) { + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; + + Focas1.IODBTIMER TimerDate = new Focas1.IODBTIMER(); Focas1.IODBTIMER TimerTime = new Focas1.IODBTIMER(); short nReturn = 0; - //Check if the NC is Connected - CheckConnection(); - //Setup the IODBTIMER TimerDate.type = 0; TimerTime.type = 1; @@ -202,94 +226,123 @@ namespace CMS_CORE.Fanuc //Throw Exception if there's an error if (nReturn != 0) - ThrowNCException(NC_PROD_ERROR, nReturn); + return GetError(NC_PROD_ERROR, nReturn); //Execute the method nReturn = Focas1.cnc_gettimer(nLibHandle[0], TimerTime); //Throw Exception if there's an error if (nReturn != 0) - ThrowNCException(NC_PROD_ERROR, nReturn); - + return GetError(NC_PROD_ERROR, nReturn); + //Setup the out value ActualTime = new DateTime(TimerDate.date.year, TimerDate.date.month, TimerDate.date.date, TimerTime.time.hour, TimerTime.time.minute, TimerTime.time.second); + return NO_ERROR; } //Get the Machine Number - public override void NC_RMachineNumber(ref string MachNumber) + public override CmsError NC_RMachineNumber(ref string MachNumber) { ushort Value = 0; - //Check if the NC is Connected - CheckConnection(); + // Read word + CmsError cmsError = MEM_RWWord(R, UNDEF_PROC, MATR_MACCH_FANUC.MemType, MATR_MACCH_FANUC.Address, ref Value); + if (cmsError.errorCode != OK) + return cmsError; - MEM_RWWord(R, UNDEF_PROC, MATR_MACCH_FANUC.MemType, MATR_MACCH_FANUC.Address, ref Value); MachNumber = Value.ToString(); + + return NO_ERROR; } //Get the process status - public override void PROC_RStatus(ushort Number, ref PROC_Status 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 - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + 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[GetHandleIndexFromPath(Number)], StatInfo); + nReturn = Focas1.cnc_statinfo(nLibHandle[path], StatInfo); //Throw Exception if there's an error if (nReturn != 0) - ThrowNCException(NC_PROD_ERROR, nReturn); + return GetError(NC_PROD_ERROR, nReturn); Status = ConverToSTEPStatus(StatInfo); + + return NO_ERROR; } //Get the process Mode - public override void PROC_RMode(ushort Number, ref PROC_Mode Mode) + public override CmsError PROC_RMode(ushort Number, ref PROC_Mode Mode) { Focas1.ODBST StatInfo = new Focas1.ODBST(); - short nReturn=0; + short nReturn = 0; //Check if the NC is Connected - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + 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[GetHandleIndexFromPath(Number)], StatInfo); + nReturn = Focas1.cnc_statinfo(nLibHandle[path], StatInfo); //Throw Exception if there's an error if (nReturn != 0) - ThrowNCException(NC_PROD_ERROR, nReturn); + return GetError(NC_PROD_ERROR, nReturn); Mode = ConverToSTEPMode(StatInfo); + + return NO_ERROR; } - + //Get the NC Alarms - public override void NC_RActiveAlarms(ref List Alarms) + public override CmsError NC_RActiveAlarms(ref List Alarms) { + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; + Focas1.ODBALMMSG2 Messg = new Focas1.ODBALMMSG2(); short nReturn = 0; short count = FANUC_MAXMSGCNC; - //Check if the NC is Connected - CheckConnection(); + // Get path index + short path = GetHandleIndexFromPath(1); + if (path < 0) + return PROC_NOT_FOUND_ERROR; //Execute the method - nReturn = Focas1.cnc_rdalmmsg2(nLibHandle[GetHandleIndexFromPath(1)], -1, ref count, Messg); + nReturn = Focas1.cnc_rdalmmsg2(nLibHandle[path], -1, ref count, Messg); //Throw Exception if there's an error if (nReturn != 0) - ThrowNCException(NC_PROD_ERROR, nReturn); + return GetError(NC_PROD_ERROR, nReturn); //Add Alarm in List Alarms.Clear(); @@ -313,95 +366,121 @@ namespace CMS_CORE.Fanuc Alarms.Add(Messg.msg9.alm_no + " " + Messg.msg9.alm_msg.Substring(0, Messg.msg9.msg_len)); if (count >= 10) Alarms.Add(Messg.msg10.alm_no + " " + Messg.msg10.alm_msg.Substring(0, Messg.msg10.msg_len)); + + return NO_ERROR; } //Get the process Alarms - public override void PROC_RActiveAlarms(ushort ProcNumber, ref List Alarms) + public override CmsError PROC_RActiveAlarms(ushort ProcNumber, ref List Alarms) { Alarms.Clear(); + + return NO_ERROR; } //Get PP Lines - public override void PROC_RPPLines(ushort ProcNumber, ref List Lines) + public override CmsError PROC_RPPLines(ushort ProcNumber, ref List Lines) { + + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; + short nReturn = 0; int linN; ushort Lenght = 256; short ReturnIndex = 1; - Char[] Chars= new Char[255]; + Char[] Chars = new Char[255]; String[] newLines; - //Check if the NC is Connected - CheckConnection(); + short path = GetHandleIndexFromPath(ProcNumber); + if (path < 0) + return PROC_NOT_FOUND_ERROR; //Execute the method - nReturn = Focas1.cnc_rdblkcount(nLibHandle[GetHandleIndexFromPath(ProcNumber)], out linN); - ReturnIndex = (short) linN; + nReturn = Focas1.cnc_rdblkcount(nLibHandle[path], out linN); + ReturnIndex = (short)linN; //Throw Exception if there's an error if (nReturn != 0) - ThrowNCException(NC_PROD_ERROR, nReturn); + return GetError(NC_PROD_ERROR, nReturn); + path = GetHandleIndexFromPath(ProcNumber); + if (path < 0) + return PROC_NOT_FOUND_ERROR; //Execute the method - nReturn = Focas1.cnc_rdexecprog(nLibHandle[GetHandleIndexFromPath(ProcNumber)],ref Lenght, out ReturnIndex, Chars); + 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) - ThrowNCException(NC_PROD_ERROR, nReturn); + return GetError(NC_PROD_ERROR, nReturn); //Setup the return values Lines.Clear(); foreach (String Line in newLines) Lines.Add(Line); + return NO_ERROR; } //Get Active PP Name - public override void PROC_RPPName(ushort ProcNumber, ref string Name) + public override CmsError PROC_RPPName(ushort ProcNumber, ref string Name) { + + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; + short nReturn = 0; Focas1.ODBEXEPRG Prg = new Focas1.ODBEXEPRG(); ; - //Check if the NC is Connected - CheckConnection(); + // Get path index + short path = GetHandleIndexFromPath(ProcNumber); + if (path < 0) + return PROC_NOT_FOUND_ERROR; //Execute the method - nReturn = Focas1.cnc_exeprgname(nLibHandle[GetHandleIndexFromPath(ProcNumber)], Prg); + nReturn = Focas1.cnc_exeprgname(nLibHandle[path], Prg); //Throw Exception if there's an error if (nReturn != 0) - ThrowNCException(NC_PROD_ERROR, nReturn); + return GetError(NC_PROD_ERROR, nReturn); Name = new String(Prg.name).Replace("\0", String.Empty); + return NO_ERROR; } //Get the PMC Messages - public override void PLC_RActiveMessages(ref List Alarms) + public override CmsError PLC_RActiveMessages(ref List Alarms) { + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; + Focas1.OPMSG3 Messg = new Focas1.OPMSG3(); short nReturn = 0; short count = FANUC_MAXMSGPMC; - //Check if the NC is Connected - CheckConnection(); - //Execute the method nReturn = Focas1.cnc_rdopmsg3(nLibHandle[0], -1, ref count, Messg); //Throw Exception if there's an error if (nReturn != 0) - ThrowNCException(NC_PROD_ERROR, nReturn); + return GetError(NC_PROD_ERROR, nReturn); //Add Alarm in List Alarms.Clear(); @@ -415,27 +494,36 @@ namespace CMS_CORE.Fanuc Alarms.Add(Messg.msg4.datano + " " + Messg.msg4.data); if (count >= 5 && Messg.msg5.datano >= 0) Alarms.Add(Messg.msg5.datano + " " + Messg.msg5.data); + + return NO_ERROR; } //Get the Inrpolated position - public override void AXES_RInterpPosition(ushort ProcNumber, ref Dictionary Axes) + public override CmsError AXES_RInterpPosition(ushort ProcNumber, ref Dictionary Axes) { + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; + Focas1.ODBPOS axisFan = new Focas1.ODBPOS(); short nReturn; short i; short NumAxes = Focas1.MAX_AXIS; - //Check if the NC is Connected - CheckConnection(); + // Get path index + short path = GetHandleIndexFromPath(ProcNumber); + if (path < 0) + return PROC_NOT_FOUND_ERROR; //Execute the method - nReturn = Focas1.cnc_rdposition(nLibHandle[GetHandleIndexFromPath(ProcNumber)], FANUC_RELATIVEPOS, ref NumAxes, axisFan); + nReturn = Focas1.cnc_rdposition(nLibHandle[path], FANUC_RELATIVEPOS, ref NumAxes, axisFan); //Throw Exception if there's an error if (nReturn != 0) - ThrowNCException(NC_PROD_ERROR, nReturn); + return GetError(NC_PROD_ERROR, nReturn); //If an axis goes out from Process Clear the List if (Axes.Count > NumAxes) @@ -444,19 +532,19 @@ namespace CMS_CORE.Fanuc } //Fill all the List - for(i=1;i<=NumAxes; i++) + for (i = 1; i <= NumAxes; i++) { switch (i) { - case 1 : ReadRelativeAxisPos(axisFan.p1.rel, ref Axes); break; - case 2 : ReadRelativeAxisPos(axisFan.p2.rel, ref Axes); break; - case 3 : ReadRelativeAxisPos(axisFan.p3.rel, ref Axes); break; - case 4 : ReadRelativeAxisPos(axisFan.p4.rel, ref Axes); break; - case 5 : ReadRelativeAxisPos(axisFan.p5.rel, ref Axes); break; - case 6 : ReadRelativeAxisPos(axisFan.p6.rel, ref Axes); break; - case 7 : ReadRelativeAxisPos(axisFan.p7.rel, ref Axes); break; - case 8 : ReadRelativeAxisPos(axisFan.p8.rel, ref Axes); break; - case 9 : ReadRelativeAxisPos(axisFan.p9.rel, ref Axes); break; + case 1: ReadRelativeAxisPos(axisFan.p1.rel, ref Axes); break; + case 2: ReadRelativeAxisPos(axisFan.p2.rel, ref Axes); break; + case 3: ReadRelativeAxisPos(axisFan.p3.rel, ref Axes); break; + case 4: ReadRelativeAxisPos(axisFan.p4.rel, ref Axes); break; + case 5: ReadRelativeAxisPos(axisFan.p5.rel, ref Axes); break; + case 6: ReadRelativeAxisPos(axisFan.p6.rel, ref Axes); break; + case 7: ReadRelativeAxisPos(axisFan.p7.rel, ref Axes); break; + case 8: ReadRelativeAxisPos(axisFan.p8.rel, ref Axes); break; + case 9: ReadRelativeAxisPos(axisFan.p9.rel, ref Axes); break; case 10: ReadRelativeAxisPos(axisFan.p10.rel, ref Axes); break; case 11: ReadRelativeAxisPos(axisFan.p11.rel, ref Axes); break; case 12: ReadRelativeAxisPos(axisFan.p12.rel, ref Axes); break; @@ -482,27 +570,36 @@ namespace CMS_CORE.Fanuc case 32: ReadRelativeAxisPos(axisFan.p32.rel, ref Axes); break; } } + + return NO_ERROR; } //Get the Machine position - public override void AXES_RMachinePosition(ushort ProcNumber, ref Dictionary Axes) + public override CmsError AXES_RMachinePosition(ushort ProcNumber, ref Dictionary Axes) { + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; + Focas1.ODBPOS axisFan = new Focas1.ODBPOS(); short nReturn; short i; short NumAxes = Focas1.MAX_AXIS; - //Check if the NC is Connected - CheckConnection(); + // Get path index + short path = GetHandleIndexFromPath(ProcNumber); + if (path < 0) + return PROC_NOT_FOUND_ERROR; //Execute the method - nReturn = Focas1.cnc_rdposition(nLibHandle[GetHandleIndexFromPath(ProcNumber)], FANUC_MACHINEPOS, ref NumAxes, axisFan); + nReturn = Focas1.cnc_rdposition(nLibHandle[path], FANUC_MACHINEPOS, ref NumAxes, axisFan); //Throw Exception if there's an error if (nReturn != 0) - ThrowNCException(NC_PROD_ERROR, nReturn); + return GetError(NC_PROD_ERROR, nReturn); //If an axis goes out from Process Clear the List if (Axes.Count > NumAxes) @@ -549,27 +646,35 @@ namespace CMS_CORE.Fanuc case 32: ReadRelativeAxisPos(axisFan.p32.mach, ref Axes); break; } } + return NO_ERROR; } //Get the Distance To Go - public override void AXES_RDistanceToGo(ushort ProcNumber, ref Dictionary Axes) + public override CmsError AXES_RDistanceToGo(ushort ProcNumber, ref Dictionary Axes) { + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; + Focas1.ODBPOS axisFan = new Focas1.ODBPOS(); short nReturn; short i; short NumAxes = Focas1.MAX_AXIS; - //Check if the NC is Connected - CheckConnection(); + // Get path index + short path = GetHandleIndexFromPath(ProcNumber); + if (path < 0) + return PROC_NOT_FOUND_ERROR; //Execute the method nReturn = Focas1.cnc_rdposition(nLibHandle[GetHandleIndexFromPath(ProcNumber)], FANUC_DISTTOGO, ref NumAxes, axisFan); //Throw Exception if there's an error if (nReturn != 0) - ThrowNCException(NC_PROD_ERROR, nReturn); + return GetError(NC_PROD_ERROR, nReturn); //If an axis goes out from Process Clear the List if (Axes.Count > NumAxes) @@ -616,12 +721,14 @@ namespace CMS_CORE.Fanuc case 32: ReadRelativeAxisPos(axisFan.p32.dist, ref Axes); break; } } + + return NO_ERROR; } //Get the Programmed Position - public override void AXES_RProgrPosition(ushort ProcNumber, ref Dictionary Axes) + public override CmsError AXES_RProgrPosition(ushort ProcNumber, ref Dictionary Axes) { //In fanuc is not implemented, so i need to build it Dictionary ActualMach = new Dictionary(); @@ -629,11 +736,16 @@ namespace CMS_CORE.Fanuc KeyValuePair val; //Read the positions - AXES_RMachinePosition(ProcNumber, ref ActualMach); - AXES_RDistanceToGo(ProcNumber, ref ToGo); + CmsError cmsError = AXES_RMachinePosition(ProcNumber, ref ActualMach); + if (cmsError.errorCode != OK) + return cmsError; + + cmsError = AXES_RDistanceToGo(ProcNumber, ref ToGo); + if (cmsError.errorCode != OK) + return cmsError; //If it has the same size - if(ActualMach.Count == ToGo.Count) + if (ActualMach.Count == ToGo.Count) { //If an axis goes out from Process Clear the List if (Axes.Count > ActualMach.Count) @@ -641,7 +753,7 @@ namespace CMS_CORE.Fanuc Axes.Clear(); } - foreach (KeyValuePair axis in ActualMach) + foreach (KeyValuePair axis in ActualMach) { val = Axes.FirstOrDefault(X => X.Key == axis.Key); if (val.Key != null) @@ -651,13 +763,14 @@ namespace CMS_CORE.Fanuc } } else - ThrowNCException(INTERNAL_ERROR, 0); + return GetError(INTERNAL_ERROR, 0); + return NO_ERROR; } - public override void AXES_RFollowingError(ushort ProcNumber, ref Dictionary Axes) + public override CmsError AXES_RFollowingError(ushort ProcNumber, ref Dictionary Axes) { - ThrowNCException(FUNC_NOTALL_NC_ERROR, 0); + return FUNCTION_NOT_ALLOWED_ERROR; } @@ -670,125 +783,148 @@ namespace CMS_CORE.Fanuc //-------------------------------------------------------------------------------------------------------------------------- // PARAMS - + //Get NC Bit Parameter - public override void NC_RParam(short Index, short Bit, ref Boolean Value) + public override CmsError NC_RParam(short Index, short Bit, ref Boolean Value) { + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + 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); + byte mask = (byte)Math.Pow(2, Bit); - //Check if the NC is Connected - CheckConnection(); //Check if the Bit Number is Correct - CheckBitRange(Bit); + cmsError = CheckBitRange(Bit); + if (cmsError.errorCode != OK) + 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) - ThrowNCException(NC_PROD_ERROR, nReturn); + return GetError(NC_PROD_ERROR, nReturn); Value = ((outpar.cdata & mask) == mask) ? true : false; + + return NO_ERROR; } //Get NC Byte Parameter - public override void NC_RParam(short Index, ref byte Value) + public override CmsError NC_RParam(short Index, ref byte Value) { + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; + Focas1.IODBPSD_1 outpar = new Focas1.IODBPSD_1(); short nReturn; short axes_num = 0; short size = 5; - //Check if the NC is Connected - CheckConnection(); - //Execute the method nReturn = Focas1.cnc_rdparam(nLibHandle[0], Index, axes_num, size, outpar); //Throw Exception if there's an error if (nReturn != 0) - ThrowNCException(NC_PROD_ERROR, nReturn); + return GetError(NC_PROD_ERROR, nReturn); Value = outpar.cdata; + + return NO_ERROR; } //Get NC Word Parameter - public override void NC_RParam(short Index, ref short Value) + public override CmsError NC_RParam(short Index, ref short Value) { + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; + Focas1.IODBPSD_1 outpar = new Focas1.IODBPSD_1(); short nReturn; short axes_num = 0; short size = 6; - //Check if the NC is Connected - CheckConnection(); - //Execute the method nReturn = Focas1.cnc_rdparam(nLibHandle[0], Index, axes_num, size, outpar); //Throw Exception if there's an error if (nReturn != 0) - ThrowNCException(NC_PROD_ERROR, nReturn); + return GetError(NC_PROD_ERROR, nReturn); Value = outpar.idata; + + return NO_ERROR; } //Get NC DWord Parameter - public override void NC_RParam(short Index, ref int Value) + public override CmsError NC_RParam(short Index, ref int Value) { + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; + Focas1.IODBPSD_1 outpar = new Focas1.IODBPSD_1(); short nReturn; short axes_num = 0; short size = 8; - //Check if the NC is Connected - CheckConnection(); - //Execute the method nReturn = Focas1.cnc_rdparam(nLibHandle[0], Index, axes_num, size, outpar); //Throw Exception if there's an error if (nReturn != 0) - ThrowNCException(NC_PROD_ERROR, nReturn); + return GetError(NC_PROD_ERROR, nReturn); Value = outpar.ldata; + + return NO_ERROR; } //Get NC Real Parameter - public override void NC_RParam(short Index, ref double Value) + public override CmsError NC_RParam(short Index, ref double Value) { + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; + Focas1.IODBPSD_2 outpar = new Focas1.IODBPSD_2(); short nReturn; short axes_num = 0; short size = 12; double Divider = 1; - //Check if the NC is Connected - CheckConnection(); - //Execute the method nReturn = Focas1.cnc_rdparam(nLibHandle[0], Index, axes_num, size, outpar); //Throw Exception if there's an error if (nReturn != 0) - ThrowNCException(NC_PROD_ERROR, nReturn); + return GetError(NC_PROD_ERROR, nReturn); Divider = Math.Pow(10, outpar.rdata.dec_val); Value = outpar.rdata.prm_val / Divider; + + return NO_ERROR; } @@ -797,23 +933,20 @@ namespace CMS_CORE.Fanuc // BOOL (NC) <-> BOOL (.NET) ToDo //Read-Write a Boolean-Value inside the NC. - public override void 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); + if (cmsError.errorCode != OK) + return cmsError; + byte ReadValue = 0; byte pow = (byte)Math.Pow(2, MemBit); - //Check if the NC is Connected - CheckConnection(); - - //Check if the Memory area is corrected - CheckMemoryArea(MemType.ToString()); - - //Check if the Bit Number is Correct - CheckBitRange(MemBit); - //Read the Byte where is the bit - MEM_RWByte(R, Process, MemType, MemIndex, 0, ref ReadValue); - + cmsError = MEM_RWByte(R, Process, MemType, MemIndex, 0, ref ReadValue); + if (cmsError.errorCode != OK) + return cmsError; //If i have to read -> Read the Bit if (bWrite == R) { @@ -823,12 +956,14 @@ namespace CMS_CORE.Fanuc else { if (Value) - ReadValue = (byte) (ReadValue | (1 << MemBit)); + ReadValue = (byte)(ReadValue | (1 << MemBit)); else ReadValue = (byte)(ReadValue & ~(1 << MemBit)); - - MEM_RWByte(W, Process, MemType, MemIndex,0, ref ReadValue); + + MEM_RWByte(W, Process, MemType, MemIndex, 0, ref ReadValue); } + + return NO_ERROR; } @@ -837,28 +972,35 @@ namespace CMS_CORE.Fanuc // BYTE (NC) <-> BYTE (.NET) //Read-Write a Byte-Value inside the NC. In writing-mode the field "Number" is not required - public override void 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 }; - //Check if the NC is Connected - CheckConnection(); - - //Check if the Memory area is corrected - CheckMemoryArea(MemType.ToString()); - //uses the List method with one-element list - MEM_RWByteList(bWrite, Process, MemType, MemIndex, 0, 1, ref Values); + CmsError cmsError = MEM_RWByteList(bWrite, Process, MemType, MemIndex, 0, 1, ref Values); + if (cmsError.errorCode != OK) + return cmsError; Value = Values.First(); + return NO_ERROR; } //Read-Write a Byte-Value-List inside the NC. In writing-mode the field "Number" is not required - public override void 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(); + if (cmsError.errorCode != OK) + return cmsError; + + //Check if the Memory area is corrected + cmsError = CheckMemoryArea(MemType.ToString()); + if (cmsError.errorCode != OK) + return cmsError; + //The maximum number of variables readed/writed at the same time is 5 //I have to iterate it Focas1.IODBPMC0 Io = new Focas1.IODBPMC0(); @@ -873,12 +1015,6 @@ namespace CMS_CORE.Fanuc int j = 0; int k = 0; - //Check if the NC is Connected - CheckConnection(); - - //Check if the Memory area is corrected - CheckMemoryArea(MemType.ToString()); - //Setup the 'Value' variable if (bWrite) Number = Value.Count(); @@ -887,11 +1023,11 @@ namespace CMS_CORE.Fanuc //Setup the iterations LastNumber = (Number % FANUC_MAXNVAR); - Iterat = Number /FANUC_MAXNVAR; + Iterat = Number / FANUC_MAXNVAR; //Iterates - for (int i=0; i<=Iterat; i++) + for (int i = 0; i <= Iterat; i++) { //Set the variables-index to iterate ActualStartIndex = MemIndex + (i * FANUC_MAXNVAR); @@ -901,7 +1037,7 @@ namespace CMS_CORE.Fanuc ActualEndIndex = ActualStartIndex + LastNumber - 1; else ActualEndIndex = ActualStartIndex + FANUC_MAXNVAR - 1; - + //Set the variables-numbers to iterate ActualNumber = (ActualEndIndex - ActualStartIndex + 1); //Set the variables-number Fanuc @@ -910,31 +1046,33 @@ namespace CMS_CORE.Fanuc //Set the IODBPMC if you have to write if (bWrite) { - Io.datano_s = (short) ActualStartIndex; - Io.datano_e = (short) ActualEndIndex; - Io.type_a = (short) MemType; + Io.datano_s = (short)ActualStartIndex; + Io.datano_e = (short)ActualEndIndex; + Io.type_a = (short)MemType; Io.type_d = (short)FANUC_DType.BYTE; //Fill the cdata j = (i * FANUC_MAXNVAR); - for(k=0;k< ActualNumber;k++) - Io.cdata[k] = Value[j+k]; + for (k = 0; k < ActualNumber; k++) + Io.cdata[k] = Value[j + k]; } //Execute the method - if (!bWrite) + if (!bWrite) nReturn = Focas1.pmc_rdpmcrng(nLibHandle[0], (short)MemType, (short)FANUC_DType.BYTE, (ushort)ActualStartIndex, (ushort)ActualEndIndex, (ushort)FanucNumber, Io); else nReturn = Focas1.pmc_wrpmcrng(nLibHandle[0], (ushort)FanucNumber, Io); //Throw Exception if there's an error if (nReturn != 0) - ThrowNCException(NC_PROD_ERROR, nReturn); + return GetError(NC_PROD_ERROR, nReturn); //Else add the variables in the List (is is a read-statement) else if (!bWrite) Value.AddRange(Io.cdata.Take(ActualNumber).ToArray()); } + return NO_ERROR; + } @@ -943,26 +1081,24 @@ namespace CMS_CORE.Fanuc // DWORD (NC) <-> INT (.NET) //Write a Int-Value inside the NC. In writing-mode the field "Number" is not required - public override void 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) { List ListValue = new List() { Value }; - //Check if the NC is Connected - CheckConnection(); - - //Check if the Memory area is corrected - CheckMemoryArea(MemType.ToString()); - //uses the List method with one-element list - MEM_RWIntegerList(bWrite, Process, MemType, MemIndex, 1, ref ListValue); + CmsError cmsError = MEM_RWIntegerList(bWrite, Process, MemType, MemIndex, 1, ref ListValue); + if (cmsError.errorCode != OK) + 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 void 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 Focas1.IODBPMC2 Io = new Focas1.IODBPMC2(); @@ -978,10 +1114,14 @@ namespace CMS_CORE.Fanuc int k = 0; //Check if the NC is Connected - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; //Check if the Memory area is corrected - CheckMemoryArea(MemType.ToString()); + cmsError = CheckMemoryArea(MemType.ToString()); + if (cmsError.errorCode != OK) + return cmsError; //Setup the 'Value' variable if (bWrite) @@ -1006,7 +1146,7 @@ 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 @@ -1033,12 +1173,14 @@ namespace CMS_CORE.Fanuc //Throw Exception if there's an error if (nReturn != 0) - ThrowNCException(NC_PROD_ERROR, nReturn); + return GetError(NC_PROD_ERROR, nReturn); //Else add the variables in the List (is is a read-statement) else if (!bWrite) Value.AddRange(Io.ldata.Take(ActualNumber).ToArray()); } + + return NO_ERROR; } @@ -1047,46 +1189,41 @@ namespace CMS_CORE.Fanuc // DWORD (NC) <-> UINT (.NET) //Write a DWord-Value inside the NC. In writing-mode the field "Number" is not required - public override void 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) { List ListValue = new List() { Value }; - //Check if the NC is Connected - CheckConnection(); - - //Check if the Memory area is corrected - CheckMemoryArea(MemType.ToString()); - //uses the List method with one-element list - MEM_RWDWordList(bWrite, Process, MemType, MemIndex, 1, ref ListValue); + CmsError cmsError = MEM_RWDWordList(bWrite, Process, MemType, MemIndex, 1, ref ListValue); + if (cmsError.errorCode != OK) + 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 void 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(); - //Check if the NC is Connected - CheckConnection(); - - //Check if the Memory area is corrected - CheckMemoryArea(MemType.ToString()); - //If i have to write convert the INT list into (2x) WORD if (bWrite) WordValues = Values.Select(i => (int)i).ToList(); //Exetute the function - MEM_RWIntegerList(bWrite, Process, MemType, MemIndex, Number, ref WordValues); + CmsError cmsError = MEM_RWIntegerList(bWrite, Process, MemType, MemIndex, Number, ref WordValues); + if (cmsError.errorCode != OK) + return cmsError; //If i have to read, convert the WORD list into INT if (!bWrite) Values = WordValues.Select(i => (uint)i).ToList(); + return NO_ERROR; } @@ -1095,27 +1232,35 @@ namespace CMS_CORE.Fanuc // WORD (NC) <-> SHORT (.NET) //Write a Short-Value inside the NC. In writing-mode the field "Number" is not required - public override void 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) { List ListValue = new List() { Value }; - //Check if the NC is Connected - CheckConnection(); - - //Check if the Memory area is corrected - CheckMemoryArea(MemType.ToString()); - //uses the List method with one-element list - MEM_RWShortList(bWrite, Process, MemType, MemIndex, 1, ref ListValue); + CmsError cmsError = MEM_RWShortList(bWrite, Process, MemType, MemIndex, 1, ref ListValue); + if (cmsError.errorCode != OK) + 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 void 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(); + if (cmsError.errorCode != OK) + return cmsError; + + //Check if the Memory area is corrected + cmsError = CheckMemoryArea(MemType.ToString()); + if (cmsError.errorCode != OK) + return cmsError; + //The maximum number of variables readed/writed at the same time is 5 //I have to iterate it Focas1.IODBPMC1 Io = new Focas1.IODBPMC1(); @@ -1130,12 +1275,6 @@ namespace CMS_CORE.Fanuc int j = 0; int k = 0; - //Check if the NC is Connected - CheckConnection(); - - //Check if the Memory area is corrected - CheckMemoryArea(MemType.ToString()); - //Setup the 'Value' variable if (bWrite) Number = Value.Count(); @@ -1186,12 +1325,14 @@ namespace CMS_CORE.Fanuc //Throw Exception if there's an error if (nReturn != 0) - ThrowNCException(NC_PROD_ERROR, nReturn); + return GetError(NC_PROD_ERROR, nReturn); //Else add the variables in the List (is is a read-statement) else if (!bWrite) Value.AddRange(Io.idata.Take(ActualNumber).ToArray()); } + + return NO_ERROR; } @@ -1200,45 +1341,41 @@ namespace CMS_CORE.Fanuc // WORD (NC) <-> SHORT (.NET) //Write a Word-Value inside the NC. In writing-mode the field "Number" is not required - public override void 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) { List ListValue = new List() { Value }; - //Check if the NC is Connected - CheckConnection(); - - //Check if the Memory area is corrected - CheckMemoryArea(MemType.ToString()); - //uses the List method with one-element list - MEM_RWWordList(bWrite, Process, MemType, MemIndex, 1, ref ListValue); + CmsError cmsError = MEM_RWWordList(bWrite, Process, MemType, MemIndex, 1, ref ListValue); + if (cmsError.errorCode != OK) + 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 void 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(); - //Check if the NC is Connected - CheckConnection(); - - //Check if the Memory area is corrected - CheckMemoryArea(MemType.ToString()); - //If i have to write convert the INT list into (2x) WORD if (bWrite) WordValues = Values.Select(i => (short)i).ToList(); //Exetute the function - MEM_RWShortList(bWrite, Process, MemType, MemIndex, Number, ref WordValues); + CmsError cmsError = MEM_RWShortList(bWrite, Process, MemType, MemIndex, Number, ref WordValues); + if (cmsError.errorCode != OK) + return cmsError; //If i have to read, convert the WORD list into INT if (!bWrite) Values = WordValues.Select(i => (ushort)i).ToList(); + + return NO_ERROR; } @@ -1246,58 +1383,58 @@ namespace CMS_CORE.Fanuc //-------------------------------------------------------------------------------------------------------------------------- // Siemens Version of Memory-Access Methods - public override void 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) { - MEM_RWBoolean(bWrite, Process, MemType, MemIndex, MemBit, ref Value); + return MEM_RWBoolean(bWrite, Process, MemType, MemIndex, MemBit, ref Value); } - public override void 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) { - MEM_RWByte(bWrite, Process, MemType, MemIndex, MemByte, ref Value); + return MEM_RWByte(bWrite, Process, MemType, MemIndex, MemByte, ref Value); } - public override void 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) { - MEM_RWWord(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); + return MEM_RWWord(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); } - public override void 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) { - MEM_RWShort(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); + return MEM_RWShort(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); } - public override void 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) { - MEM_RWDWord(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); + return MEM_RWDWord(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); } - public override void 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) { - MEM_RWInteger(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); + return MEM_RWInteger(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); } - public override void 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) { - MEM_RWByteList(bWrite, Process, MemType, MemIndex, MemByteStart, Number, ref Value); + return MEM_RWByteList(bWrite, Process, MemType, MemIndex, MemByteStart, Number, ref Value); } - public override void 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) { - MEM_RWWordList(bWrite, Process, MemType, MemIndex, Number, ref Value); + return MEM_RWWordList(bWrite, Process, MemType, MemIndex, Number, ref Value); } - public override void 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) { - MEM_RWShortList(bWrite, Process, MemType, MemIndex, Number, ref Value); + return MEM_RWShortList(bWrite, Process, MemType, MemIndex, Number, ref Value); } - public override void 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) { - MEM_RWDWordList(bWrite, Process, MemType, MemIndex, Number, ref Value); + return MEM_RWDWordList(bWrite, Process, MemType, MemIndex, Number, ref Value); } - public override void 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) { - MEM_RWIntegerList(bWrite, Process, MemType, MemIndex, Number, ref Value); + return MEM_RWIntegerList(bWrite, Process, MemType, MemIndex, Number, ref Value); } @@ -1307,12 +1444,15 @@ namespace CMS_CORE.Fanuc /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #region File Management - public override void FILES_RProgramToFile(string partProgramPath, FileStream localFile) + public override CmsError FILES_RProgramToFile(string partProgramPath, FileStream localFile) { string partProgramContent = ""; // Read NC part program content - ReadPartProgramContent(partProgramPath, ref partProgramContent); + CmsError cmsError = ReadPartProgramContent(partProgramPath, ref partProgramContent); + if (cmsError.errorCode != OK) + return cmsError; + try { // Write content into local file @@ -1320,13 +1460,15 @@ namespace CMS_CORE.Fanuc } catch (Exception ex) { - ThrowNCException(INTERNAL_ERROR, 0); + return GetError(INTERNAL_ERROR, 0); } + + return NO_ERROR; } - - public override void FILES_WProgramFromFile(string partProgramPath, FileStream localFile) + + public override CmsError FILES_WProgramFromFile(string partProgramPath, FileStream localFile) { string partProgramContent = ""; @@ -1337,23 +1479,25 @@ namespace CMS_CORE.Fanuc } catch (Exception ex) { - ThrowNCException(INTERNAL_ERROR, 0); + return GetError(INTERNAL_ERROR, 0); } - WritePartProgramContent(partProgramPath, partProgramContent); - } + return WritePartProgramContent(partProgramPath, partProgramContent); + } - public override void FILES_CopyProgram(string partProgramPath, string newPartProgramPath, bool failIfExist) + public override CmsError FILES_CopyProgram(string partProgramPath, string newPartProgramPath, bool failIfExist) { //Check if the NC is Connected - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; short nReturn; // If the 2 path are the same - if(partProgramPath == newPartProgramPath) - ThrowNCException(NC_PROD_ERROR, 5); // TODO FIX + if (partProgramPath == newPartProgramPath) + return GetError(NC_PROD_ERROR, 5); // TODO FIX if (failIfExist) { @@ -1371,8 +1515,8 @@ namespace CMS_CORE.Fanuc // TODO // nReturn = Focas1.cnc_pdf_copy(nLibHandle[0], partProgramPath, newPartProgramPath); - - if(nReturn == 5) + + if (nReturn == 5) { Focas1.ODBERR errorDetails = new Focas1.ODBERR(); Focas1.cnc_getdtailerr(nLibHandle[0], errorDetails); @@ -1386,40 +1530,47 @@ namespace CMS_CORE.Fanuc ErrorHandler(NC_PROD_ERROR, nReturn); } } - else if(nReturn != 0) + else if (nReturn != 0) { - ThrowNCException(NC_PROD_ERROR, nReturn); + return GetError(NC_PROD_ERROR, nReturn); } - } + + return NO_ERROR; } - public override void FILES_DeleteProgram(string partProgramPath, string partProgramName) + public override CmsError FILES_DeleteProgram(string partProgramPath, string partProgramName) { //Check if the NC is Connected - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; short nReturn; - nReturn = Focas1.cnc_pdf_del(nLibHandle[0], partProgramPath + partProgramName); + nReturn = Focas1.cnc_pdf_del(nLibHandle[0], partProgramPath + partProgramName); ErrorHandler(NC_PROD_ERROR, nReturn); + + return NO_ERROR; } #endregion /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #region Subordinate Private Functions - private void ErrorHandler(uint errorClass, short exNum) + private CmsError ErrorHandler(uint errorClass, short exNum) { if (exNum != 0) - ThrowNCException(errorClass, exNum); + return GetError(errorClass, exNum); + + return NO_ERROR; } private void ReadRelativeAxisPos(Focas1.POSELM pos, ref Dictionary Axes) { //If is setted VISIBLE add to List - if(pos.disp != 0) + if (pos.disp != 0) { string AxName; double AxVal; @@ -1437,7 +1588,7 @@ namespace CMS_CORE.Fanuc Axes.Add(AxName, AxVal); } } - + //Convert to Step Language @@ -1445,16 +1596,16 @@ namespace CMS_CORE.Fanuc { switch (language) { - case 0 : return new CultureInfo("en"); - case 1 : return new CultureInfo("ja"); - case 2 : return new CultureInfo("de"); - case 3 : return new CultureInfo("fr"); - case 4 : return new CultureInfo("zh-CHT"); - case 5 : return new CultureInfo("it"); - case 6 : return new CultureInfo("ko"); - case 7 : return new CultureInfo("es"); - case 8 : return new CultureInfo("nl"); - case 9 : return new CultureInfo("da"); + case 0: return new CultureInfo("en"); + case 1: return new CultureInfo("ja"); + case 2: return new CultureInfo("de"); + case 3: return new CultureInfo("fr"); + case 4: return new CultureInfo("zh-CHT"); + case 5: return new CultureInfo("it"); + case 6: return new CultureInfo("ko"); + case 7: return new CultureInfo("es"); + case 8: return new CultureInfo("nl"); + case 9: return new CultureInfo("da"); case 10: return new CultureInfo("pt"); case 11: return new CultureInfo("pl"); case 12: return new CultureInfo("hu"); @@ -1466,17 +1617,17 @@ namespace CMS_CORE.Fanuc case 18: return new CultureInfo("bg"); case 19: return new CultureInfo("ro"); case 20: return new CultureInfo("sk"); - case 21: return new CultureInfo("fi"); + case 21: return new CultureInfo("fi"); default: return new CultureInfo("en"); } - + } //Manage the Status Process private PROC_Status ConverToSTEPStatus(Focas1.ODBST status) { - if(status.emergency != 0) + if (status.emergency != 0) return PROC_Status.EMERG; if (status.alarm != 0) @@ -1502,63 +1653,70 @@ namespace CMS_CORE.Fanuc { switch (status.aut) { - case 0: return PROC_Mode.MDI; - case 1: return PROC_Mode.AUTO; - case 2: return PROC_Mode.ERROR; - case 3: return PROC_Mode.EDIT; - case 4: return PROC_Mode.HANDLE; - case 5: return PROC_Mode.JOG; - case 6: return PROC_Mode.TEACH; - case 7: return PROC_Mode.TEACH; - case 8: return PROC_Mode.JOGINC; - case 9: return PROC_Mode.REF; + case 0: return PROC_Mode.MDI; + case 1: return PROC_Mode.AUTO; + case 2: return PROC_Mode.ERROR; + case 3: return PROC_Mode.EDIT; + case 4: return PROC_Mode.HANDLE; + case 5: return PROC_Mode.JOG; + case 6: return PROC_Mode.TEACH; + case 7: return PROC_Mode.TEACH; + case 8: return PROC_Mode.JOGINC; + case 9: return PROC_Mode.REF; case 10: return PROC_Mode.REMOTE; } return PROC_Mode.ERROR; } - + //Get the Right Process - private ushort GetHandleIndexFromPath(ushort Path) + private short GetHandleIndexFromPath(ushort Path) { //Check it is too big if (Path > Cnc_NumPath) - ThrowNCException(PROC_NOT_FOUND_ERROR,0); + return -1; //Check it is too small - if (Path <= 0 ) - ThrowNCException(PROC_NOT_FOUND_ERROR,0); + if (Path <= 0) + return -1; //Return - return (ushort)(Path - 1); + return (short)(Path - 1); } - + //Read Static Data - private void ReadStaticNCData() + private CmsError ReadStaticNCData() { + // Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; + short nReturn; Focas1.ODBSYS node = new Focas1.ODBSYS(); Focas1.ODBSYSEX nodeex = new Focas1.ODBSYSEX(); //Read oly one time every 10 seconds - if ( DateTime.Now - Last_Static_Read > new TimeSpan(NC_MIN_SEC_READ_STATIC_DATA * TimeSpan.TicksPerSecond)) + if (DateTime.Now - Last_Static_Read > new TimeSpan(NC_MIN_SEC_READ_STATIC_DATA * TimeSpan.TicksPerSecond)) { //Read Language from NC PARAM - NC_RParam( (short) PARAM_LING_FANUC.Address, ref FanucLanguage); + cmsError = NC_RParam((short)PARAM_LING_FANUC.Address, ref FanucLanguage); + if (cmsError.errorCode != OK) + return cmsError; //Execute the method nReturn = Focas1.cnc_sysinfo(nLibHandle[0], node); - + nReturn = Focas1.cnc_sysinfo_ex(nLibHandle[0], nodeex); //Throw Exception if there's an error if (nReturn != 0) - ThrowNCException(NC_PROD_ERROR, nReturn); + return GetError(NC_PROD_ERROR, nReturn); else { //Setup the name @@ -1570,55 +1728,60 @@ namespace CMS_CORE.Fanuc //Setup the Number Series Cnc_SeriesNum = new string(node.series); - Last_Static_Read = DateTime.Now; - + Last_Static_Read = DateTime.Now; } } + return NO_ERROR; } - //Manage the Exception Launch - private void ThrowNCException(uint Owner, short exNum) + private CmsError GetError(uint Owner, short exNum) { if (exNum == (short)Focas1.focas_ret.EW_SOCKET) NC_Disconnect(); - throw new Nc_Exception(getError(Owner,exNum)); + return new CmsError(Owner, GetErrorMessage(Owner, exNum)); } //Check if NC is connected - private void CheckConnection() + private CmsError CheckConnection() { if (!NC_IsConnected()) - throw new Nc_Exception(getError(NOT_CONNECTED_ERROR, 0)); + return NOT_CONNECTED_ERROR; + + return NO_ERROR; } - + //Check if Memory Area is corrected - private void CheckMemoryArea(String AreaName) + private CmsError CheckMemoryArea(String AreaName) { if (!AreaName.StartsWith(FANUC_MEMTYPE) && !AreaName.StartsWith(UNDEFINED_MEMTYPE)) - throw new Nc_Exception(getError(INCORRECT_PARAMETERS_ERROR, 0)); + return new CmsError(INCORRECT_PARAMETERS, GetErrorMessage(INCORRECT_PARAMETERS, 0)); + + return NO_ERROR; } //Check if NC is connected - private void CheckBitRange(int bitnum) + private CmsError CheckBitRange(int bitnum) { if (bitnum < 0 || bitnum > 7) - throw new Nc_Exception(getError(BIT_NOT_IN_RANGE_ERROR, 0)); + return BIT_NOT_IN_RANGE_ERROR; + + return NO_ERROR; } // Convert the internal Name var in Readable STEP Name - private String getName(char [] Cnc_Type, char[] Mt_Type) + private String getName(char[] Cnc_Type, char[] Mt_Type) { String name = "Fanuc "; switch (new String(Cnc_Type)) @@ -1640,10 +1803,12 @@ namespace CMS_CORE.Fanuc // Write Part program content - private void WritePartProgramContent(string partProgramPath, string partProgramContent) + private CmsError WritePartProgramContent(string partProgramPath, string partProgramContent) { //Check if the NC is Connected - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; short nReturn; @@ -1654,7 +1819,7 @@ namespace CMS_CORE.Fanuc ErrorHandler(NC_PROD_ERROR, nReturn); //int lenghtMax = fileData.Length; - System.Threading.Thread.Sleep(1000); + Thread.Sleep(1000); int lenght = partProgramContent.Length; // Write program nReturn = Focas1.cnc_download4(nLibHandle[0], ref lenght, partProgramContent); @@ -1666,15 +1831,19 @@ namespace CMS_CORE.Fanuc //Throw Exception if there's an error ErrorHandler(NC_PROD_ERROR, nReturn); + + return NO_ERROR; } // Read Part program content - private void ReadPartProgramContent(string partProgramPath, ref string partProgramContent) + private CmsError ReadPartProgramContent(string partProgramPath, ref string partProgramContent) { //Check if the NC is Connected - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; bool fileEnded = false; short nReturn; @@ -1715,7 +1884,7 @@ namespace CMS_CORE.Fanuc break; default: { - ThrowNCException(NC_PROD_ERROR, nReturn); + return GetError(NC_PROD_ERROR, nReturn); } break; } @@ -1727,65 +1896,57 @@ namespace CMS_CORE.Fanuc ErrorHandler(NC_PROD_ERROR, nReturn); partProgramContent = partProgramContent.Replace("\0", String.Empty); + + return NO_ERROR; } + //Manage the Exception Launch + private CmsError ManageException(Exception ex) + { + Connected = false; + return new CmsError(INTERNAL_ERROR, ex.Message); + } // Convert the internal error in a readable-String error - private String getError(uint CMSError, short Value) + private String GetErrorMessage(uint CMSError, short Value) { String ErrororOwner = ""; - if (CMSError != 0) + ErrororOwner = "Fanuc-Core-Error: "; + Focas1.focas_ret Val = (Focas1.focas_ret)Value; + switch (Val) { - ErrororOwner = "CMS-Core-Error: "; - switch (CMSError) - { - case NOT_CONNECTED_ERROR: return ErrororOwner + "Nc not Connected"; - case PROC_NOT_FOUND_ERROR: return ErrororOwner + "Process Id not found"; - case FUNC_NOTALL_NC_ERROR: return ErrororOwner + "Function not allowed for this type of NC"; - case BIT_NOT_IN_RANGE_ERROR: return ErrororOwner + "Bit-number must be between 0 and 7"; - case INTERNAL_ERROR: return ErrororOwner + "Internal function error"; - case INCORRECT_PARAMETERS_ERROR: return ErrororOwner + "Incorrect Parameters error"; - } - } - else - { - ErrororOwner = "Fanuc-Core-Error: "; - Focas1.focas_ret Val = (Focas1.focas_ret)Value; - switch (Val) - { - case Focas1.focas_ret.EW_PROTOCOL: return ErrororOwner + "protocol error"; - case Focas1.focas_ret.EW_SOCKET: return ErrororOwner + "Windows socket error"; - case Focas1.focas_ret.EW_NODLL: return ErrororOwner + "DLL not exist error"; - case Focas1.focas_ret.EW_BUS: return ErrororOwner + "bus error"; - case Focas1.focas_ret.EW_SYSTEM2: return ErrororOwner + "system error"; - case Focas1.focas_ret.EW_HSSB: return ErrororOwner + "hssb communication error"; - case Focas1.focas_ret.EW_HANDLE: return ErrororOwner + "Windows library handle error"; - case Focas1.focas_ret.EW_VERSION: return ErrororOwner + "CNC/PMC version missmatch"; - case Focas1.focas_ret.EW_UNEXP: return ErrororOwner + "abnormal error"; - case Focas1.focas_ret.EW_SYSTEM: return ErrororOwner + "system error"; - case Focas1.focas_ret.EW_PARITY: return ErrororOwner + "shared RAM parity error"; - case Focas1.focas_ret.EW_MMCSYS: return ErrororOwner + "emm386 or mmcsys install error"; - case Focas1.focas_ret.EW_RESET: return ErrororOwner + "reset or stop occured error"; - case Focas1.focas_ret.EW_BUSY: return ErrororOwner + "busy error"; - case Focas1.focas_ret.EW_FUNC: return ErrororOwner + "command prepare error / pmc not exist"; - case Focas1.focas_ret.EW_LENGTH: return ErrororOwner + "data block length error"; - case Focas1.focas_ret.EW_NUMBER: return ErrororOwner + "data number / address range error"; - case Focas1.focas_ret.EW_ATTRIB: return ErrororOwner + "data type / attribute error"; - case Focas1.focas_ret.EW_DATA: return ErrororOwner + "data error"; - case Focas1.focas_ret.EW_NOOPT: return ErrororOwner + "no option error"; - case Focas1.focas_ret.EW_PROT: return ErrororOwner + "write protect error"; - case Focas1.focas_ret.EW_OVRFLOW: return ErrororOwner + "memory overflow error"; - case Focas1.focas_ret.EW_PARAM: return ErrororOwner + "cnc parameter not correct error"; - case Focas1.focas_ret.EW_BUFFER: return ErrororOwner + "buffer error"; - case Focas1.focas_ret.EW_PATH: return ErrororOwner + "path error"; - case Focas1.focas_ret.EW_MODE: return ErrororOwner + "cnc mode error"; - case Focas1.focas_ret.EW_REJECT: return ErrororOwner + "execution rejected error"; - case Focas1.focas_ret.EW_DTSRVR: return ErrororOwner + "data server error"; - case Focas1.focas_ret.EW_ALARM: return ErrororOwner + "alarm has been occurred"; - case Focas1.focas_ret.EW_STOP: return ErrororOwner + "CNC is not running"; - case Focas1.focas_ret.EW_PASSWD: return ErrororOwner + "protection data error"; - } + case Focas1.focas_ret.EW_PROTOCOL: return ErrororOwner + "protocol error"; + case Focas1.focas_ret.EW_SOCKET: return ErrororOwner + "Windows socket error"; + case Focas1.focas_ret.EW_NODLL: return ErrororOwner + "DLL not exist error"; + case Focas1.focas_ret.EW_BUS: return ErrororOwner + "bus error"; + case Focas1.focas_ret.EW_SYSTEM2: return ErrororOwner + "system error"; + case Focas1.focas_ret.EW_HSSB: return ErrororOwner + "hssb communication error"; + case Focas1.focas_ret.EW_HANDLE: return ErrororOwner + "Windows library handle error"; + case Focas1.focas_ret.EW_VERSION: return ErrororOwner + "CNC/PMC version missmatch"; + case Focas1.focas_ret.EW_UNEXP: return ErrororOwner + "abnormal error"; + case Focas1.focas_ret.EW_SYSTEM: return ErrororOwner + "system error"; + case Focas1.focas_ret.EW_PARITY: return ErrororOwner + "shared RAM parity error"; + case Focas1.focas_ret.EW_MMCSYS: return ErrororOwner + "emm386 or mmcsys install error"; + case Focas1.focas_ret.EW_RESET: return ErrororOwner + "reset or stop occured error"; + case Focas1.focas_ret.EW_BUSY: return ErrororOwner + "busy error"; + case Focas1.focas_ret.EW_FUNC: return ErrororOwner + "command prepare error / pmc not exist"; + case Focas1.focas_ret.EW_LENGTH: return ErrororOwner + "data block length error"; + case Focas1.focas_ret.EW_NUMBER: return ErrororOwner + "data number / address range error"; + case Focas1.focas_ret.EW_ATTRIB: return ErrororOwner + "data type / attribute error"; + case Focas1.focas_ret.EW_DATA: return ErrororOwner + "data error"; + case Focas1.focas_ret.EW_NOOPT: return ErrororOwner + "no option error"; + case Focas1.focas_ret.EW_PROT: return ErrororOwner + "write protect error"; + case Focas1.focas_ret.EW_OVRFLOW: return ErrororOwner + "memory overflow error"; + case Focas1.focas_ret.EW_PARAM: return ErrororOwner + "cnc parameter not correct error"; + case Focas1.focas_ret.EW_BUFFER: return ErrororOwner + "buffer error"; + case Focas1.focas_ret.EW_PATH: return ErrororOwner + "path error"; + case Focas1.focas_ret.EW_MODE: return ErrororOwner + "cnc mode error"; + case Focas1.focas_ret.EW_REJECT: return ErrororOwner + "execution rejected error"; + case Focas1.focas_ret.EW_DTSRVR: return ErrororOwner + "data server error"; + case Focas1.focas_ret.EW_ALARM: return ErrororOwner + "alarm has been occurred"; + case Focas1.focas_ret.EW_STOP: return ErrororOwner + "CNC is not running"; + case Focas1.focas_ret.EW_PASSWD: return ErrororOwner + "protection data error"; } return ErrororOwner + "Generic Error On Function"; } diff --git a/CMS_CORE_Library/Nc.cs b/CMS_CORE_Library/Nc.cs index 842b8c8..ac6a67b 100644 --- a/CMS_CORE_Library/Nc.cs +++ b/CMS_CORE_Library/Nc.cs @@ -171,7 +171,7 @@ namespace CMS_CORE * Thrown when an internal or a library error occours * * */ - public abstract void NC_Connect(); + public abstract CmsError NC_Connect(); /** @@ -183,7 +183,7 @@ namespace CMS_CORE * Thrown when an internal or a library error occours * * */ - public abstract void NC_Disconnect(); + public abstract CmsError NC_Disconnect(); /** @@ -208,7 +208,7 @@ namespace CMS_CORE * Thrown when an internal or a library error occours * Reference of a DateTime Variable where data will be saved * */ - public abstract void NC_RDateTime(ref DateTime ActualTime); + public abstract CmsError NC_RDateTime(ref DateTime ActualTime); /** @@ -221,7 +221,7 @@ namespace CMS_CORE * Thrown when an internal or a library error occours * Reference of a String Variable where data will be saved * */ - public abstract void NC_RSerialNumber(ref String SN); + public abstract CmsError NC_RSerialNumber(ref String SN); /** * @@ -233,7 +233,7 @@ namespace CMS_CORE * Thrown when an internal or a library error occours * Reference of a String Variable where data will be saved * */ - public abstract void NC_RModelName(ref String ModelName); + public abstract CmsError NC_RModelName(ref String ModelName); /** * @@ -245,7 +245,7 @@ namespace CMS_CORE * Thrown when an internal or a library error occours * Reference of a String Variable where data will be saved * */ - public abstract void NC_RSoftwareVersion(ref String SWV); + public abstract CmsError NC_RSoftwareVersion(ref String SWV); /** * @@ -257,7 +257,7 @@ namespace CMS_CORE * Thrown when an internal or a library error occours * Reference of a String Variable where data will be saved * */ - public abstract void NC_RMachineNumber(ref String MachNumber); + public abstract CmsError NC_RMachineNumber(ref String MachNumber); /** * @@ -269,7 +269,7 @@ namespace CMS_CORE * Thrown when an internal or a library error occours * Reference of a ushort Variable where data will be saved * */ - public abstract void NC_RProcessesNum(ref ushort ProcNumber); + public abstract CmsError NC_RProcessesNum(ref ushort ProcNumber); /** * @@ -281,7 +281,7 @@ namespace CMS_CORE * Thrown when an internal or a library error occours * Reference of a CultureInfo Variable where data will be saved * */ - public abstract void NC_RLanguage(ref CultureInfo Language); + public abstract CmsError NC_RLanguage(ref CultureInfo Language); /** @@ -295,7 +295,7 @@ namespace CMS_CORE * Process to execute the action * Reference of a List of String Variables where data will be saved * */ - public abstract void NC_RActiveAlarms(ref List Alarms); + public abstract CmsError NC_RActiveAlarms(ref List Alarms); #endregion @@ -313,7 +313,7 @@ namespace CMS_CORE * Set the Bit to Read. (0..7) * Reference of a variable with Param values * */ - public abstract void NC_RParam(short Index, short Bit, ref Boolean Value); + public abstract CmsError NC_RParam(short Index, short Bit, ref Boolean Value); /** * Read Byte Parameter Machine (Not compatible for Axis Parameter (Multiple values in a parameter) @@ -325,7 +325,7 @@ namespace CMS_CORE * Index of the parameter * Reference of a variable with Param values * */ - public abstract void NC_RParam(short Index, ref byte Value); + public abstract CmsError NC_RParam(short Index, ref byte Value); /** * Read 2 Byte (Short) Parameter Machine (Not compatible for Axis Parameter (Multiple values in a parameter) @@ -337,7 +337,7 @@ namespace CMS_CORE * Index of the parameter * Reference of a variable with Param values * */ - public abstract void NC_RParam(short Index, ref short Value); + public abstract CmsError NC_RParam(short Index, ref short Value); /** * Read 4 Byte (Integer) Parameter Machine (Not compatible for Axis Parameter (Multiple values in a parameter) @@ -349,7 +349,7 @@ namespace CMS_CORE * Index of the parameter * Reference of a variable with Param values * */ - public abstract void NC_RParam(short Index, ref int Value); + public abstract CmsError NC_RParam(short Index, ref int Value); /** * Read Real Parameter Machine (Not compatible for Axis Parameter (Multiple values in a parameter) @@ -361,7 +361,7 @@ namespace CMS_CORE * Index of the parameter * Reference of a variable with Param values * */ - public abstract void NC_RParam(short Index, ref double Value); + public abstract CmsError NC_RParam(short Index, ref double Value); #endregion @@ -378,7 +378,7 @@ namespace CMS_CORE * Thrown when an internal or a library error occours * Reference of a List of String Variables where data will be saved * */ - public abstract void PLC_RActiveMessages(ref List Alarms); + public abstract CmsError PLC_RActiveMessages(ref List Alarms); #endregion @@ -397,7 +397,7 @@ namespace CMS_CORE * Process to execute the action * Reference of a PROC_Status Variable where data will be saved * */ - public abstract void PROC_RStatus(ushort ProcNumber, ref PROC_Status Status); + public abstract CmsError PROC_RStatus(ushort ProcNumber, ref PROC_Status Status); /** * @@ -411,7 +411,7 @@ namespace CMS_CORE * Process to execute the action * Reference of a PROC_Mode Variable where data will be saved * */ - public abstract void PROC_RMode(ushort ProcNumber, ref PROC_Mode Mode); + public abstract CmsError PROC_RMode(ushort ProcNumber, ref PROC_Mode Mode); /** @@ -425,7 +425,7 @@ namespace CMS_CORE * Process to execute the action * Reference of a List of String Variables where data will be saved * */ - public abstract void PROC_RActiveAlarms(ushort ProcNumber, ref List Alarms); + public abstract CmsError PROC_RActiveAlarms(ushort ProcNumber, ref List Alarms); /** @@ -439,7 +439,7 @@ namespace CMS_CORE * Process to execute the action * Reference of a List of String Variables where data will be saved * */ - public abstract void PROC_RPPLines(ushort ProcNumber, ref List Lines); + public abstract CmsError PROC_RPPLines(ushort ProcNumber, ref List Lines); /** @@ -453,7 +453,7 @@ namespace CMS_CORE * Process to execute the action * Reference of a String Variables where data will be saved * */ - public abstract void PROC_RPPName(ushort ProcNumber, ref String Name); + public abstract CmsError PROC_RPPName(ushort ProcNumber, ref String Name); #endregion @@ -472,7 +472,7 @@ namespace CMS_CORE * Process to execute the action * Reference of Dictionary "Key,Value" with: Key: Axis Name, Value: Position * */ - public abstract void AXES_RInterpPosition(ushort ProcNumber, ref Dictionary Axes); + public abstract CmsError AXES_RInterpPosition(ushort ProcNumber, ref Dictionary Axes); /** * @@ -486,7 +486,7 @@ namespace CMS_CORE * Process to execute the action * Reference of Dictionary "Key,Value" with: Key: Axis Name, Value: Position * */ - public abstract void AXES_RProgrPosition(ushort ProcNumber, ref Dictionary Axes); + public abstract CmsError AXES_RProgrPosition(ushort ProcNumber, ref Dictionary Axes); /** * @@ -499,7 +499,7 @@ namespace CMS_CORE * Process to execute the action * Reference of Dictionary "Key,Value" with: Key: Axis Name, Value: Position * */ - public abstract void AXES_RMachinePosition(ushort ProcNumber, ref Dictionary Axes); + public abstract CmsError AXES_RMachinePosition(ushort ProcNumber, ref Dictionary Axes); /** * @@ -512,7 +512,7 @@ namespace CMS_CORE * Process to execute the action * Reference of Dictionary "Key,Value" with: Key: Axis Name, Value: Position * */ - public abstract void AXES_RFollowingError(ushort ProcNumber, ref Dictionary Axes); + public abstract CmsError AXES_RFollowingError(ushort ProcNumber, ref Dictionary Axes); /** * @@ -525,7 +525,7 @@ namespace CMS_CORE * Process to execute the action * Reference of Dictionary "Key,Value" with: Key: Axis Name, Value: Position * */ - public abstract void AXES_RDistanceToGo(ushort ProcNumber, ref Dictionary Axes); + public abstract CmsError AXES_RDistanceToGo(ushort ProcNumber, ref Dictionary Axes); #endregion @@ -547,7 +547,7 @@ namespace CMS_CORE * Set the Bit to Read-Write. (0..7) * Reference to variable to read/Write * */ - public abstract void 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) @@ -564,7 +564,7 @@ namespace CMS_CORE * Set the Bit to Read-Write. (0..7) * Reference to variable to read/Write * */ - public abstract void 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); @@ -582,7 +582,7 @@ namespace CMS_CORE * Set to 1 if the Byte is the second of a WORD (only for OSAI Nc) * Reference to variable to read/Write * */ - public abstract void 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) @@ -599,7 +599,7 @@ namespace CMS_CORE * Set to 1 if the Byte is the second of a WORD (only for OSAI Nc) * Reference to variable to read/Write * */ - public abstract void 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); @@ -617,7 +617,7 @@ namespace CMS_CORE * Number of sequential data Read/Write. (Used only in Reading Operation) * List of values to read/Write * */ - public abstract void 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) @@ -634,7 +634,7 @@ namespace CMS_CORE * Number of sequential data Read/Write. (Used only in Reading Operation) * List of values to read/Write * */ - public abstract void 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); @@ -652,7 +652,7 @@ namespace CMS_CORE * Number of sequential data Read/Write. (Used only in Reading Operation) * List of values to read/Write * */ - public abstract void 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) @@ -669,7 +669,7 @@ namespace CMS_CORE * Number of sequential data Read/Write. (Used only in Reading Operation) * List of values to read/Write * */ - public abstract void 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); @@ -687,7 +687,7 @@ namespace CMS_CORE * Number of sequential data Read/Write. (Used only in Reading Operation) * List of values to read/Write * */ - public abstract void 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) @@ -704,7 +704,7 @@ namespace CMS_CORE * Number of sequential data Read/Write. (Used only in Reading Operation) * List of values to read/Write * */ - public abstract void 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); @@ -722,7 +722,7 @@ namespace CMS_CORE * Number of sequential data Read/Write. (Used only in Reading Operation) * List of values to read/Write * */ - public abstract void 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) @@ -739,7 +739,7 @@ namespace CMS_CORE * Number of sequential data Read/Write. (Used only in Reading Operation) * List of values to read/Write * */ - public abstract void 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 @@ -761,7 +761,7 @@ namespace CMS_CORE * Number of sequential data Read/Write. (Used only in Reading Operation) * List of values to read/Write * */ - public abstract void 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) @@ -779,7 +779,7 @@ namespace CMS_CORE * Number of sequential data Read/Write. (Used only in Reading Operation) * List of values to read/Write * */ - public abstract void 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); @@ -797,7 +797,7 @@ namespace CMS_CORE * Number of sequential data Read/Write. (Used only in Reading Operation) * List of values to read/Write * */ - public abstract void 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) @@ -814,7 +814,7 @@ namespace CMS_CORE * Number of sequential data Read/Write. (Used only in Reading Operation) * List of values to read/Write * */ - public abstract void 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); @@ -833,7 +833,7 @@ namespace CMS_CORE * List of values to read/Write * */ - public abstract void 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) * @@ -849,7 +849,7 @@ namespace CMS_CORE * Number of sequential data Read/Write. (Used only in Reading Operation) * List of values to read/Write * */ - public abstract void 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); @@ -867,7 +867,7 @@ namespace CMS_CORE * Number of sequential data Read/Write. (Used only in Reading Operation) * List of values to read/Write * */ - public abstract void 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) @@ -884,7 +884,7 @@ namespace CMS_CORE * Number of sequential data Read/Write. (Used only in Reading Operation) * List of values to read/Write * */ - public abstract void 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); @@ -902,7 +902,7 @@ namespace CMS_CORE * Number of sequential data Read/Write. (Used only in Reading Operation) * List of values to read/Write * */ - public abstract void 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) @@ -919,7 +919,7 @@ namespace CMS_CORE * Number of sequential data Read/Write. (Used only in Reading Operation) * List of values to read/Write * */ - public abstract void 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 @@ -937,7 +937,7 @@ namespace CMS_CORE * Name of the Part Program and name of new local file * Reference to the new local file where the NC Part Program data will be saved * */ - public abstract void FILES_RProgramToFile(string partProgramPath, FileStream localFile); + public abstract CmsError FILES_RProgramToFile(string partProgramPath, FileStream localFile); /** * Write/Overwrite a Part Program by path and name @@ -949,7 +949,7 @@ namespace CMS_CORE * Path of the Part Program stored in the Nc * Reference to the local Part Program file * */ - public abstract void FILES_WProgramFromFile(string partProgramPath, FileStream localFile); + public abstract CmsError FILES_WProgramFromFile(string partProgramPath, FileStream localFile); /** * Copy a Part Program into another path @@ -962,7 +962,7 @@ namespace CMS_CORE * Path of the copy Part Program destination * * */ - public abstract void FILES_CopyProgram(string partProgramPath, string newPartProgramPath, bool failIfExist); + public abstract CmsError FILES_CopyProgram(string partProgramPath, string newPartProgramPath, bool failIfExist); /** * Delete a Nc Part Program @@ -974,7 +974,7 @@ namespace CMS_CORE * Path where the Nc Part Program is saved in the NC * Name of the Part Program file * */ - public abstract void FILES_DeleteProgram(string partProgramPath, string partProgramName); + public abstract CmsError FILES_DeleteProgram(string partProgramPath, string partProgramName); #endregion @@ -1190,18 +1190,46 @@ namespace CMS_CORE #endregion /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - #region Error Codes + #region Cms Errors Codes + + internal const uint OK = 0; + internal const uint NC_PROD_ERROR = 1; + internal const uint NOT_CONNECTED = 2; + internal const uint PROC_NOT_FOUND = 3; + internal const uint FUNCTION_NOT_ALLOWED = 4; + internal const uint BIT_NOT_IN_RANGE = 5; + internal const uint BYTE_NOT_IN_RANGE = 6; + internal const uint INTERNAL_ERROR = 7; + internal const uint INCORRECT_PARAMETERS = 8; + internal const uint NC_LANGUAGE_ERROR = 9; + internal const uint SIEMENS_ENVIRONMENT_NOT_FOUND = 10; + internal const uint SIEMENS_HMI_NOT_RUNNING = 11; + + + public class CmsError + { + public uint errorCode; + public string message; + + public CmsError(uint errorCode, string message) + { + this.errorCode = errorCode; + this.message = message; + } + } + + internal static CmsError NO_ERROR = new CmsError(OK, ""); + internal static CmsError NOT_CONNECTED_ERROR = new CmsError(FUNCTION_NOT_ALLOWED, "CMS-Core-Error: Nc not Connected"); + internal static CmsError PROC_NOT_FOUND_ERROR = new CmsError(FUNCTION_NOT_ALLOWED, "CMS-Core-Error: Function not allowed for this type of NC"); + internal static CmsError FUNCTION_NOT_ALLOWED_ERROR = new CmsError(FUNCTION_NOT_ALLOWED, "CMS-Core-Error: Function not allowed for this type of NC"); + internal static CmsError BIT_NOT_IN_RANGE_ERROR = new CmsError(BIT_NOT_IN_RANGE, "CMS-Core-Error: Bit - number must be between 0 and 7"); + internal static CmsError BYTE_NOT_IN_RANGE_ERROR = new CmsError(BIT_NOT_IN_RANGE, "CMS-Core-Error: Byte - number must be between 0 and 1"); + internal static CmsError INCORRECT_PARAMETERS_ERROR = new CmsError(BIT_NOT_IN_RANGE, "CMS-Core-Error: Incorrect Parameters error"); + internal static CmsError LANGUAGE_ERROR = new CmsError(BIT_NOT_IN_RANGE, "CMS-Core-Error: Incorrect Language"); + internal static CmsError SIEMENS_ENVIRONMENT_NOT_FOUND_ERROR = new CmsError(BIT_NOT_IN_RANGE, "CMS-Core-Error: Siemens Environment not found"); + internal static CmsError SIEMENS_HMI_NOT_RUNNING_ERROR = new CmsError(BIT_NOT_IN_RANGE, "CMS-Core-Error: Siemens HMI is not Running / Ready"); + - internal const uint NC_PROD_ERROR = 0; - internal const uint NOT_CONNECTED_ERROR = 1; - internal const uint PROC_NOT_FOUND_ERROR = 2; - internal const uint FUNC_NOTALL_NC_ERROR = 3; - internal const uint BIT_NOT_IN_RANGE_ERROR = 4; - internal const uint BYTE_NOT_IN_RANGE_ERROR = 5; - internal const uint INTERNAL_ERROR = 6; - internal const uint INCORRECT_PARAMETERS_ERROR = 7; - internal const uint SIEMENS_ENVIRONMENT_NOT_FOUND = 8; - internal const uint SIEMENS_HMI_NOT_RUNNING = 9; #endregion diff --git a/CMS_CORE_Library/Osai/Nc_Osai.cs b/CMS_CORE_Library/Osai/Nc_Osai.cs index 13bef94..24d778c 100644 --- a/CMS_CORE_Library/Osai/Nc_Osai.cs +++ b/CMS_CORE_Library/Osai/Nc_Osai.cs @@ -62,18 +62,17 @@ namespace CMS_CORE.Osai LanguageConfig(); //Read Plc Messages - if(PlcMessages == null) + if (PlcMessages == null) { PlcMessages = new string[] { }; ReadPlcMessages(); } - } //Connect Method - public override void NC_Connect() + public override CmsError NC_Connect() { uint errorClass, errorNum; @@ -83,7 +82,7 @@ namespace CMS_CORE.Osai setupConnection(); //Setup the Url String and the Endpoint - Url = "http://" + Ip + ":"+ Port; + Url = "http://" + Ip + ":" + Port; endPointAddress = new EndpointAddress(new Uri(Url)); //Open the connection @@ -97,31 +96,35 @@ namespace CMS_CORE.Osai //If there's an error if (errorClass != 0 || errorNum != 0 || nReturn == 0) - throw new Nc_Exception(getError(NC_PROD_ERROR, errorClass, errorNum)); - + return GetError(NC_PROD_ERROR, errorClass, errorNum); + //Find if the NC is in Phase 4 if (CNCPhase == 4) Connected = true; else Connected = false; - + } - catch(Exception ex ) + catch (Exception ex) { - ThrowNCException(ex); + return ManageException(ex); } + + return NO_ERROR; } - + //Disconnect Method - public override void NC_Disconnect() + public override CmsError NC_Disconnect() { //Set Connected to FALSE and close the session OpenNC.Close(); Connected = false; + + return NO_ERROR; } - + #endregion @@ -130,63 +133,74 @@ namespace CMS_CORE.Osai #region High-level Methods //Get the NC Language - public override void NC_RLanguage(ref CultureInfo Language) + public override CmsError NC_RLanguage(ref CultureInfo Language) { //Check if the NC is Connected - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; Language = ConverToSTEPLanguage(OsaiLanguages); + + return NO_ERROR; } //Get the NC Serial Number - public override void NC_RSerialNumber(ref string SN) + public override CmsError NC_RSerialNumber(ref string SN) { - //Check if the NC is Connected - CheckConnection(); + // Read static NC data + CmsError cmsError = ReadStaticNCData(); + if (cmsError.errorCode != OK) + return cmsError; - readStaticNCData(); SN = Cnc_SeriesNum; + return NO_ERROR; } //Get the NC Software Version - public override void NC_RSoftwareVersion(ref string SWV) + public override CmsError NC_RSoftwareVersion(ref string SWV) { - //Check if the NC is Connected - CheckConnection(); + // Read static NC data + CmsError cmsError = ReadStaticNCData(); + if (cmsError.errorCode != OK) + return cmsError; - readStaticNCData(); SWV = Cnc_SftVersion; + + return NO_ERROR; } - - - //Get the NC model Name - public override void NC_RModelName(ref string ModelName) + public override CmsError NC_RModelName(ref string ModelName) { - //Check if the NC is Connected - CheckConnection(); + // Read static NC data + CmsError cmsError = ReadStaticNCData(); + if (cmsError.errorCode != OK) + return cmsError; - readStaticNCData(); ModelName = Cnc_name; + + return NO_ERROR; } //Get the NC Time - public override void NC_RDateTime(ref DateTime ActualTime) + public override CmsError NC_RDateTime(ref DateTime ActualTime) { + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; + uint errorClass, errorNum; ushort nReturn; - ushort Year,Month,Day,Hour,Minute,Second; - - //Check if the NC is Connected - CheckConnection(); + ushort Year, Month, Day, Hour, Minute, Second; //Try to get information try @@ -195,8 +209,8 @@ namespace CMS_CORE.Osai nReturn = OpenNC.GetDateTime(out Year, out Month, out Day, out Hour, out Minute, out Second, out errorClass, out errorNum); //If there's an error launch exception - if (errorClass != 0 || errorNum != 0 || nReturn==0) - throw new Nc_Exception(getError(NC_PROD_ERROR, errorClass, errorNum)); + if (errorClass != 0 || errorNum != 0 || nReturn == 0) + return GetError(NC_PROD_ERROR, errorClass, errorNum); //Setup the out value ActualTime = new DateTime(Year, Month, Day, Hour, Minute, Second); @@ -204,50 +218,50 @@ namespace CMS_CORE.Osai } catch (Exception ex) { - ThrowNCException(ex); + return ManageException(ex); } - + return NO_ERROR; } //Get the Machine Number - public override void NC_RMachineNumber(ref string MachNumber) + public override CmsError NC_RMachineNumber(ref string MachNumber) { ushort mac = 0; - //Check if the NC is Connected - CheckConnection(); - //Exetute the function - MEM_RWWord(R, UNDEF_PROC, MATR_MACCH_OSAI.MemType, MATR_MACCH_OSAI.Address, ref mac); + CmsError cmsError = MEM_RWWord(R, UNDEF_PROC, MATR_MACCH_OSAI.MemType, MATR_MACCH_OSAI.Address, ref mac); + if (cmsError.errorCode != OK) + return cmsError; MachNumber = mac.ToString(); + + return NO_ERROR; } //Get the PLC Active Alarms - public override void PLC_RActiveMessages(ref List Alarms) + public override CmsError PLC_RActiveMessages(ref List Alarms) { - List lista = new List(); + List list = new List(); BitArray Bits; int Index; Alarms.Clear(); - //Check if the NC is Connected - CheckConnection(); - //Execute the method - MEM_RWWordList(R, 0, PLC_MESS_OSAI.MemType, PLC_MESS_OSAI.Address, PLC_MESS_OSAI.Size, ref lista); + CmsError cmsError = MEM_RWWordList(R, 0, PLC_MESS_OSAI.MemType, PLC_MESS_OSAI.Address, PLC_MESS_OSAI.Size, ref list); + if (cmsError.errorCode != OK) + return cmsError; //Elaborates the Messages - for (int i=0; i Alarms) + public override CmsError NC_RActiveAlarms(ref List Alarms) { + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; + uint errorClass, errorNum; ushort nReturn; MSGEMERGENCY errEmgy; - //Check if the NC is Connected - CheckConnection(); - //Try to get information try { @@ -329,7 +350,7 @@ namespace CMS_CORE.Osai //If there's an error launch exception if (errorClass != 0 || errorNum != 0 || nReturn == 0) - throw new Nc_Exception(getError(NC_PROD_ERROR, errorClass, errorNum)); + return GetError(NC_PROD_ERROR, errorClass, errorNum); //If there's an error if (errEmgy.CodeErr != 0) @@ -339,29 +360,34 @@ namespace CMS_CORE.Osai //Translate using OSAI .DLL (a new one!) OSAIErrorManagerLibrary.TranslateEmergMsg(ref CndexErrorEmgy, ref MessageEmgy); - + //Build the new String Message Alarms.Add(OsaiToStepMessage(MessageEmgy)); - } + } } catch (Exception ex) { - ThrowNCException(ex); + return ManageException(ex); } + + return NO_ERROR; } //Get the process status - public override void PROC_RStatus(ushort Number, ref PROC_Status Status) + public override CmsError PROC_RStatus(ushort Number, ref PROC_Status Status) { + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; + + uint errorClass, errorNum; ushort nReturn; PROCDATA status; - //Check if the NC is Connected - CheckConnection(); - //Try to get information try { @@ -372,26 +398,30 @@ namespace CMS_CORE.Osai //If there's an error launch exception if (errorClass != 0 || errorNum != 0 || nReturn == 0) - throw new Nc_Exception(getError(NC_PROD_ERROR, errorClass, errorNum)); + return GetError(NC_PROD_ERROR, errorClass, errorNum); } catch (Exception ex) { - ThrowNCException(ex); + return ManageException(ex); } + + return NO_ERROR; } //Get the process mode - public override void PROC_RMode(ushort Number, ref PROC_Mode Mode) + public override CmsError PROC_RMode(ushort Number, ref PROC_Mode Mode) { + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; + uint errorClass, errorNum; ushort nReturn; PROCDATA status; - //Check if the NC is Connected - CheckConnection(); - //Try to get information try { @@ -402,26 +432,30 @@ namespace CMS_CORE.Osai //If there's an error launch exception if (errorClass != 0 || errorNum != 0 || nReturn == 0) - throw new Nc_Exception(getError(NC_PROD_ERROR, errorClass, errorNum)); + return GetError(NC_PROD_ERROR, errorClass, errorNum); } catch (Exception ex) { - ThrowNCException(ex); + return ManageException(ex); } + + return NO_ERROR; } //Get the process Alarm - public override void PROC_RActiveAlarms(ushort Number, ref List Alarms) + public override CmsError PROC_RActiveAlarms(ushort Number, ref List Alarms) { + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; + uint errorClass, errorNum; ushort nReturn; MSGERROR err; - //Check if the NC is Connected - CheckConnection(); - //Try to get information try { @@ -433,8 +467,8 @@ namespace CMS_CORE.Osai //If there's an error launch exception if (errorClass != 0 || errorNum != 0 || nReturn == 0) - throw new Nc_Exception(getError(NC_PROD_ERROR, errorClass, errorNum)); - + return GetError(NC_PROD_ERROR, errorClass, errorNum); + //If there's an error if (err.CodeErr != 0) { @@ -452,15 +486,22 @@ namespace CMS_CORE.Osai } catch (Exception ex) { - ThrowNCException(ex); + return ManageException(ex); } + + return NO_ERROR; } //Get PP Lines - public override void PROC_RPPLines(ushort ProcNumber, ref List Lines) + public override CmsError PROC_RPPLines(ushort ProcNumber, ref List Lines) { + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; + uint errorClass, errorNum; ushort nReturn; String L1 = ""; @@ -472,18 +513,15 @@ namespace CMS_CORE.Osai String L7 = ""; String L8 = ""; - //Check if the NC is Connected - CheckConnection(); - //Try to get information try { //Execute the method - nReturn = OpenNC.GetPartProgramLines(ProcNumber,out L1, out L2, out L3, out L4, out L5, out L6, out L7, out L8, out errorClass, out errorNum); + nReturn = OpenNC.GetPartProgramLines(ProcNumber, out L1, out L2, out L3, out L4, out L5, out L6, out L7, out L8, out errorClass, out errorNum); //If there's an error launch exception if (errorClass != 0 || errorNum != 0 || nReturn == 0) - throw new Nc_Exception(getError(NC_PROD_ERROR, errorClass, errorNum)); + return GetError(NC_PROD_ERROR, errorClass, errorNum); //Clear All Values Lines.Clear(); @@ -497,28 +535,32 @@ namespace CMS_CORE.Osai Lines.Add(L6); Lines.Add(L7); Lines.Add(L8); - + } catch (Exception ex) { - ThrowNCException(ex); + return ManageException(ex); } + + return NO_ERROR; } //Get Active PP Name - public override void PROC_RPPName(ushort ProcNumber, ref string Name) + public override CmsError PROC_RPPName(ushort ProcNumber, ref string Name) { + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; + uint errorClass, errorNum; ushort nReturn; ushort Level = 0; String MainName = ""; String SubName = ""; - //Check if the NC is Connected - CheckConnection(); - //Try to get information try { @@ -527,23 +569,30 @@ namespace CMS_CORE.Osai //If there's an error launch exception if (errorClass != 0 || errorNum != 0 || nReturn == 0) - throw new Nc_Exception(getError(NC_PROD_ERROR, errorClass, errorNum)); - + return GetError(NC_PROD_ERROR, errorClass, errorNum); + //Build the new String Name = MainName; } catch (Exception ex) { - ThrowNCException(ex); + return ManageException(ex); } + + return NO_ERROR; } //Get a dictionary with the Actual position of the axes in Process - public override void AXES_RInterpPosition(ushort Process, ref Dictionary Axes) + public override CmsError AXES_RInterpPosition(ushort Process, ref Dictionary Axes) { + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; + uint errorClass, errorNum; ushort nReturn; ushort nAxis = 20; @@ -551,9 +600,6 @@ namespace CMS_CORE.Osai GETINTDATAC4array Pos; KeyValuePair val; - //Check if the NC is Connected - CheckConnection(); - //Try to get information try { @@ -561,8 +607,8 @@ namespace CMS_CORE.Osai //If there's an error launch exception if (errorClass != 0 || errorNum != 0 || nReturn == 0) - throw new Nc_Exception(getError(NC_PROD_ERROR, errorClass, errorNum)); - + return GetError(NC_PROD_ERROR, errorClass, errorNum); + //If an axis goes out from Process Clear the List if (Axes.Count > Pos.Count) { @@ -573,7 +619,7 @@ namespace CMS_CORE.Osai //Fill all the List foreach (GETINTDATA ax in Pos) { - if(ax.AxisName > 0) + if (ax.AxisName > 0) { AxName = ((char)ax.AxisName).ToString(); val = Axes.FirstOrDefault(X => X.Key == AxName); @@ -587,15 +633,22 @@ namespace CMS_CORE.Osai } catch (Exception ex) { - ThrowNCException(ex); + return ManageException(ex); } + + return NO_ERROR; } //Get a dictionary with the Programmed position of the axes in Process - public override void AXES_RProgrPosition(ushort Process, ref Dictionary Axes) + public override CmsError AXES_RProgrPosition(ushort Process, ref Dictionary Axes) { + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; + uint errorClass, errorNum; ushort nReturn; ushort nAxis = 20; @@ -603,9 +656,6 @@ namespace CMS_CORE.Osai GETINTDATAC4array Pos; KeyValuePair val; - //Check if the NC is Connected - CheckConnection(); - //Try to get information try { @@ -613,14 +663,14 @@ namespace CMS_CORE.Osai //If there's an error launch exception if (errorClass != 0 || errorNum != 0 || nReturn == 0) - throw new Nc_Exception(getError(NC_PROD_ERROR, errorClass, errorNum)); + return GetError(NC_PROD_ERROR, errorClass, errorNum); //If an axis goes out from Process Clear the List if (Axes.Count > Pos.Count) { Axes.Clear(); } - + //Fill all the List foreach (GETINTDATA ax in Pos) { @@ -638,15 +688,22 @@ namespace CMS_CORE.Osai } catch (Exception ex) { - ThrowNCException(ex); + return ManageException(ex); } + + return NO_ERROR; } //Get a dictionary with the Machine position of the axes in Process - public override void AXES_RMachinePosition(ushort Process, ref Dictionary Axes) + public override CmsError AXES_RMachinePosition(ushort Process, ref Dictionary Axes) { + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; + uint errorClass, errorNum; ushort nReturn; ushort nAxis = 20; @@ -654,9 +711,6 @@ namespace CMS_CORE.Osai GETINTDATAC4array Pos; KeyValuePair val; - //Check if the NC is Connected - CheckConnection(); - //Try to get information try { @@ -664,7 +718,7 @@ namespace CMS_CORE.Osai //If there's an error launch exception if (errorClass != 0 || errorNum != 0 || nReturn == 0) - throw new Nc_Exception(getError(NC_PROD_ERROR, errorClass, errorNum)); + return GetError(NC_PROD_ERROR, errorClass, errorNum); //If an axis goes out from Process Clear the List if (Axes.Count > Pos.Count) @@ -689,15 +743,22 @@ namespace CMS_CORE.Osai } catch (Exception ex) { - ThrowNCException(ex); + return ManageException(ex); } + + return NO_ERROR; } //Get a dictionary with the Following Error of the axes in Process - public override void AXES_RFollowingError(ushort Process, ref Dictionary Axes) + public override CmsError AXES_RFollowingError(ushort Process, ref Dictionary Axes) { + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; + uint errorClass, errorNum; ushort nReturn; ushort nAxis = 20; @@ -705,9 +766,6 @@ namespace CMS_CORE.Osai GETINTDATAC4array Pos; KeyValuePair val; - //Check if the NC is Connected - CheckConnection(); - //Try to get information try { @@ -715,14 +773,14 @@ namespace CMS_CORE.Osai //If there's an error launch exception if (errorClass != 0 || errorNum != 0 || nReturn == 0) - throw new Nc_Exception(getError(NC_PROD_ERROR, errorClass, errorNum)); + return GetError(NC_PROD_ERROR, errorClass, errorNum); //If an axis goes out from Process Clear the List if (Axes.Count > Pos.Count) { Axes.Clear(); } - + //Fill all the List foreach (GETINTDATA ax in Pos) { @@ -740,15 +798,22 @@ namespace CMS_CORE.Osai } catch (Exception ex) { - ThrowNCException(ex); + return ManageException(ex); } + + return NO_ERROR; } //Get a dictionary with the Distance To Go of the axes in Process - public override void AXES_RDistanceToGo(ushort Process, ref Dictionary Axes) + public override CmsError AXES_RDistanceToGo(ushort Process, ref Dictionary Axes) { + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; + uint errorClass, errorNum; ushort nReturn; ushort nAxis = 20; @@ -756,9 +821,6 @@ namespace CMS_CORE.Osai GETINTDATAC4array Pos; KeyValuePair val; - //Check if the NC is Connected - CheckConnection(); - //Try to get information try { @@ -766,14 +828,14 @@ namespace CMS_CORE.Osai //If there's an error launch exception if (errorClass != 0 || errorNum != 0 || nReturn == 0) - throw new Nc_Exception(getError(NC_PROD_ERROR, errorClass, errorNum)); + return GetError(NC_PROD_ERROR, errorClass, errorNum); //If an axis goes out from Process Clear the List if (Axes.Count > Pos.Count) { Axes.Clear(); } - + //Fill all the List foreach (GETINTDATA ax in Pos) { @@ -791,8 +853,10 @@ namespace CMS_CORE.Osai } catch (Exception ex) { - ThrowNCException(ex); + return ManageException(ex); } + + return NO_ERROR; } @@ -801,27 +865,20 @@ namespace CMS_CORE.Osai /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #region Low-level Methods - + //-------------------------------------------------------------------------------------------------------------------------- // BOOLEAN (NC) <-> BOOLEAN (.NET) //Read-Write a Boolean-Value inside the NC. - public override void 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); - //Check if the NC is Connected - CheckConnection(); - - //Check if the Memory area is corrected - CheckMemoryArea(MemType.ToString()); - - //Check if the Bit Number is Correct - CheckBitRange(MemBit); - - //Read the Byte where is the bit - MEM_RWWord(R, Process, MemType, MemIndex, ref WordValue); + //Read the Byte where is the bit + CmsError cmsError = MEM_RWWord(R, Process, MemType, MemIndex, ref WordValue); + if (cmsError.errorCode != OK) + return cmsError; //If i have to read -> Read the Bit if (bWrite == R) @@ -836,8 +893,12 @@ namespace CMS_CORE.Osai else WordValue = (byte)(WordValue & ~(1 << MemBit)); - MEM_RWWord(W, Process, MemType, MemIndex, ref WordValue); + cmsError = MEM_RWWord(W, Process, MemType, MemIndex, ref WordValue); + if (cmsError.errorCode != OK) + return cmsError; } + + return NO_ERROR; } @@ -846,27 +907,20 @@ namespace CMS_CORE.Osai // BYTE (NC) <-> BYTE (.NET) ToDo //Read-Write a Byte-Value inside the NC. In writing-mode the field "Number" is not required - public override void 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; - //Check if the NC is Connected - CheckConnection(); - - //Check if the Memory area is corrected - CheckMemoryArea(MemType.ToString()); - - //Check if the Bit Number is Correct - CheckByteRange(MemByte); - //Read the Byte where is the bit - MEM_RWWord(R, Process, MemType, MemIndex, ref WordValue); + CmsError cmsError = MEM_RWWord(R, Process, MemType, MemIndex, ref WordValue); + if (cmsError.errorCode != OK) + return cmsError; //If i have to read -> Read the Bit if (bWrite == R) { - if(MemByte == 1) + if (MemByte == 1) Value = (byte)(WordValue >> 8); else Value = (byte)(WordValue & 0xff); @@ -888,28 +942,24 @@ namespace CMS_CORE.Osai WordToWrite = (ushort)(WordToWrite | WordValue); //Write to the NC - MEM_RWWord(W, Process, MemType, MemIndex, ref WordToWrite); + cmsError = MEM_RWWord(W, Process, MemType, MemIndex, ref WordToWrite); + if (cmsError.errorCode != OK) + return cmsError; } + + return NO_ERROR; } //Read-Write a Byte-Value-List inside the NC. In writing-mode the field "Number" is not required - public override void 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; int MemIndexTemp = MemIndex; List WordList = new List(); - - //Check if the NC is Connected - CheckConnection(); - - //Check if the Memory area is corrected - CheckMemoryArea(MemType.ToString()); - - //Check if the Bit Number is Correct - CheckByteRange(MemByteStart); + CmsError cmsError = null; //Save if i have to start from Higher bit index = MemByteStart; @@ -918,12 +968,16 @@ namespace CMS_CORE.Osai { //Prevent some exceptions if (Values.Count == 0) - return; - + return NO_ERROR; + for (int i = 0; i < Values.Count; i++) { TempVal = Values[i]; - MEM_RWByte(W, Process, MemType, MemIndexTemp, index, ref TempVal); + + cmsError = MEM_RWByte(W, Process, MemType, MemIndexTemp, index, ref TempVal); + if (cmsError.errorCode != OK) + return cmsError; + if (index == 1) { index = 0; @@ -935,12 +989,15 @@ namespace CMS_CORE.Osai { //Prevent some exceptions if (Number == 0) - return; + return NO_ERROR; Values.Clear(); for (int i = 0; i < Number; i++) { - MEM_RWByte(W, Process, MemType, MemIndexTemp, index, ref TempVal); + cmsError = MEM_RWByte(W, Process, MemType, MemIndexTemp, index, ref TempVal); + if (cmsError.errorCode != OK) + return cmsError; + Values.Add(TempVal); if (index == 1) { @@ -950,46 +1007,48 @@ namespace CMS_CORE.Osai } } - + 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 void 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) { List ListValue = new List() { Value }; - //Check if the NC is Connected - CheckConnection(); - - //Check if the Memory area is corrected - CheckMemoryArea(MemType.ToString()); - //uses the List method with one-element list - MEM_RWWordList(bWrite, Process, MemType, MemIndex, 1, ref ListValue); + CmsError cmsError = MEM_RWWordList(bWrite, Process, MemType, MemIndex, 1, ref ListValue); + if (cmsError.errorCode != OK) + 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 void 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(); + if (cmsError.errorCode != OK) + return cmsError; + + //Check if the Memory area is corrected + cmsError = CheckMemoryArea(MemType.ToString()); + if (cmsError.errorCode != OK) + return cmsError; + uint errorClass, errorNum; ushort nReturn; unsignedshortarray values; - //Check if the NC is Connected - CheckConnection(); - - //Check if the Memory area is corrected - CheckMemoryArea(MemType.ToString()); - //Try to get information try { @@ -1005,7 +1064,7 @@ namespace CMS_CORE.Osai //If there's an error if (errorClass != 0 || errorNum != 0 || nReturn == 0) - throw new Nc_Exception(getError(NC_PROD_ERROR, errorClass, errorNum)); + return GetError(NC_PROD_ERROR, errorClass, errorNum); } else @@ -1015,7 +1074,7 @@ namespace CMS_CORE.Osai //If there's an error if (errorClass != 0 || errorNum != 0 || nReturn == 0) - throw new Nc_Exception(getError(NC_PROD_ERROR, errorClass, errorNum)); + return GetError(NC_PROD_ERROR, errorClass, errorNum); // Create the array with the Values Values = values.ToList(); @@ -1024,8 +1083,10 @@ namespace CMS_CORE.Osai } catch (Exception ex) { - ThrowNCException(ex); + return ManageException(ex); } + + return NO_ERROR; } @@ -1033,27 +1094,29 @@ namespace CMS_CORE.Osai //-------------------------------------------------------------------------------------------------------------------------- // WORD (NC) <-> SHORT (.NET) - public override void 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) { List ListValue = new List() { Value }; - //Check if the NC is Connected - CheckConnection(); - - //Check if the Memory area is corrected - CheckMemoryArea(MemType.ToString()); - //uses the List method with one-element list - MEM_RWShortList(bWrite, Process, MemType, MemIndex, 1, ref ListValue); + CmsError cmsError = MEM_RWShortList(bWrite, Process, MemType, MemIndex, 1, ref ListValue); + if (cmsError.errorCode != OK) + return cmsError; Value = ListValue.First(); + + return NO_ERROR; } - public override void 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); - MEM_RWWordList(bWrite, Process, MemType, MemIndex, 1, ref ShortValue); + List ShortValue = Value.ConvertAll(x => (ushort)x); + CmsError cmsError = MEM_RWWordList(bWrite, Process, MemType, MemIndex, 1, ref ShortValue); + if (cmsError.errorCode != OK) + return cmsError; + + return NO_ERROR; } @@ -1063,44 +1126,40 @@ namespace CMS_CORE.Osai //Write a Word-Value inside the NC. In writing-mode the field "Number" is not required - public override void 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) { List ListValue = new List() { Value }; - //Check if the NC is Connected - CheckConnection(); - - //Check if the Memory area is corrected - CheckMemoryArea(MemType.ToString()); - //uses the List method with one-element list - MEM_RWDWordList(bWrite, Process, MemType, MemIndex, 1, ref ListValue); + CmsError cmsError = MEM_RWDWordList(bWrite, Process, MemType, MemIndex, 1, ref ListValue); + if (cmsError.errorCode != OK) + 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 void 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(); - //Check if the NC is Connected - CheckConnection(); - - //Check if the Memory area is corrected - CheckMemoryArea(MemType.ToString()); - //If i have to write convert the UINT list into (2x) WORD if (bWrite) WordValues = Nc_Utils.UIntTOWordList(Values); //Exetute the function - MEM_RWWordList(bWrite, Process, MemType, MemIndex, (Number * 2), ref WordValues); + CmsError cmsError = MEM_RWWordList(bWrite, Process, MemType, MemIndex, (Number * 2), ref WordValues); + if (cmsError.errorCode != OK) + return cmsError; //If i have to read convert the (2x) WORD list into UINT if (!bWrite) Values = Nc_Utils.WordTOUintList(WordValues); + + return NO_ERROR; } @@ -1110,104 +1169,101 @@ namespace CMS_CORE.Osai //Write a Int-Value inside the NC. In writing-mode the field "Number" is not required - public override void 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) { List ListValue = new List() { Value }; - //Check if the NC is Connected - CheckConnection(); - - //Check if the Memory area is corrected - CheckMemoryArea(MemType.ToString()); - //uses the List method with one-element list - MEM_RWIntegerList(bWrite, Process, MemType, MemIndex, 1, ref ListValue); + CmsError cmsError = MEM_RWIntegerList(bWrite, Process, MemType, MemIndex, 1, ref ListValue); + if (cmsError.errorCode != OK) + 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 void 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(); - //Check if the NC is Connected - CheckConnection(); - - //Check if the Memory area is corrected - CheckMemoryArea(MemType.ToString()); - //If i have to write convert the INT list into (2x) WORD if (bWrite) WordValues = Nc_Utils.IntTOWordList(Values); //Exetute the function - MEM_RWWordList(bWrite, Process, MemType, MemIndex, (Number * 2), ref WordValues); + CmsError cmsError = MEM_RWWordList(bWrite, Process, MemType, MemIndex, (Number * 2), ref WordValues); + if (cmsError.errorCode != OK) + return cmsError; //If i have to read convert the (2x) WORD list into INT if (!bWrite) Values = Nc_Utils.WordTOIntList(WordValues); + + return NO_ERROR; } //-------------------------------------------------------------------------------------------------------------------------- // Siemens Version of Memory-Access Methods - - public override void 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) { - MEM_RWBoolean(bWrite, Process, MemType, MemIndex, MemBit, ref Value); + return MEM_RWBoolean(bWrite, Process, MemType, MemIndex, MemBit, ref Value); + } - public override void 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) { - MEM_RWByte(bWrite, Process, MemType, MemIndex, MemByte, ref Value); + return MEM_RWByte(bWrite, Process, MemType, MemIndex, MemByte, ref Value); } - public override void 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) { - MEM_RWWord(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); + return MEM_RWWord(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); } - public override void 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) { - MEM_RWShort(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); + return MEM_RWShort(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); } - public override void 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) { - MEM_RWDWord(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); + return MEM_RWDWord(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); } - public override void 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) { - MEM_RWInteger(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); + return MEM_RWInteger(bWrite, Process, MemType, MemIndex, MemIndex, ref Value); } - public override void 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) { - MEM_RWByteList(bWrite, Process, MemType, MemIndex, MemByteStart, Number, ref Value); + return MEM_RWByteList(bWrite, Process, MemType, MemIndex, MemByteStart, Number, ref Value); } - public override void 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) { - MEM_RWWordList(bWrite, Process, MemType, MemIndex, Number, ref Value); + return MEM_RWWordList(bWrite, Process, MemType, MemIndex, Number, ref Value); } - public override void 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) { - MEM_RWShortList(bWrite, Process, MemType, MemIndex, Number, ref Value); + return MEM_RWShortList(bWrite, Process, MemType, MemIndex, Number, ref Value); } - public override void 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) { - MEM_RWDWordList(bWrite, Process, MemType, MemIndex, Number, ref Value); + return MEM_RWDWordList(bWrite, Process, MemType, MemIndex, Number, ref Value); } - public override void 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) { - MEM_RWIntegerList(bWrite, Process, MemType, MemIndex, Number, ref Value); + return MEM_RWIntegerList(bWrite, Process, MemType, MemIndex, Number, ref Value); } @@ -1215,29 +1271,29 @@ namespace CMS_CORE.Osai //-------------------------------------------------------------------------------------------------------------------------- // PARAMS - public override void NC_RParam(short Index, short Bit, ref bool Value) + public override CmsError NC_RParam(short Index, short Bit, ref bool Value) { - throw new Nc_Exception(getError(FUNC_NOTALL_NC_ERROR, 0, 0)); + return FUNCTION_NOT_ALLOWED_ERROR; } - public override void NC_RParam(short Index, ref byte Value) + public override CmsError NC_RParam(short Index, ref byte Value) { - throw new Nc_Exception(getError(FUNC_NOTALL_NC_ERROR, 0, 0)); + return FUNCTION_NOT_ALLOWED_ERROR; } - public override void NC_RParam(short Index, ref short Value) + public override CmsError NC_RParam(short Index, ref short Value) { - throw new Nc_Exception(getError(FUNC_NOTALL_NC_ERROR, 0, 0)); + return FUNCTION_NOT_ALLOWED_ERROR; } - public override void NC_RParam(short Index, ref int Value) + public override CmsError NC_RParam(short Index, ref int Value) { - throw new Nc_Exception(getError(FUNC_NOTALL_NC_ERROR, 0, 0)); + return FUNCTION_NOT_ALLOWED_ERROR; } - public override void NC_RParam(short Index, ref double Value) + public override CmsError NC_RParam(short Index, ref double Value) { - throw new Nc_Exception(getError(FUNC_NOTALL_NC_ERROR, 0, 0)); + return FUNCTION_NOT_ALLOWED_ERROR; } @@ -1247,11 +1303,13 @@ namespace CMS_CORE.Osai /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #region File Management - public override void FILES_RProgramToFile(string partProgramPath, FileStream localFile) + public override CmsError FILES_RProgramToFile(string partProgramPath, FileStream localFile) { string partProgramContent = ""; // Read NC part program content - FILES_RProgram(partProgramPath, ref partProgramContent); ; + CmsError cmsError = FILES_RProgram(partProgramPath, ref partProgramContent); + if (cmsError.errorCode != OK) + return cmsError; try { @@ -1260,14 +1318,18 @@ namespace CMS_CORE.Osai } catch (Exception ex) { - ThrowNCException(ex); + return ManageException(ex); } + + return NO_ERROR; } - private void FILES_RProgram(string partProgramPath, ref string partProgramContent) + private CmsError FILES_RProgram(string partProgramPath, ref string partProgramContent) { //Check if the NC is Connected - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; ushort nReturn; uint errorClass, errorNum; @@ -1282,15 +1344,17 @@ namespace CMS_CORE.Osai //If there's an error launch exception if (errorClass != 0 || errorNum != 0 || nReturn == 0) - throw new Nc_Exception(getError(NC_PROD_ERROR, errorClass, errorNum)); + return GetError(NC_PROD_ERROR, errorClass, errorNum); } catch (Exception ex) { - ThrowNCException(ex); + return ManageException(ex); } + + return NO_ERROR; } - public override void FILES_WProgramFromFile(string partProgramPath, FileStream localFile) + public override CmsError FILES_WProgramFromFile(string partProgramPath, FileStream localFile) { string partProgramContent = ""; @@ -1301,16 +1365,18 @@ namespace CMS_CORE.Osai } catch (Exception ex) { - ThrowNCException(ex); + return ManageException(ex); } // Write/Overwrite Nc file - FILES_WProgram(partProgramPath, partProgramContent); + return FILES_WProgram(partProgramPath, partProgramContent); } - private void FILES_WProgram(string partProgramPath, string partProgramContent) + private CmsError FILES_WProgram(string partProgramPath, string partProgramContent) { //Check if the NC is Connected - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; ushort nReturn; uint errorClass, errorNum; @@ -1322,26 +1388,29 @@ namespace CMS_CORE.Osai //If there's an error launch exception if (errorClass != 0 || errorNum != 0 || nReturn == 0) - throw new Nc_Exception(getError(NC_PROD_ERROR, errorClass, errorNum)); + return GetError(NC_PROD_ERROR, errorClass, errorNum); } - catch(Exception ex) + catch (Exception ex) { - ThrowNCException(ex); + return ManageException(ex); } + + return NO_ERROR; } - public override void FILES_CopyProgram(string partProgramPath, string newPartProgramPath, bool failIfExist) + public override CmsError FILES_CopyProgram(string partProgramPath, string newPartProgramPath, bool failIfExist) { //Check if the NC is Connected - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; uint errorClass, errorNum; ushort nReturn; // If the 2 path are the same if (partProgramPath == newPartProgramPath) - throw new Nc_Exception(getError(NC_PROD_ERROR, 0, 0)); // TODO FIX - + return INCORRECT_PARAMETERS_ERROR; try { // Copy Nc part program to the new path @@ -1349,19 +1418,23 @@ namespace CMS_CORE.Osai //If there's an error launch exception if (errorClass != 0 || errorNum != 0 || nReturn == 0) - throw new Nc_Exception(getError(NC_PROD_ERROR, errorClass, errorNum)); + return GetError(NC_PROD_ERROR, errorClass, errorNum); } catch (Exception ex) { - ThrowNCException(ex); + return ManageException(ex); } + + return NO_ERROR; } - public override void FILES_DeleteProgram(string partProgramPath, string partProgramName) + public override CmsError FILES_DeleteProgram(string partProgramPath, string partProgramName) { //Check if the NC is Connected - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; uint errorClass, errorNum; ushort nReturn; @@ -1373,12 +1446,14 @@ namespace CMS_CORE.Osai //If there's an error launch exception if (errorClass != 0 || errorNum != 0 || nReturn == 0) - throw new Nc_Exception(getError(NC_PROD_ERROR, errorClass, errorNum)); + return GetError(NC_PROD_ERROR, errorClass, errorNum); } catch (Exception ex) { - ThrowNCException(ex); + return ManageException(ex); } + + return NO_ERROR; } @@ -1394,7 +1469,7 @@ namespace CMS_CORE.Osai HttpBinding = new BasicHttpBinding(BasicHttpSecurityMode.None); HttpBinding.Name = "OPENcontrol"; - HttpBinding.CloseTimeout = TimeSpan.Parse("00:00:10"); + HttpBinding.CloseTimeout = TimeSpan.Parse("00:00:10"); HttpBinding.OpenTimeout = TimeSpan.Parse("00:00:10"); HttpBinding.ReceiveTimeout = new TimeSpan(TimeSpan.TicksPerMillisecond * timeOutConn); HttpBinding.SendTimeout = new TimeSpan(TimeSpan.TicksPerMillisecond * timeOutConn); @@ -1413,25 +1488,29 @@ namespace CMS_CORE.Osai //Check if NC is connected - private void CheckConnection() + private CmsError CheckConnection() { if (!NC_IsConnected()) - throw new Nc_Exception(getError(NOT_CONNECTED_ERROR,0 , 0)); + return NOT_CONNECTED_ERROR; + + return NO_ERROR; } //Check if Memory Area is corrected - private void CheckMemoryArea(String AreaName) - { + private CmsError CheckMemoryArea(String AreaName) + { if (!AreaName.StartsWith(OSAI_MEMTYPE) && !AreaName.StartsWith(UNDEFINED_MEMTYPE)) - throw new Nc_Exception(getError(INCORRECT_PARAMETERS_ERROR, 0, 0)); + return INCORRECT_PARAMETERS_ERROR; + else + return NO_ERROR; } - + //Read Static Data - private void readStaticNCData() + private CmsError ReadStaticNCData() { uint errorClass, errorNum; @@ -1448,38 +1527,43 @@ namespace CMS_CORE.Osai //If there's an error launch exception if (errorClass != 0 || errorNum != 0 || nReturn == 0) - throw new Nc_Exception(getError(NC_PROD_ERROR,errorClass, errorNum)); + return GetError(NC_PROD_ERROR, errorClass, errorNum); //Setup the CNC Name Cnc_name = "OSAI - Open Control"; - + Last_Static_Read = DateTime.Now; } catch (Exception ex) { - ThrowNCException(ex); + return ManageException(ex); } } + return NO_ERROR; } //Check Bit In Range - private void CheckBitRange(int bitnum) + private CmsError CheckBitRange(int bitnum) { if (bitnum < 0 || bitnum > 7) - throw new Nc_Exception(getError(BIT_NOT_IN_RANGE_ERROR,0, 0)); + return BIT_NOT_IN_RANGE_ERROR; + else + return NO_ERROR; } //Check Byte In Range - private void CheckByteRange(int bytenum) + private CmsError CheckByteRange(int bytenum) { if (bytenum < 0 || bytenum > 1) - throw new Nc_Exception(getError(BIT_NOT_IN_RANGE_ERROR, 0, 0)); + return BIT_NOT_IN_RANGE_ERROR; + else + return NO_ERROR; } @@ -1503,31 +1587,32 @@ namespace CMS_CORE.Osai //Read Language Configuration private void LanguageConfig() { - String [] ConfigLines; + String[] ConfigLines; String LangLine; String[] SPlitted; try { //Read From Files - ConfigLines = File.ReadAllLines(OSAI_WinNbiPath + ConfigFile ); + ConfigLines = File.ReadAllLines(OSAI_WinNbiPath + ConfigFile); //Find the first line that contains "ID_LANGUAGE" String LangLine = ConfigLines.FirstOrDefault(X => X.ToUpper().Contains("ID_LANGUAGE")); //Check if i found it 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 ) + if (SPlitted.Length != 2) throw new Nc_Exception("'ID_LANGUAGE' Line in Osai Config File is not configured correctly"); //Setup the variable OsaiLanguages = SPlitted[1].ToLower(); - + } catch (Exception ex) { @@ -1565,29 +1650,12 @@ namespace CMS_CORE.Osai } - - - //Manage the Exception Launch - private void ThrowNCException(Exception ex) - { - if (!(ex is Nc_Exception)) - Connected = false; - - //Catch the .Net exceptions - if (ex is EndpointNotFoundException) - throw new Nc_Exception("NC not found: " + ex.Message); - else - throw new Nc_Exception("NC Comunication Error: " + ex.Message); - } - - - //Manage the Languages private CultureInfo ConverToSTEPLanguage(String Lang) { - CultureInfo Culture = CultureInfo.GetCultures(CultureTypes.AllCultures).FirstOrDefault(X=>X.EnglishName.ToLower() == Lang.ToLower()); + CultureInfo Culture = CultureInfo.GetCultures(CultureTypes.AllCultures).FirstOrDefault(X => X.EnglishName.ToLower() == Lang.ToLower()); - if(Culture != null) + if (Culture != null) return Culture; else return new CultureInfo("en"); @@ -1639,13 +1707,13 @@ namespace CMS_CORE.Osai { Cndex.MSG_ERROR OsaiSerie10Err = new Cndex.MSG_ERROR(); - OsaiSerie10Err.BootID = (int)OpenError.BootID; - OsaiSerie10Err.UnIdSeq = (int)OpenError.UnIdSeq; - OsaiSerie10Err.Code_Err = (int)OpenError.CodeErr; - OsaiSerie10Err.Comando = (byte)OpenError.Comando; - OsaiSerie10Err.FormatTxt = OpenError.FormatTxt; - OsaiSerie10Err.Process = OpenError.Process; - OsaiSerie10Err.SubCom = (byte)OpenError.SubCom; + OsaiSerie10Err.BootID = (int)OpenError.BootID; + OsaiSerie10Err.UnIdSeq = (int)OpenError.UnIdSeq; + OsaiSerie10Err.Code_Err = (int)OpenError.CodeErr; + OsaiSerie10Err.Comando = (byte)OpenError.Comando; + OsaiSerie10Err.FormatTxt = OpenError.FormatTxt; + OsaiSerie10Err.Process = OpenError.Process; + OsaiSerie10Err.SubCom = (byte)OpenError.SubCom; return OsaiSerie10Err; } @@ -1666,203 +1734,202 @@ namespace CMS_CORE.Osai return OsaiSerie10Err; } + //Manage the Exception Launch + private CmsError ManageException(Exception ex) + { + Connected = false; + //Catch the .Net exceptions + if (ex is EndpointNotFoundException) + return NOT_CONNECTED_ERROR; + else + return new CmsError(INTERNAL_ERROR, ex.Message); + } + + private CmsError GetError(uint CMSError, uint errorClass, uint errorNum) + { + return new CmsError(CMSError, GetNCErrorMessage(CMSError, errorClass, errorNum)); + } // Convert the internal error in a readable-String error - private String getError(uint CMSError, uint Class, uint Num) + private string GetNCErrorMessage(uint CMSError, uint Class, uint Num) { - String szErrorClassDesc = "", szErrorDesc = "", ErrororOwner = ""; + string szErrorClassDesc = "", szErrorDesc = "", ErrorOwner = ""; - if (CMSError != 0) + ErrorOwner = "Osai-Core-Error: "; + + if (Class == 0 && Num == 0) + return ErrorOwner + "Generic Error On Function"; + + switch (Class) { - ErrororOwner = "CMS-Core-Error: "; - switch (CMSError) - { - case NOT_CONNECTED_ERROR: return ErrororOwner + "Nc not Connected"; - case PROC_NOT_FOUND_ERROR: return ErrororOwner + "Process Id not found"; - case FUNC_NOTALL_NC_ERROR: return ErrororOwner + "Function not allowed for this type of NC"; - case BIT_NOT_IN_RANGE_ERROR: return ErrororOwner + "Bit-number must be between 0 and 7"; - case BYTE_NOT_IN_RANGE_ERROR: return ErrororOwner + "Byte-number must be between 0 and 1"; - case INTERNAL_ERROR: return ErrororOwner + "Internal function error"; - case INCORRECT_PARAMETERS_ERROR:return ErrororOwner + "Incorrect Parameters error"; - } - } - else - { - ErrororOwner = "Osai-Core-Error: "; - - if (Class == 0 && Num == 0) - return ErrororOwner + "Generic Error On Function"; - - switch (Class) - { - case 2: - szErrorClassDesc = "SERVER error class"; - switch (Num) - { - case 1: szErrorDesc = "Memory for dynamic allocations insufficient"; break; - case 2: szErrorDesc = "Impossible to create synchronisation events"; break; - case 3: szErrorDesc = "Session aborted and no longer usable"; break; - case 4: szErrorDesc = "Session not open"; break; - case 5: szErrorDesc = "Impossible to allocate a channel"; break; - case 6: szErrorDesc = "Function of a non-existing process requested"; break; - case 7: szErrorDesc = "Broadcasting command aborted"; break; - case 8: szErrorDesc = "Buffer supplied by function in which the data supplied by the NC are copied is too small"; break; - case 9: szErrorDesc = "Session already open"; break; - case 10: szErrorDesc = "Broadcasting list invalid"; break; - case 11: szErrorDesc = "Realtime command aborted"; break; - case 12: szErrorDesc = "Function already active"; break; - case 13: szErrorDesc = "Function not yet active"; break; - case 14: szErrorDesc = "Reception thread ended"; break; - case 15: szErrorDesc = "No reply to command received within allotted time"; break; - case 16: szErrorDesc = "NC release to which you are connected is not compatible with communications with server"; break; - case 17: szErrorDesc = "Cookie does not identify any communication session"; break; - case 18: szErrorDesc = "Realtime thread cannot be created"; break; - case 19: szErrorDesc = "No more sections available"; break; - case 20: szErrorDesc = "Error in symbol acquisition"; break; - case 23: szErrorDesc = "Internal object instance cannot be created"; break; - case 24: szErrorDesc = "Broadcasting thread cannot be created"; break; - case 25: szErrorDesc = "Function cannot be executed in the numerical control boot phase"; break; - case 26: szErrorDesc = "Parameter wrong"; break; - case 27: szErrorDesc = "Invalid buffer"; break; - case 29: szErrorDesc = "Session identifier (UserSession) is invalid (session closed or never opened)"; break; - case 31: szErrorDesc = "Session identifier is invalid (value out of range) or session has been closed automatically by Cndex server"; break; - case 32: szErrorDesc = "Error writing registry"; break; - case 33: szErrorDesc = "Out of memory"; break; - case 34: szErrorDesc = "Function not available (boot phase is not correct or an error has occurred while loading the minimal SW configuration for running the requested command)"; break; - case 35: szErrorDesc = "Time-out while waiting for a generic event (used during reboot)"; break; - case 36: szErrorDesc = "Error when registering current thread as an OPENControl thread"; break; - case 37: szErrorDesc = "Error when launching or running an external process or application"; break; - case 38: szErrorDesc = "Function not implemented"; break; - case 39: szErrorDesc = "DLL not found"; break; - case 40: szErrorDesc = "A function entry point in a DLL was not found"; break; - case 41: szErrorDesc = "Error while declaring a shared memory area for data exchange with an application"; break; - case 42: szErrorDesc = "Unknown error"; break; - case 43: szErrorDesc = "The index of the active AMP in BootAmp.txt is not valid"; break; - case 44: szErrorDesc = "Error while reading from the registry"; break; - case 45: szErrorDesc = "Registry key not present"; break; - case 46: szErrorDesc = "Error while opening a file"; break; - case 47: szErrorDesc = "Error while reading data from file"; break; - case 48: szErrorDesc = "Error while writing data to file"; break; - case 49: szErrorDesc = "CNC name too long"; break; - } - return ErrororOwner + szErrorClassDesc + ": " + szErrorDesc + " (" + Class + "-" + Num + ")"; + case 2: + szErrorClassDesc = "SERVER error class"; + switch (Num) + { + case 1: szErrorDesc = "Memory for dynamic allocations insufficient"; break; + case 2: szErrorDesc = "Impossible to create synchronisation events"; break; + case 3: szErrorDesc = "Session aborted and no longer usable"; break; + case 4: szErrorDesc = "Session not open"; break; + case 5: szErrorDesc = "Impossible to allocate a channel"; break; + case 6: szErrorDesc = "Function of a non-existing process requested"; break; + case 7: szErrorDesc = "Broadcasting command aborted"; break; + case 8: szErrorDesc = "Buffer supplied by function in which the data supplied by the NC are copied is too small"; break; + case 9: szErrorDesc = "Session already open"; break; + case 10: szErrorDesc = "Broadcasting list invalid"; break; + case 11: szErrorDesc = "Realtime command aborted"; break; + case 12: szErrorDesc = "Function already active"; break; + case 13: szErrorDesc = "Function not yet active"; break; + case 14: szErrorDesc = "Reception thread ended"; break; + case 15: szErrorDesc = "No reply to command received within allotted time"; break; + case 16: szErrorDesc = "NC release to which you are connected is not compatible with communications with server"; break; + case 17: szErrorDesc = "Cookie does not identify any communication session"; break; + case 18: szErrorDesc = "Realtime thread cannot be created"; break; + case 19: szErrorDesc = "No more sections available"; break; + case 20: szErrorDesc = "Error in symbol acquisition"; break; + case 23: szErrorDesc = "Internal object instance cannot be created"; break; + case 24: szErrorDesc = "Broadcasting thread cannot be created"; break; + case 25: szErrorDesc = "Function cannot be executed in the numerical control boot phase"; break; + case 26: szErrorDesc = "Parameter wrong"; break; + case 27: szErrorDesc = "Invalid buffer"; break; + case 29: szErrorDesc = "Session identifier (UserSession) is invalid (session closed or never opened)"; break; + case 31: szErrorDesc = "Session identifier is invalid (value out of range) or session has been closed automatically by Cndex server"; break; + case 32: szErrorDesc = "Error writing registry"; break; + case 33: szErrorDesc = "Out of memory"; break; + case 34: szErrorDesc = "Function not available (boot phase is not correct or an error has occurred while loading the minimal SW configuration for running the requested command)"; break; + case 35: szErrorDesc = "Time-out while waiting for a generic event (used during reboot)"; break; + case 36: szErrorDesc = "Error when registering current thread as an OPENControl thread"; break; + case 37: szErrorDesc = "Error when launching or running an external process or application"; break; + case 38: szErrorDesc = "Function not implemented"; break; + case 39: szErrorDesc = "DLL not found"; break; + case 40: szErrorDesc = "A function entry point in a DLL was not found"; break; + case 41: szErrorDesc = "Error while declaring a shared memory area for data exchange with an application"; break; + case 42: szErrorDesc = "Unknown error"; break; + case 43: szErrorDesc = "The index of the active AMP in BootAmp.txt is not valid"; break; + case 44: szErrorDesc = "Error while reading from the registry"; break; + case 45: szErrorDesc = "Registry key not present"; break; + case 46: szErrorDesc = "Error while opening a file"; break; + case 47: szErrorDesc = "Error while reading data from file"; break; + case 48: szErrorDesc = "Error while writing data to file"; break; + case 49: szErrorDesc = "CNC name too long"; break; + } + return ErrorOwner + szErrorClassDesc + ": " + szErrorDesc + " (" + Class + "-" + Num + ")"; - case 3: - szErrorClassDesc = "NETBIOS error class"; - switch (Num) - { - case 0x1: szErrorDesc = "Illegal buffer length"; break; - case 0x3: szErrorDesc = "Illegal command"; break; - case 0x5: szErrorDesc = "Command timed out"; break; - case 0x6: szErrorDesc = "Message incomplete, issue another command"; break; - case 0x7: szErrorDesc = "Illegal buffer address"; break; - case 0x8: szErrorDesc = "Session number out of range"; break; - case 0x9: szErrorDesc = "No resource available"; break; - case 0xA: szErrorDesc = "Session closed"; break; - case 0xB: szErrorDesc = "Command cancelled"; break; - case 0xD: szErrorDesc = "Duplicate name"; break; - case 0xE: szErrorDesc = "Name table full"; break; - case 0xF: szErrorDesc = "No deletions, name has active sessions"; break; - case 0x11: szErrorDesc = "Local session table full"; break; - case 0x12: szErrorDesc = "Remote session table full"; break; - case 0x13: szErrorDesc = "Illegal name number"; break; - case 0x14: szErrorDesc = "No callname"; break; - case 0x15: szErrorDesc = "Cannot put * in NCB_NAME"; break; - case 0x16: szErrorDesc = "Name in use on remote adapter"; break; - case 0x17: szErrorDesc = "Name deleted"; break; - case 0x18: szErrorDesc = "Session ended abnormally"; break; - case 0x19: szErrorDesc = "Name conflict detected"; break; - case 0x21: szErrorDesc = "Interface busy, IRET before retrying"; break; - case 0x22: szErrorDesc = "Too many commands outstanding, retry later"; break; - case 0x23: szErrorDesc = "Ncb_lana_num field invalid"; break; - case 0x24: szErrorDesc = "Command completed while cancel occurring"; break; - case 0x26: szErrorDesc = "Command not valid to cancel"; break; - case 0x30: szErrorDesc = "Name defined by another local process"; break; - case 0x34: szErrorDesc = "Environment undefined. RESET required"; break; - case 0x35: szErrorDesc = "Required OS resources exhausted"; break; - case 0x36: szErrorDesc = "Max number of applications exceeded"; break; - case 0x37: szErrorDesc = "No saps available for netbios"; break; - case 0x38: szErrorDesc = "Requested resources are not available"; break; - case 0x39: szErrorDesc = "Invalid ncb address or length > segment"; break; - case 0x3B: szErrorDesc = "Invalid NCB DDID"; break; - case 0x3C: szErrorDesc = "Lock of user area failed"; break; - case 0x3F: szErrorDesc = "NETBIOS not loaded"; break; - case 0x40: szErrorDesc = "System error"; break; - } - return ErrororOwner + szErrorClassDesc + ": " + szErrorDesc + " (" + Class + "-" + Num + ")"; + case 3: + szErrorClassDesc = "NETBIOS error class"; + switch (Num) + { + case 0x1: szErrorDesc = "Illegal buffer length"; break; + case 0x3: szErrorDesc = "Illegal command"; break; + case 0x5: szErrorDesc = "Command timed out"; break; + case 0x6: szErrorDesc = "Message incomplete, issue another command"; break; + case 0x7: szErrorDesc = "Illegal buffer address"; break; + case 0x8: szErrorDesc = "Session number out of range"; break; + case 0x9: szErrorDesc = "No resource available"; break; + case 0xA: szErrorDesc = "Session closed"; break; + case 0xB: szErrorDesc = "Command cancelled"; break; + case 0xD: szErrorDesc = "Duplicate name"; break; + case 0xE: szErrorDesc = "Name table full"; break; + case 0xF: szErrorDesc = "No deletions, name has active sessions"; break; + case 0x11: szErrorDesc = "Local session table full"; break; + case 0x12: szErrorDesc = "Remote session table full"; break; + case 0x13: szErrorDesc = "Illegal name number"; break; + case 0x14: szErrorDesc = "No callname"; break; + case 0x15: szErrorDesc = "Cannot put * in NCB_NAME"; break; + case 0x16: szErrorDesc = "Name in use on remote adapter"; break; + case 0x17: szErrorDesc = "Name deleted"; break; + case 0x18: szErrorDesc = "Session ended abnormally"; break; + case 0x19: szErrorDesc = "Name conflict detected"; break; + case 0x21: szErrorDesc = "Interface busy, IRET before retrying"; break; + case 0x22: szErrorDesc = "Too many commands outstanding, retry later"; break; + case 0x23: szErrorDesc = "Ncb_lana_num field invalid"; break; + case 0x24: szErrorDesc = "Command completed while cancel occurring"; break; + case 0x26: szErrorDesc = "Command not valid to cancel"; break; + case 0x30: szErrorDesc = "Name defined by another local process"; break; + case 0x34: szErrorDesc = "Environment undefined. RESET required"; break; + case 0x35: szErrorDesc = "Required OS resources exhausted"; break; + case 0x36: szErrorDesc = "Max number of applications exceeded"; break; + case 0x37: szErrorDesc = "No saps available for netbios"; break; + case 0x38: szErrorDesc = "Requested resources are not available"; break; + case 0x39: szErrorDesc = "Invalid ncb address or length > segment"; break; + case 0x3B: szErrorDesc = "Invalid NCB DDID"; break; + case 0x3C: szErrorDesc = "Lock of user area failed"; break; + case 0x3F: szErrorDesc = "NETBIOS not loaded"; break; + case 0x40: szErrorDesc = "System error"; break; + } + return ErrorOwner + szErrorClassDesc + ": " + szErrorDesc + " (" + Class + "-" + Num + ")"; - case 4: - szErrorClassDesc = "CNC error class"; - switch (Num) - { - case 0x101: szErrorDesc = "Command unknown"; break; - case 0x102: szErrorDesc = "No channel available"; break; - case 0x103: szErrorDesc = "Tick requested not multiple of system tick"; break; - case 0x104: szErrorDesc = "Id channel wrong"; break; - case 0x105: szErrorDesc = "Data acquisition still underway"; break; - case 0x106: szErrorDesc = "Channel not configured"; break; - case 0x107: szErrorDesc = "Error on stop trigger"; break; - case 0x108: szErrorDesc = "Channel already configured for other types of data"; break; - case 0x109: szErrorDesc = "Error codes for Dry Run functions"; break; - case 0x200: szErrorDesc = "Process not configured"; break; - case 0x201: szErrorDesc = "Axis not present in process"; break; - case 0x202: szErrorDesc = "Dry run not configured"; break; - case 0x203: szErrorDesc = "Dry run already being executed"; break; - case 0x204: szErrorDesc = "Dry run already in stop status"; break; - } - return ErrororOwner + szErrorClassDesc + ": " + szErrorDesc + " (" + Class + "-" + Num + ")"; + case 4: + szErrorClassDesc = "CNC error class"; + switch (Num) + { + case 0x101: szErrorDesc = "Command unknown"; break; + case 0x102: szErrorDesc = "No channel available"; break; + case 0x103: szErrorDesc = "Tick requested not multiple of system tick"; break; + case 0x104: szErrorDesc = "Id channel wrong"; break; + case 0x105: szErrorDesc = "Data acquisition still underway"; break; + case 0x106: szErrorDesc = "Channel not configured"; break; + case 0x107: szErrorDesc = "Error on stop trigger"; break; + case 0x108: szErrorDesc = "Channel already configured for other types of data"; break; + case 0x109: szErrorDesc = "Error codes for Dry Run functions"; break; + case 0x200: szErrorDesc = "Process not configured"; break; + case 0x201: szErrorDesc = "Axis not present in process"; break; + case 0x202: szErrorDesc = "Dry run not configured"; break; + case 0x203: szErrorDesc = "Dry run already being executed"; break; + case 0x204: szErrorDesc = "Dry run already in stop status"; break; + } + return ErrorOwner + szErrorClassDesc + ": " + szErrorDesc + " (" + Class + "-" + Num + ")"; - case 5: - szErrorClassDesc = "FILESYSTEM error class"; - switch (Num) - { - case 0x001: szErrorDesc = "An error has occurred while opening a transaction with the target for file transfer."; break; - case 0x002: szErrorDesc = "An error has occurred while closing a transaction with the target for file transfer."; break; - case 0x003: szErrorDesc = "Invalid file ID."; break; - case 0x004: szErrorDesc = "The number of transaction is not valid."; break; - case 0x005: szErrorDesc = "Error opening file."; break; - case 0x006: szErrorDesc = "Error closing file."; break; - case 0x007: szErrorDesc = "A file path containing wildcards was passed to a function that does not support wildcards."; break; - case 0x008: szErrorDesc = "Error reading data from file."; break; - case 0x009: szErrorDesc = "Error writing data to file."; break; - case 0x00A: szErrorDesc = "The logical drive was not found on the target."; break; - case 0x00C: szErrorDesc = "The specified file path was not valid."; break; - case 0x00D: szErrorDesc = "An attempt was made to create a logical drive on the target with the same name as an existing logical drive."; break; - case 0x00E: szErrorDesc = "The invoked function requires a different security level on the target."; break; - case 0x00F: szErrorDesc = "A logical drive cannot be created on a remote PC."; break; - case 0x010: szErrorDesc = "Insufficient disk space to complete the requested operation."; break; - case 0x011: szErrorDesc = "The requested file was not found."; break; - } - return ErrororOwner + szErrorClassDesc + ": " + szErrorDesc + " (" + Class + "-" + Num + ")"; + case 5: + szErrorClassDesc = "FILESYSTEM error class"; + switch (Num) + { + case 0x001: szErrorDesc = "An error has occurred while opening a transaction with the target for file transfer."; break; + case 0x002: szErrorDesc = "An error has occurred while closing a transaction with the target for file transfer."; break; + case 0x003: szErrorDesc = "Invalid file ID."; break; + case 0x004: szErrorDesc = "The number of transaction is not valid."; break; + case 0x005: szErrorDesc = "Error opening file."; break; + case 0x006: szErrorDesc = "Error closing file."; break; + case 0x007: szErrorDesc = "A file path containing wildcards was passed to a function that does not support wildcards."; break; + case 0x008: szErrorDesc = "Error reading data from file."; break; + case 0x009: szErrorDesc = "Error writing data to file."; break; + case 0x00A: szErrorDesc = "The logical drive was not found on the target."; break; + case 0x00C: szErrorDesc = "The specified file path was not valid."; break; + case 0x00D: szErrorDesc = "An attempt was made to create a logical drive on the target with the same name as an existing logical drive."; break; + case 0x00E: szErrorDesc = "The invoked function requires a different security level on the target."; break; + case 0x00F: szErrorDesc = "A logical drive cannot be created on a remote PC."; break; + case 0x010: szErrorDesc = "Insufficient disk space to complete the requested operation."; break; + case 0x011: szErrorDesc = "The requested file was not found."; break; + } + return ErrorOwner + szErrorClassDesc + ": " + szErrorDesc + " (" + Class + "-" + Num + ")"; - case 6: - szErrorClassDesc = "WINDOWS error class"; + case 6: + szErrorClassDesc = "WINDOWS error class"; - szErrorDesc = new Win32Exception((int)Num).Message; - return ErrororOwner + szErrorClassDesc + ": " + szErrorDesc + " (" + Class + "-" + Num + ")"; + szErrorDesc = new Win32Exception((int)Num).Message; + return ErrorOwner + szErrorClassDesc + ": " + szErrorDesc + " (" + Class + "-" + Num + ")"; - case 10: - szErrorClassDesc = "DLL_INTERFACE error class"; - switch (Num) - { - case 1: szErrorDesc = "The server has been created more than once"; break; - case 2: szErrorDesc = "An error has occurred during the creation of the Cndex server"; break; - 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; + case 10: + szErrorClassDesc = "DLL_INTERFACE error class"; + switch (Num) + { + case 1: szErrorDesc = "The server has been created more than once"; break; + case 2: szErrorDesc = "An error has occurred during the creation of the Cndex server"; break; + 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 ErrororOwner + szErrorClassDesc + ": " + szErrorDesc + " (" + Class + "-" + Num + ")"; + } + return ErrorOwner + szErrorClassDesc + ": " + szErrorDesc + " (" + Class + "-" + Num + ")"; - default: return ErrororOwner + " Generic Osai Error - Class: " + Class + " Num: " + Num; - - } + default: return ErrorOwner + " Generic Osai Error - Class: " + Class + " Num: " + Num; } - return ErrororOwner + "Generic Error On Function"; + return ErrorOwner + "Generic Error On Function"; + + } #endregion diff --git a/CMS_CORE_Library/Siemens/Nc_Siemens.cs b/CMS_CORE_Library/Siemens/Nc_Siemens.cs index caa868e..765c620 100644 --- a/CMS_CORE_Library/Siemens/Nc_Siemens.cs +++ b/CMS_CORE_Library/Siemens/Nc_Siemens.cs @@ -17,31 +17,31 @@ 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; + 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; // 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 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"; + 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"; // Global Variables private DateTime Last_Static_Read; @@ -49,14 +49,14 @@ namespace CMS_CORE.Siemens private String Cnc_name; private String Cnc_SftVersion; private String Cnc_SeriesNum; - private String Cms_MachNumber; + private String Cms_MachNumber; private uint ConfChannelNo; private uint MaxChannelNo; private uint SiemensLanguage; // STatic variables private static AlarmSvc SiemensAlmSvc; - private static Alarm[] SiemensAlarms; + private static Alarm[] SiemensAlarms; /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #region Contructor & global methods @@ -76,30 +76,34 @@ namespace CMS_CORE.Siemens //Setup timeout TimeoutConn = ConnectionTimeOut; - - //Check if Siemens Environment is started - CheckSiemensEnv(); - + SiemensAlarms = new Alarm[] { }; } - + //Connect Method - public override void NC_Connect() - { + public override CmsError NC_Connect() + { //Try to get information try - { + { + //Check if Siemens Environment is started + CmsError cmsError = CheckSiemensEnv(); + if (cmsError.errorCode != OK) + return cmsError; + //Set Connected to FALSE and close the session Connected = true; //Read static Data - ReadStaticNCData(); + cmsError = ReadStaticNCData(); + if (cmsError.errorCode != OK) + return cmsError; //Setup the alarms (Only managed in this way (Siemens Thread) - if(SiemensAlmSvc == null) + if (SiemensAlmSvc == null) { - SiemensAlarms = new Alarm[]{ }; + SiemensAlarms = new Alarm[] { }; SiemensAlmSvc = new AlarmSvc(ConvertToSTEPLanguage(SiemensLanguage).ThreeLetterISOLanguageName); SiemensAlmSvc.Subscribe(AlarmsChanged); } @@ -107,18 +111,21 @@ namespace CMS_CORE.Siemens } catch (Exception ex) { - ThrowNCException(ex); + return ManageException(ex); } + + return NO_ERROR; } //Disconnect Method - public override void NC_Disconnect() + public override CmsError NC_Disconnect() { //Set Connected to FALSE and close the session Connected = false; + return NO_ERROR; } #endregion @@ -127,105 +134,142 @@ namespace CMS_CORE.Siemens #region High level methods //Get the processes-count configurated - public override void NC_RProcessesNum(ref ushort ProcNumber) + public override CmsError NC_RProcessesNum(ref ushort ProcNumber) { - ReadStaticNCData(); + CmsError cmsError = ReadStaticNCData(); + if (cmsError.errorCode != OK) + return cmsError; + ProcNumber = (ushort)ConfChannelNo; + + return NO_ERROR; } //Get the NC model Name - public override void NC_RModelName(ref string ModelName) + public override CmsError NC_RModelName(ref string ModelName) { - ReadStaticNCData(); + CmsError cmsError = ReadStaticNCData(); + if (cmsError.errorCode != OK) + return cmsError; + ModelName = Cnc_name; + + return NO_ERROR; + } //Get the NC Software Version - public override void NC_RSoftwareVersion(ref string SWV) + public override CmsError NC_RSoftwareVersion(ref string SWV) { - ReadStaticNCData(); + CmsError cmsError = ReadStaticNCData(); + if (cmsError.errorCode != OK) + return cmsError; + SWV = Cnc_SftVersion; + + return NO_ERROR; } //Get the NC Language - public override void NC_RLanguage(ref CultureInfo Language) + public override CmsError NC_RLanguage(ref CultureInfo Language) { - ReadStaticNCData(); + CmsError cmsError = ReadStaticNCData(); + if (cmsError.errorCode != OK) + return cmsError; + Language = ConvertToSTEPLanguage(SiemensLanguage); + + return NO_ERROR; } //Get the NC Serial number - public override void NC_RSerialNumber(ref string SN) + public override CmsError NC_RSerialNumber(ref string SN) { - ReadStaticNCData(); + CmsError cmsError = ReadStaticNCData(); + if (cmsError.errorCode != OK) + return cmsError; + SN = Cnc_SeriesNum; + + return NO_ERROR; } //Get CMS Machine number - public override void NC_RMachineNumber(ref string MachNumber) + public override CmsError NC_RMachineNumber(ref string MachNumber) { - ReadStaticNCData(); + CmsError cmsError = ReadStaticNCData(); + if (cmsError.errorCode != OK) + return cmsError; + MachNumber = Cms_MachNumber; + + return NO_ERROR; } //Get the Date-Time of the NC - public override void NC_RDateTime(ref DateTime ActualTime) + public override CmsError NC_RDateTime(ref DateTime ActualTime) { //Check if the NC is Connected - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; - //Setup variables - DataSvc Data = new DataSvc(); - Data.Timeout = TimeoutConn; - Data.PriorityFlag = SlPriority.lowPriority; - Item ReadItem = new Item(PathNcTime); - //Try to get information try { + //Setup variables + DataSvc Data = new DataSvc(); + Data.Timeout = TimeoutConn; + Data.PriorityFlag = SlPriority.lowPriority; + Item ReadItem = new Item(PathNcTime); + //Read Data Data.Read(ReadItem); //Save Data - ActualTime = (DateTime) ReadItem.Value; + ActualTime = (DateTime)ReadItem.Value; } catch (Exception ex) { - ThrowNCException(ex); + return ManageException(ex); } + + return NO_ERROR; } //Get the process Mode - public override void PROC_RMode(ushort ProcNumber, ref PROC_Mode Mode) + public override CmsError PROC_RMode(ushort ProcNumber, ref PROC_Mode Mode) { //Check if the NC is Connected - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; - //Setup variables - DataSvc Data = new DataSvc(); - Data.Timeout = TimeoutConn; - Data.PriorityFlag = SlPriority.highPriority; - Item ReadItem = new Item(PathGenericNcMode + "[u"+ ProcNumber + "]"); - Item ReadItemIncr = new Item(PathIncrJog + "[u" + ProcNumber + "]"); - Item ReadItemAdv = new Item(PathAdvancedJog + "[u" + ProcNumber + "]"); - //Try to get information try { + //Setup variables + DataSvc Data = new DataSvc(); + Data.Timeout = TimeoutConn; + Data.PriorityFlag = SlPriority.highPriority; + Item ReadItem = new Item(PathGenericNcMode + "[u" + ProcNumber + "]"); + Item ReadItemIncr = new Item(PathIncrJog + "[u" + ProcNumber + "]"); + Item ReadItemAdv = new Item(PathAdvancedJog + "[u" + ProcNumber + "]"); + //Read Data Data.Read(ReadItem); Data.Read(ReadItemIncr); @@ -233,31 +277,35 @@ namespace CMS_CORE.Siemens //Save Data Mode = ConvertToSTEPMode((uint)ReadItem.Value, (uint)ReadItemIncr.Value, (uint)ReadItemAdv.Value); - + } catch (Exception ex) { - ThrowNCException(ex); - } + return ManageException(ex); + } + + return NO_ERROR; } //Get the process status - public override void PROC_RStatus(ushort ProcNumber, ref PROC_Status Status) - { + public override CmsError PROC_RStatus(ushort ProcNumber, ref PROC_Status Status) + { //Check if the NC is Connected - CheckConnection(); - - //Setup variables - DataSvc Data = new DataSvc(); - Data.Timeout = TimeoutConn; - Data.PriorityFlag = SlPriority.highPriority; - Item ReadItem = new Item(PathGenericNcState + "[u" + ProcNumber + "]"); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; //Try to get information try { + //Setup variables + DataSvc Data = new DataSvc(); + Data.Timeout = TimeoutConn; + Data.PriorityFlag = SlPriority.highPriority; + Item ReadItem = new Item(PathGenericNcState + "[u" + ProcNumber + "]"); + //Read Data Data.Read(ReadItem); @@ -267,35 +315,37 @@ namespace CMS_CORE.Siemens } catch (Exception ex) { - ThrowNCException(ex); + return ManageException(ex); } + + return NO_ERROR; } //Get PP Lines - public override void PROC_RPPLines(ushort ProcNumber, ref List Lines) + public override CmsError PROC_RPPLines(ushort ProcNumber, ref List Lines) { + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; String[] newLines; - - //Check if the NC is Connected - CheckConnection(); - - //Setup variables - DataSvc Data = new DataSvc(); - Data.Timeout = TimeoutConn; - Data.PriorityFlag = SlPriority.highPriority; - Item ReadItem = new Item(PathActProgLines + "[u" + ProcNumber + "]"); - //Try to get information try { + //Setup variables + DataSvc Data = new DataSvc(); + Data.Timeout = TimeoutConn; + Data.PriorityFlag = SlPriority.highPriority; + Item ReadItem = new Item(PathActProgLines + "[u" + ProcNumber + "]"); + //Read Data Data.Read(ReadItem); //Save Data - newLines = ((String)ReadItem.Value).Replace("\r",string.Empty).Split('\n'); + newLines = ((String)ReadItem.Value).Replace("\r", string.Empty).Split('\n'); //Setup the return values Lines.Clear(); @@ -303,35 +353,39 @@ namespace CMS_CORE.Siemens Lines.Add(Line); //Remove the first Line (the previous line) - if(Lines.Count > 0) + if (Lines.Count > 0) Lines.RemoveAt(0); } catch (Exception ex) { - ThrowNCException(ex); + return ManageException(ex); } + + return NO_ERROR; } //Get PP Name - public override void PROC_RPPName(ushort ProcNumber, ref string Name) + public override CmsError PROC_RPPName(ushort ProcNumber, ref string Name) { + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; + String RetString; int LastUnderscore; - //Check if the NC is Connected - CheckConnection(); - - //Setup variables - DataSvc Data = new DataSvc(); - Data.Timeout = TimeoutConn; - Data.PriorityFlag = SlPriority.highPriority; - Item ReadItem = new Item(PathActProgName + "[u" + ProcNumber + "]"); - //Try to get information try { + //Setup variables + DataSvc Data = new DataSvc(); + Data.Timeout = TimeoutConn; + Data.PriorityFlag = SlPriority.highPriority; + Item ReadItem = new Item(PathActProgName + "[u" + ProcNumber + "]"); + //Read Data Data.Read(ReadItem); @@ -348,72 +402,82 @@ namespace CMS_CORE.Siemens } catch (Exception ex) { - ThrowNCException(ex); + return ManageException(ex); } - + + return NO_ERROR; } //Get the Nc Active Alarms - public override void NC_RActiveAlarms(ref List 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 => x.Message).ToList(); + + return NO_ERROR; } //Get the PLC Active Messages - public override void PLC_RActiveMessages(ref List Alarms) + public override CmsError PLC_RActiveMessages(ref List Alarms) { Alarms = SiemensAlarms.Where(x => x.Id >= IDMinPLCMessage && x.Id <= IDMaxPLCMessage).Select(x => x.Message).ToList(); + + return NO_ERROR; } //Get the process Active Alarms - public override void PROC_RActiveAlarms(ushort ProcNumber, ref List 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 => x.Message).ToList(); + + return NO_ERROR; } - + //Get a dictionary with the Actual position of the axes in Process - public override void AXES_RInterpPosition(ushort ProcNumber, ref Dictionary Axes) + public override CmsError AXES_RInterpPosition(ushort ProcNumber, ref Dictionary Axes) { - Axes.Clear(); + return FUNCTION_NOT_ALLOWED_ERROR; } //Get a dictionary with the Machine position of the axes in Process - public override void AXES_RMachinePosition(ushort ProcNumber, ref Dictionary Axes) + public override CmsError AXES_RMachinePosition(ushort ProcNumber, ref Dictionary Axes) { - Axes.Clear(); + return FUNCTION_NOT_ALLOWED_ERROR; } //Get a dictionary with the Programmed position of the axes in Process - public override void AXES_RProgrPosition(ushort ProcNumber, ref Dictionary Axes) + public override CmsError AXES_RProgrPosition(ushort ProcNumber, ref Dictionary Axes) { - Axes.Clear(); + return FUNCTION_NOT_ALLOWED_ERROR; } //Get a dictionary with the Following Error of the axes in Process - public override void AXES_RFollowingError(ushort ProcNumber, ref Dictionary Axes) + public override CmsError AXES_RFollowingError(ushort ProcNumber, ref Dictionary Axes) { - Axes.Clear(); + return FUNCTION_NOT_ALLOWED_ERROR; } //Get a dictionary with the Distance To Go of the axes in Process - public override void AXES_RDistanceToGo(ushort ProcNumber, ref Dictionary Axes) + public override CmsError AXES_RDistanceToGo(ushort ProcNumber, ref Dictionary Axes) { - Axes.Clear(); + return FUNCTION_NOT_ALLOWED_ERROR; } #endregion @@ -425,23 +489,28 @@ namespace CMS_CORE.Siemens // BOOLEAN (NC) <-> BOOLEAN (.NET) //Read-Write a Boolean-Value inside the NC. - public override void 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 - CheckConnection(); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; //Check if the Bit Number is Correct - CheckBitRange(MemBit); - - //Setup variables - DataSvc Data = new DataSvc(); - Data.Timeout = TimeoutConn; - Data.PriorityFlag = SlPriority.highPriority; - Item Item = new Item(ConvertMemToPath(MemType, MemTable, MemIndex, MemBit, 1, 'X')); + cmsError = CheckBitRange(MemBit); + if (cmsError.errorCode != OK) + return cmsError; //Try to get information try { + //Setup variables + DataSvc Data = new DataSvc(); + Data.Timeout = TimeoutConn; + Data.PriorityFlag = SlPriority.highPriority; + Item Item = new Item(ConvertMemToPath(MemType, MemTable, MemIndex, MemBit, 1, 'X')); + + //Read-Write Data if (bWrite) { @@ -453,12 +522,14 @@ namespace CMS_CORE.Siemens Data.Read(Item); Value = (bool)Item.Value; - } + } } catch (Exception ex) { - ThrowNCException(ex); + return ManageException(ex); } + + return NO_ERROR; } @@ -468,20 +539,22 @@ namespace CMS_CORE.Siemens // BYTE (NC) <-> BYTE (.NET) //Read-Write a Byte-Value inside the NC. In writing-mode the field "Number" is not required - public override void 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) { //Check if the NC is Connected - CheckConnection(); - - //Setup variables - DataSvc Data = new DataSvc(); - Data.Timeout = TimeoutConn; - Data.PriorityFlag = SlPriority.highPriority; - Item Item = new Item(ConvertMemToPath(MemType, MemTable, MemIndex, 0, (bWrite) ? Value.Count : Number, 'B')); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; //Try to get/set information try { + //Setup variables + DataSvc Data = new DataSvc(); + Data.Timeout = TimeoutConn; + Data.PriorityFlag = SlPriority.highPriority; + Item Item = new Item(ConvertMemToPath(MemType, MemTable, MemIndex, 0, (bWrite) ? Value.Count : Number, 'B')); + //Read-Write Data if (bWrite) { @@ -503,47 +576,52 @@ namespace CMS_CORE.Siemens } catch (Exception ex) { - ThrowNCException(ex); + return ManageException(ex); } + + return NO_ERROR; } - + //Read-Write a Byte-Value-List inside the NC. In writing-mode the field "Number" is not required - public override void 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) { List ListValue = new List() { Value }; - //Check if the NC is Connected - CheckConnection(); - //uses the List method with one-element list - MEM_RWByteList(bWrite, Process, MemType, MemIndex, MemByte, 1, ref ListValue); + CmsError cmsError = MEM_RWByteList(bWrite, Process, MemType, MemTable, MemIndex, MemByte, 1, ref ListValue); + if (cmsError.errorCode != OK) + 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 void 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 - CheckConnection(); - - //Setup variables - DataSvc Data = new DataSvc(); - Data.Timeout = TimeoutConn; - Data.PriorityFlag = SlPriority.highPriority; - Item Item = new Item(ConvertMemToPath(MemType, MemTable, MemIndex, 0, (bWrite) ? Value.Count : Number, 'W')); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; //Try to get/set information try { + //Setup variables + DataSvc Data = new DataSvc(); + Data.Timeout = TimeoutConn; + Data.PriorityFlag = SlPriority.highPriority; + Item Item = new Item(ConvertMemToPath(MemType, MemTable, MemIndex, 0, (bWrite) ? Value.Count : Number, 'W')); + //Read-Write Data if (bWrite) { @@ -552,7 +630,7 @@ namespace CMS_CORE.Siemens } else { - Data.Read(Item); + Data.Read(Item); if (Item.Value.GetType().IsArray) Value = Array.ConvertAll(((object[])Item.Value).Cast().ToArray(), input => (ushort)input).ToList(); else @@ -565,23 +643,26 @@ namespace CMS_CORE.Siemens } catch (Exception ex) { - ThrowNCException(ex); + return ManageException(ex); } + + return NO_ERROR; } //Write a Word-Value inside the NC. In writing-mode the field "Number" is not required - public override void 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) { List ListValue = new List() { Value }; - //Check if the NC is Connected - CheckConnection(); - //uses the List method with one-element list - MEM_RWWordList(bWrite, Process, MemType, MemTable, MemIndex, 1, ref ListValue); + CmsError cmsError = MEM_RWWordList(bWrite, Process, MemType, MemTable, MemIndex, 1, ref ListValue); + if (cmsError.errorCode != OK) + return cmsError; Value = ListValue.First(); + + return NO_ERROR; } @@ -589,20 +670,22 @@ namespace CMS_CORE.Siemens //-------------------------------------------------------------------------------------------------------------------------- // WORD (NC) <-> SHORT (.NET) - public override void 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 - CheckConnection(); - - //Setup variables - DataSvc Data = new DataSvc(); - Data.Timeout = TimeoutConn; - Data.PriorityFlag = SlPriority.highPriority; - Item Item = new Item(ConvertMemToPath(MemType, MemTable, MemIndex, 0, (bWrite) ? Value.Count : Number, 'W')); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; //Try to get/set information try { + //Setup variables + DataSvc Data = new DataSvc(); + Data.Timeout = TimeoutConn; + Data.PriorityFlag = SlPriority.highPriority; + Item Item = new Item(ConvertMemToPath(MemType, MemTable, MemIndex, 0, (bWrite) ? Value.Count : Number, 'W')); + //Read-Write Data if (bWrite) { @@ -624,22 +707,25 @@ namespace CMS_CORE.Siemens } catch (Exception ex) { - ThrowNCException(ex); + return ManageException(ex); } + + return NO_ERROR; } - public override void 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) { List ListValue = new List() { Value }; - //Check if the NC is Connected - CheckConnection(); - //uses the List method with one-element list - MEM_RWShortList(bWrite, Process, MemType, MemTable, MemIndex, 1, ref ListValue); + CmsError cmsError = MEM_RWShortList(bWrite, Process, MemType, MemTable, MemIndex, 1, ref ListValue); + if (cmsError.errorCode != OK) + return cmsError; Value = ListValue.First(); + + return NO_ERROR; } @@ -648,20 +734,22 @@ namespace CMS_CORE.Siemens // DWORD (NC) <-> UINT (.NET) //Write a Word-Value-List inside the NC. In writing-mode the field "Number" is not required - public override void 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 - CheckConnection(); - - //Setup variables - DataSvc Data = new DataSvc(); - Data.Timeout = TimeoutConn; - Data.PriorityFlag = SlPriority.highPriority; - Item Item = new Item(ConvertMemToPath(MemType, MemTable, MemIndex, 0, (bWrite) ? Value.Count : Number, 'D')); + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; //Try to get/set information try { + //Setup variables + DataSvc Data = new DataSvc(); + Data.Timeout = TimeoutConn; + Data.PriorityFlag = SlPriority.highPriority; + Item Item = new Item(ConvertMemToPath(MemType, MemTable, MemIndex, 0, (bWrite) ? Value.Count : Number, 'D')); + //Read-Write Data if (bWrite) { @@ -683,45 +771,50 @@ namespace CMS_CORE.Siemens } catch (Exception ex) { - ThrowNCException(ex); + return ManageException(ex); } + + return NO_ERROR; } //Write a Word-Value inside the NC. In writing-mode the field "Number" is not required - public override void 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) { List ListValue = new List() { Value }; - //Check if the NC is Connected - CheckConnection(); - //uses the List method with one-element list - MEM_RWDWordList(bWrite, Process, MemType, MemTable, MemIndex, 1, ref ListValue); + CmsError cmsError = MEM_RWDWordList(bWrite, Process, MemType, MemTable, MemIndex, 1, ref ListValue); + if (cmsError.errorCode != OK) + 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 void MEM_RWIntegerList(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, int Number, ref List Value) - { - //Check if the NC is Connected - CheckConnection(); - //Setup variables - DataSvc Data = new DataSvc(); - Data.Timeout = TimeoutConn; - Data.PriorityFlag = SlPriority.highPriority; - Item Item = new Item(ConvertMemToPath(MemType, MemTable, MemIndex, 0, (bWrite) ? Value.Count : Number, 'D')); + //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) + { + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; //Try to get/set information try { + //Setup variables + DataSvc Data = new DataSvc(); + Data.Timeout = TimeoutConn; + Data.PriorityFlag = SlPriority.highPriority; + Item Item = new Item(ConvertMemToPath(MemType, MemTable, MemIndex, 0, (bWrite) ? Value.Count : Number, 'D')); + //Read-Write Data if (bWrite) { @@ -743,24 +836,25 @@ namespace CMS_CORE.Siemens } catch (Exception ex) { - ThrowNCException(ex); + return ManageException(ex); } + + return NO_ERROR; } - - //Write a Int-Value inside the NC. In writing-mode the field "Number" is not required - public override void 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) { List ListValue = new List() { Value }; - //Check if the NC is Connected - CheckConnection(); - //uses the List method with one-element list - MEM_RWIntegerList(bWrite, Process, MemType, MemTable, MemIndex, 1, ref ListValue); + CmsError cmsError = MEM_RWIntegerList(bWrite, Process, MemType, MemTable, MemIndex, 1, ref ListValue); + if (cmsError.errorCode != OK) + return cmsError; Value = ListValue.First(); + + return NO_ERROR; } @@ -768,142 +862,161 @@ namespace CMS_CORE.Siemens //-------------------------------------------------------------------------------------------------------------------------- // Other-NC Version of Memory-Access Methods - public override void 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) { - throw new Nc_Exception("CMS-Core-Error: Function not allowed for this type of NC"); + return FUNCTION_NOT_ALLOWED_ERROR; } - public override void 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) { - throw new Nc_Exception("CMS-Core-Error: Function not allowed for this type of NC"); + return FUNCTION_NOT_ALLOWED_ERROR; } - public override void 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) { - throw new Nc_Exception("CMS-Core-Error: Function not allowed for this type of NC"); + return FUNCTION_NOT_ALLOWED_ERROR; } - public override void 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) { - throw new Nc_Exception("CMS-Core-Error: Function not allowed for this type of NC"); + return FUNCTION_NOT_ALLOWED_ERROR; } - public override void 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) { - throw new Nc_Exception("CMS-Core-Error: Function not allowed for this type of NC"); + return FUNCTION_NOT_ALLOWED_ERROR; } - public override void 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) { - throw new Nc_Exception("CMS-Core-Error: Function not allowed for this type of NC"); + return FUNCTION_NOT_ALLOWED_ERROR; } - public override void 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) { - throw new Nc_Exception("CMS-Core-Error: Function not allowed for this type of NC"); + return FUNCTION_NOT_ALLOWED_ERROR; } - public override void 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) { - throw new Nc_Exception("CMS-Core-Error: Function not allowed for this type of NC"); + return FUNCTION_NOT_ALLOWED_ERROR; } - public override void 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) { - throw new Nc_Exception("CMS-Core-Error: Function not allowed for this type of NC"); + return FUNCTION_NOT_ALLOWED_ERROR; } - public override void 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) { - throw new Nc_Exception("CMS-Core-Error: Function not allowed for this type of NC"); + return FUNCTION_NOT_ALLOWED_ERROR; } - public override void 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) { - throw new Nc_Exception("CMS-Core-Error: Function not allowed for this type of NC"); + return FUNCTION_NOT_ALLOWED_ERROR; } //-------------------------------------------------------------------------------------------------------------------------- // PARAMS - public override void NC_RParam(short Index, short Bit, ref bool Value) + public override CmsError NC_RParam(short Index, short Bit, ref bool Value) { - throw new Nc_Exception("CMS-Core-Error: Function not allowed for this type of NC"); + return FUNCTION_NOT_ALLOWED_ERROR; } - public override void NC_RParam(short Index, ref byte Value) + public override CmsError NC_RParam(short Index, ref byte Value) { - throw new Nc_Exception("CMS-Core-Error: Function not allowed for this type of NC"); + return FUNCTION_NOT_ALLOWED_ERROR; } - public override void NC_RParam(short Index, ref short Value) + public override CmsError NC_RParam(short Index, ref short Value) { - throw new Nc_Exception("CMS-Core-Error: Function not allowed for this type of NC"); + return FUNCTION_NOT_ALLOWED_ERROR; } - public override void NC_RParam(short Index, ref int Value) + public override CmsError NC_RParam(short Index, ref int Value) { - throw new Nc_Exception("CMS-Core-Error: Function not allowed for this type of NC"); + return FUNCTION_NOT_ALLOWED_ERROR; } - public override void NC_RParam(short Index, ref double Value) + public override CmsError NC_RParam(short Index, ref double Value) { - throw new Nc_Exception("CMS-Core-Error: Function not allowed for this type of NC"); + return FUNCTION_NOT_ALLOWED_ERROR; } #endregion /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #region File Management - - public override void FILES_CopyProgram(string partProgramPath, string newPartProgramPath, bool failIfExist) - { - FileSvc FileData = new FileSvc(); - Node sourceNode = new Node(partProgramPath); - Node destNode = new Node(newPartProgramPath); - + public override CmsError FILES_CopyProgram(string partProgramPath, string newPartProgramPath, bool failIfExist) + { + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; try { + //Setup variables + FileSvc FileData = new FileSvc(); + Node sourceNode = new Node(partProgramPath); + Node destNode = new Node(newPartProgramPath); + //Execute Function FileData.Copy(sourceNode, destNode, failIfExist); } catch (Exception ex) { - ThrowNCException(ex); + return ManageException(ex); } + + return NO_ERROR; } - public override void FILES_DeleteProgram(string partProgramPath, string partProgramName) + public override CmsError FILES_DeleteProgram(string partProgramPath, string partProgramName) { - FileSvc FileData = new FileSvc(); + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; - Node sourceNode = new Node(partProgramPath); - try { + // Setup variables + FileSvc FileData = new FileSvc(); + Node sourceNode = new Node(partProgramPath); + //Execute Function FileData.Delete(sourceNode); } catch (Exception ex) { - ThrowNCException(ex); + return ManageException(ex); } + + return NO_ERROR; } - public override void FILES_RProgramToFile(string partProgramPath, FileStream localFile) + public override CmsError FILES_RProgramToFile(string partProgramPath, FileStream localFile) { - String TempFile = Path.GetTempFileName(); - FileSvc FileData = new FileSvc(); - Node sourceNode = new Node(partProgramPath); - Node destNode = new Node(TempFile); + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; try { + // Setup variables + String TempFile = Path.GetTempFileName(); + FileSvc FileData = new FileSvc(); + Node sourceNode = new Node(partProgramPath); + Node destNode = new Node(TempFile); + //Execute Function FileData.Copy(sourceNode, destNode, true); //Write to local file - Nc_Utils.WriteLocalFile(Nc_Utils.ReadLocalFile(new FileStream(TempFile,FileMode.Open)), ref localFile); + Nc_Utils.WriteLocalFile(Nc_Utils.ReadLocalFile(new FileStream(TempFile, FileMode.Open)), ref localFile); //Delete temporary file File.Delete(TempFile); @@ -911,35 +1024,45 @@ namespace CMS_CORE.Siemens } catch (Exception ex) { - ThrowNCException(ex); + return ManageException(ex); } + + return NO_ERROR; } - public override void FILES_WProgramFromFile(string partProgramPath, FileStream localFile) + public override CmsError FILES_WProgramFromFile(string partProgramPath, FileStream localFile) { - FileSvc FileData = new FileSvc(); - Node sourceNode = new Node(localFile.Name); - Node destNode = new Node(partProgramPath); + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; try { + // Setup variables + FileSvc FileData = new FileSvc(); + Node sourceNode = new Node(localFile.Name); + Node destNode = new Node(partProgramPath); + //Execute Function FileData.Copy(sourceNode, destNode, true); } catch (Exception ex) { - ThrowNCException(ex); + return ManageException(ex); } + + return NO_ERROR; } #endregion /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #region Subordinate Private Functions - + //Manage the Alarms - Called automatically on changes private void AlarmsChanged(Guid guid, Alarm[] alarms) { @@ -951,7 +1074,7 @@ namespace CMS_CORE.Siemens //Manage the Mode private PROC_Mode ConvertToSTEPMode(uint mode, uint JogMode, uint AdvMode) { - if(mode == 0) + if (mode == 0) { if (AdvMode == 0) return (JogMode < 6) ? PROC_Mode.JOGINC : PROC_Mode.JOG; @@ -966,8 +1089,8 @@ namespace CMS_CORE.Siemens return PROC_Mode.MDI; else if (mode == 2) return PROC_Mode.AUTO; - - return PROC_Mode.ERROR; + + return PROC_Mode.ERROR; } @@ -987,27 +1110,29 @@ namespace CMS_CORE.Siemens //Check Bit In Range - private void CheckBitRange(int bitnum) + private CmsError CheckBitRange(int bitnum) { if (bitnum < 0 || bitnum > 7) - throw new Nc_Exception("CMS-Core-Error: Bit - number must be between 0 and 7"); + return BIT_NOT_IN_RANGE_ERROR; + + return NO_ERROR; } //Check if Memory Area is corrected - private String ConvertMemToPath(MEMORY_Type MemoryType,int Address, int SubAddress, int SubBit, int Qty, char MemAccess) + private String ConvertMemToPath(MEMORY_Type MemoryType, int Address, int SubAddress, int SubBit, int Qty, char MemAccess) { - char[] allowedAccess = { 'X', 'B', 'W', 'D'}; + char[] allowedAccess = { 'X', 'B', 'W', 'D' }; //Check if is the right area and allowed type - if (!MemoryType.ToString().StartsWith(SIEMENS_MEMTYPE) || !allowedAccess.Contains(MemAccess) || Qty<1) + if (!MemoryType.ToString().StartsWith(SIEMENS_MEMTYPE) || !allowedAccess.Contains(MemAccess) || Qty < 1) throw new Nc_Exception("Incorrect Parameters error"); else { //If is Bit Access change access type - if(MemAccess == 'X') - return "DB" + Address + ".DB" + MemAccess + SubAddress + "." + SubBit; + if (MemAccess == 'X') + return "DB" + Address + ".DB" + MemAccess + SubAddress + "." + SubBit; else return "DB" + Address + ".DB" + MemAccess + SubAddress + "[" + Qty + "]"; } @@ -1016,67 +1141,75 @@ namespace CMS_CORE.Siemens //Check if NC is connected - private void CheckConnection() + private CmsError CheckConnection() { if (!NC_IsConnected()) - throw new Nc_Exception("CMS-Core-Error: Nc not Connected"); + return NOT_CONNECTED_ERROR; + + return NO_ERROR; } //Check if Siemens Environment is started - private void CheckSiemensEnv() + private CmsError CheckSiemensEnv() { if (String.IsNullOrEmpty(Environment.GetEnvironmentVariable(SinumerikEnvVar))) - throw new Nc_Exception("CMS-Core-Error: Siemens Environment not found"); + return SIEMENS_ENVIRONMENT_NOT_FOUND_ERROR; + return NO_ERROR; } //Manage the Exception Launch - private void ThrowNCException(Exception ex) + private CmsError ManageException(Exception ex) { - //Catch the Siemens exceptions - if (ex is OperateMissingOptionException && ex.Message.Contains(OptionHMINotRunning) ) + if (ex is OperateMissingOptionException && ex.Message.Contains(OptionHMINotRunning)) { Connected = false; - throw new Nc_Exception("CMS-Core-Error: Siemens HMI is not Running / Ready"); + return SIEMENS_HMI_NOT_RUNNING_ERROR; } else if (ex.Message.Contains(NcNotFound) || ex.Message.Contains(NcNotFound2) || ex.Message.Contains(NcNotFound3)) - { + { Connected = false; - throw new Nc_Exception("CMS-Core-Error: Nc not Connected"); - } + return NOT_CONNECTED_ERROR; + } else - throw new Nc_Exception("Siemens-Core-Error: " + ex.Message); + return GetError(INTERNAL_ERROR, ex.Message); } - + // Create and return CmsError object + private CmsError GetError(uint CMSError, string message) + { + return new CmsError(CMSError, message); + } //Read Static Data - private void ReadStaticNCData() + private CmsError ReadStaticNCData() { //Check if the NC is Connected - CheckConnection(); - + CmsError cmsError = CheckConnection(); + if (cmsError.errorCode != OK) + return cmsError; + //Read oly one time every X seconds if (DateTime.Now - Last_Static_Read > new TimeSpan(NC_MIN_SEC_READ_STATIC_DATA * TimeSpan.TicksPerSecond)) { - DataSvc ReadStaticData = new DataSvc(); - ReadStaticData.Timeout = TimeoutConn; - ReadStaticData.PriorityFlag = SlPriority.defaultPriority; - Item ItemNcType = new Item(PathNcType); - Item ItemNcVersion = new Item(PathNcVersion); - Item ItemMaxChannelNo = new Item(PathMaxChannelNo); - Item ItemConfChannelNo = new Item(PathConfChannelNo); - Item ItemLanguage = new Item(PathLanguage); - Item ItemSerialNumber = new Item(PathSerialNumber); - Item ItemMachineNumber = new Item(ConvertMemToPath(MATR_MACCH_SIEMENS.MemType, MATR_MACCH_SIEMENS.Address, MATR_MACCH_SIEMENS.SubAddress,0,1,'W')); - //Try to get information try { + DataSvc ReadStaticData = new DataSvc(); + ReadStaticData.Timeout = TimeoutConn; + ReadStaticData.PriorityFlag = SlPriority.defaultPriority; + Item ItemNcType = new Item(PathNcType); + Item ItemNcVersion = new Item(PathNcVersion); + Item ItemMaxChannelNo = new Item(PathMaxChannelNo); + Item ItemConfChannelNo = new Item(PathConfChannelNo); + Item ItemLanguage = new Item(PathLanguage); + Item ItemSerialNumber = new Item(PathSerialNumber); + Item ItemMachineNumber = new Item(ConvertMemToPath(MATR_MACCH_SIEMENS.MemType, MATR_MACCH_SIEMENS.Address, MATR_MACCH_SIEMENS.SubAddress, 0, 1, 'W')); + //Read All Data ReadStaticData.Read(ItemNcType); ReadStaticData.Read(ItemNcVersion); @@ -1085,27 +1218,28 @@ namespace CMS_CORE.Siemens ReadStaticData.Read(ItemLanguage); ReadStaticData.Read(ItemSerialNumber); ReadStaticData.Read(ItemMachineNumber); - + //Setup variables - Cnc_name = getName((uint)ItemNcType.Value); + Cnc_name = getName((uint)ItemNcType.Value); Cnc_SftVersion = Regex.Replace(((double)ItemNcVersion.Value).ToString(), ".{2}", "$0.").TrimEnd('.'); ; Cnc_SeriesNum = ((String)ItemSerialNumber.Value); - MaxChannelNo = (uint)ItemMaxChannelNo.Value; - ConfChannelNo = (uint)ItemConfChannelNo.Value; + MaxChannelNo = (uint)ItemMaxChannelNo.Value; + ConfChannelNo = (uint)ItemConfChannelNo.Value; SiemensLanguage = (uint)ItemLanguage.Value; - Cms_MachNumber = ((uint)ItemMachineNumber.Value).ToString(); - + Cms_MachNumber = ((uint)ItemMachineNumber.Value).ToString(); + //Save NOW Last_Static_Read = DateTime.Now; } catch (Exception ex) { - ThrowNCException(ex); + return ManageException(ex); } } + return NO_ERROR; } @@ -1116,16 +1250,16 @@ namespace CMS_CORE.Siemens String name = "Siemens "; switch (value) { - case 0: name += "840D pl"; break; - case 1000: name += "FM-NC" ; break; - case 2000: name += "810D pl" ; break; - case 3000: name += "802S" ; break; - case 4000: name += "802D pl"; break; - case 5000: name += "840Di pl"; break; - case 6000: name += "SOLUTIONLINE"; break; + case 0: name += "840D pl"; break; + case 1000: name += "FM-NC"; break; + case 2000: name += "810D pl"; break; + case 3000: name += "802S"; break; + case 4000: name += "802D pl"; break; + case 5000: name += "840Di pl"; break; + case 6000: name += "SOLUTIONLINE"; break; case 10700: name += "840D sl"; break; - case 14000: name += "802D sl T/M - N/G - C/U" ; break; - case 15000: name += "840Di sl" ; break; + case 14000: name += "802D sl T/M - N/G - C/U"; break; + case 15000: name += "840Di sl"; break; } return name; } @@ -1169,7 +1303,6 @@ namespace CMS_CORE.Siemens default: return new CultureInfo("en"); } } - #endregion }