Imports CndexLinkDotNet
Imports Microsoft.Win32
Imports CMSControl.App.Runtime
Imports CMSControl.Config.Settings

Imports T_memType = System.Collections.Generic.Dictionary(Of System.Int32, System.Collections.Generic.Dictionary(Of System.Int32, System.Object))
Imports T_memDim = System.Collections.Generic.Dictionary(Of System.Int32, System.Object)

Namespace CNC

    Public Class OSAI_OPEN
        Inherits OSAI

        'Variabili per Web Service OPENcontrol
        Protected _szIpAddress As String
        Friend OPENws As OPENcontrol.OPENcontrolPortTypeClient
        Private nReturn As Short

        Protected Const MAXRET = 3

        Public Enum O_Table
            TOOL_TABLE_ID = 1
            OFFSET_TABLE_ID = 2
            ORIGIN_TABLE_ID = 3
            USER_TABLE_ID = 4
        End Enum

        Public Overrides Property Licenza() As Integer
            Get
                Dim uiLicence(0) As UInteger
                'leggo dal cn il valore
                Me.O_RW_DWord(R, MemTypeWord.GW_CODE, 303, uiLicence)
                Return UnsignedToInteger(uiLicence(0))
            End Get
            Set(ByVal value As Integer)
                'setto sul cn il valore
                Dim uiLicence(0) As UInteger
                uiLicence(0) = IntegerToUnsigned(value)
                Me.O_RW_DWord(W, MemTypeWord.GW_CODE, 303, uiLicence)
            End Set
        End Property

        Public Overrides Property LicenzaScaduta() As Boolean
            Get
                Dim bLicenzaScaduta As Boolean
                'leggo dal cn il valore
                Me.O_RW_Boolean(R, MemTypeWord.GW_CODE, 302, 0, bLicenzaScaduta)
                Return bLicenzaScaduta
            End Get
            Set(ByVal value As Boolean)
                'setto sul cn il valore
                Me.O_RW_Boolean(W, MemTypeWord.GW_CODE, 302, 0, value)
            End Set
        End Property

        Public Sub New(ByRef szIpAddress As String)
            _Type = NcType.OSAI
            _szIpAddress = szIpAddress

            Dim conf As String = "OPENcontrol"
            Dim url As String = "http://" & szIpAddress & ":8080"

            Try
                OPENws = New OPENcontrol.OPENcontrolPortTypeClient(conf, url)
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try

            'Definisco l'area della Cnc Window
            SetCncWindowSize()

            'Inizializzo le variabili
            Me._Descrizione = "NC OSAI OPENcontrol" & vbNewLine
            Me._Descrizione = Me._Descrizione & "IpAddress: " & _szIpAddress
        End Sub

        Public Overrides Sub Connect(Optional ByRef szStatus As String = "")
            Dim BootPhaseEnquiryR As New OPENcontrol.BootPhaseEnquiryR
            Dim BootPhaseEnquiry As OPENcontrol.BootPhaseEnquiry
            Dim szReturn As String = ""
            Dim usValue(0) As UShort
            Dim TimeStart As Date

            BootPhaseEnquiry = New OPENcontrol.BootPhaseEnquiry()

            'leggo in che fase di boot mi trovo
            Try
                BootPhaseEnquiryR = OPENws.BootPhaseEnquiry(BootPhaseEnquiry)
            Catch ex As System.ServiceModel.EndpointNotFoundException
                _bConnected = False
                Throw New CmsNcException(ex.Message)
            Catch ex As System.ServiceModel.CommunicationException
                _bConnected = False
                Throw New CmsNcException(ex.Message)
            End Try

            If O_CheckRetError(BootPhaseEnquiryR.retval, BootPhaseEnquiryR.ErrClass, BootPhaseEnquiryR.ErrNum, String.Format("BootPhaseEnquiry({0}) Connect CNC.OSAI_OPEN", BootPhaseEnquiry), szReturn) Then
                _bConnected = False
                Throw New CmsNcException(szReturn)
            Else
                'verifico che il sistema si trovi in una fase operativa "stabile"
                Log.WI("OK  BootPhaseEnquiry CNC.OSAI_OPEN", "Phase=" & BootPhaseEnquiryR.Phase, CLog.Lev.Secondary)
                If BootPhaseEnquiryR.Phase = 4 Then 'SYSTEM_UP_PHASE

                    'leggo matricola e verifico che sia diversa da zero
                    TimeStart = Now
                    Do
                        Select Case Settings.MemoryMapping
                            Case MemoryMapping.ElsManager, _
                                 MemoryMapping.ToolManager
                                'Matricola
                                usValue(0) = 0 'non esiste mappatura elsmangaer e toolmanager in OPENcontrol
                                MsgBox("Non esiste implementazione con questa mappatura su OSAI OPENcontrol", MsgBoxStyle.Critical)
                                End
                            Case MemoryMapping.Default, _
                                 MemoryMapping.ToolTable
                                'Matricola
                                nReturn = O_RW_Word(R, MemTypeWord.MW_CODE, 3403, usValue)
                        End Select

                        If usValue(0) > 0 Then
                            Threading.Thread.Sleep(500)
                            Exit Do
                        End If

                        If (Now - TimeStart).Seconds > 30 Then
                            Select Case MsgBox("Matricola non inizializzata in 30 secondi: Verificare inizializzazione PLC", MsgBoxStyle.Exclamation + MsgBoxStyle.RetryCancel)
                                Case MsgBoxResult.Retry : TimeStart = Now
                                Case MsgBoxResult.Cancel : Exit Do
                            End Select
                        End If
                        Log.WI("OK  Connect CNC.OSAI_OPEN but SERIAL NUMBER NOT YET INITIALIZED", , CLog.Lev.Secondary)
                        Application.DoEvents()
                        Threading.Thread.Sleep(500) 'aspetto 500ms prima di ritentare
                        Application.DoEvents()
                    Loop

                    _bConnected = True
                    Log.WI("OK  Connect CNC.OSAI_OPEN", "Connected=" & _bConnected, CLog.Lev.Secondary)
                Else
                    _bConnected = False
                    Log.WI("OK  Connect CNC.OSAI_OPEN but PHASE NOT OK", "Phase=" & BootPhaseEnquiryR.Phase & " Connected=" & _bConnected, CLog.Lev.Secondary)
                    Throw New CmsNcException("ERR BootPhase NOT OK CNC.OSAI_OPEN")
                End If
            End If

        End Sub

        Public Overrides Sub Disconnect(Optional ByRef szStatus As String = "")
            _bConnected = False
        End Sub



        ''' <summary>
        ''' Legge le memorie di configurazione dal cn
        ''' </summary>
        Public Overrides Sub GetStaticData()
            Dim nValue(0) As Integer
            Dim sValue(0) As Short
            Dim ucValue(0) As Byte

            If Not bStaticDataReaded Then
                'Try
                Select Case Settings.MemoryMapping
                    Case MemoryMapping.ElsManager

                    Case MemoryMapping.Default, _
                         MemoryMapping.ToolManager, _
                         MemoryMapping.ToolTable

                        'Matricola
                        nReturn = O_RW_Short(R, MemTypeWord.MW_CODE, 3403, sValue)
                        Me._Matricola = sValue(0)
                        'Teste
                        nReturn = O_RW_Short(R, MemTypeWord.MW_CODE, 3405, sValue)
                        Me._Teste = sValue(0)
                        'Magazzini
                        nReturn = O_RW_Short(R, MemTypeWord.MW_CODE, 3407, sValue)
                        Me._Magazzini = sValue(0)
                        'Manine per Magazzino
                        ReDim Me._ManineMagazzino(Me._Magazzini - 1)
                        ReDim ucValue(19)
                        nReturn = O_RW_Byte(R, MemTypeWord.MW_CODE, 2900, LOW_ORDER, ucValue)
                        Array.Copy(ucValue, Me._ManineMagazzino, Me._ManineMagazzino.Length)
                        ReDim ucValue(0)

                        'Magazzini Con Attrezzaggio Automatico (maschera)
                        O_RW_Integer(R, MemTypeWord.MW_CODE, 4060, nValue)
                        Me._MagazziniConAttrezzaggioAutomatico = nValue(0)
                End Select

                Me._MaxUtensiliGestibili = 300 'TODO IMPLEMENTARE
                Me._MaxIdUtensile = 300 'TODO IMPLEMENTARE

                Select Case Settings.MemoryMapping
                    Case MemoryMapping.ElsManager
                    Case MemoryMapping.ToolManager
                    Case MemoryMapping.Default, _
                        MemoryMapping.ToolTable
                        'ZoomSpeed
                        nReturn = O_RW_Short(R, MemTypeWord.MW_CODE, 3425, sValue)
                        If sValue(0) > 0 And sValue(0) <= 100 Then
                            Me._ZoomSpeed = sValue(0)
                        Else
                            Me._ZoomSpeed = 1
                        End If
                End Select

                bStaticDataReaded = True

                'Catch ex As CmsNcException
                '    Me.CncException(ex.Message)
                'End Try

            End If
        End Sub


        ''' <summary>
        ''' Legge o scrive Boolean da MEMORIE PLC
        ''' </summary>
        ''' <param name="bWrite">Se True SCRIVE, se False LEGGE</param>
        ''' <param name="MemType">Tipo di memoria Osai</param>
        ''' <param name="MemIndex">Indice di memoria</param>
        ''' <param name="MemBit">Bit della memoria</param>
        ''' <param name="Value">Valore da scrivere su scrittura e letto su lettura</param>
        ''' <returns>True se andata a buon fine</returns>
        Public Overloads Overrides Function O_RW_Boolean(ByVal bWrite As Boolean, ByVal MemType As MemTypeWord, ByVal MemIndex As Integer, ByVal MemBit As Integer, ByRef Value As Boolean) As Boolean
            Dim szReturn As String = ""
            Dim nRetry As Integer
Retry:      nRetry += 1

            Try
                If bWrite Then ' *** Write
                    Dim myWriteVarWordBitR As OPENcontrol.WriteVarWordBitR
                    Dim myWriteVarWordBit As New OPENcontrol.WriteVarWordBit
                    myWriteVarWordBit.Code = MemType
                    myWriteVarWordBit.Index = MemIndex
                    myWriteVarWordBit.BitIndex = MemBit
                    myWriteVarWordBit.BitValue = IIf(Value, 1, 0)
                    myWriteVarWordBitR = OPENws.WriteVarWordBit(myWriteVarWordBit)
                    If O_CheckRetError(myWriteVarWordBitR.retval, myWriteVarWordBitR.ErrClass, myWriteVarWordBitR.ErrNum, String.Format("WriteVarWordBit({0},{1}) O_RW_Boolean CNC.OSAI_OPEN", [Enum].GetName(MemType.GetType, MemType), MemIndex), szReturn) Then
                        Throw New CmsNcException(szReturn)
                        Return False
                    End If

                Else ' ************* Read
                    Dim myReadVarWordR As OPENcontrol.ReadVarWordR
                    Dim myReadVarWord As New OPENcontrol.ReadVarWord
                    myReadVarWord.Code = MemType
                    myReadVarWord.Index = MemIndex
                    myReadVarWord.NumVar = 1
                    myReadVarWordR = OPENws.ReadVarWord(myReadVarWord)
                    If O_CheckRetError(myReadVarWordR.retval, myReadVarWordR.ErrClass, myReadVarWordR.ErrNum, String.Format("ReadVarWord({0},{1}) O_RW_Boolean CNC.OSAI_OPEN", [Enum].GetName(MemType.GetType, MemType), MemIndex), szReturn) Then
                        Throw New CmsNcException(szReturn)
                        Return False
                    End If
                    If (myReadVarWordR.Value(0) And (2 ^ MemBit)) = (2 ^ MemBit) Then 'True
                        Value = True
                    Else 'False
                        Value = False
                    End If
                End If

                Return True
            Catch ex As System.ServiceModel.CommunicationException
                If nRetry < MAXRET Then GoTo Retry
                Throw New CmsNcException(ex.Message)
                Return False
            Catch ex As System.TimeoutException
                Throw New CmsNcException(ex.Message)
                Return False
            End Try
        End Function

        ''' <summary>
        ''' Legge o scrive Byte da MEMORIE PLC
        ''' </summary>
        ''' <param name="bWrite">Se True SCRIVE, se False LEGGE</param>
        ''' <param name="MemType">Tipo di memoria Osai</param>
        ''' <param name="MemIndex">Indice di memoria</param>
        ''' <param name="MemOrderStart">Ordine di partenza LOW_ORDER = 0 HIGH_ORDER = 1</param>
        ''' <param name="Value">Matrice di valori da scrivere su scrittura o letti su lettura</param>
        ''' <returns>True se andata a buon fine</returns>
        Public Overloads Overrides Function O_RW_Byte(ByVal bWrite As Boolean, ByVal MemType As MemTypeWord, ByVal MemIndex As Integer, ByVal MemOrderStart As Integer, ByRef Value() As Byte) As Boolean
            Dim szReturn As String = ""
            Dim bStartHigh As Boolean = MemOrderStart
            Dim bEndDispari As Boolean = (Value.Length + MemOrderStart) Mod 2
            Dim cStart, cEnd As Byte
            Dim ValueTmp(((Value.Length + MemOrderStart) \ 2) + ((Value.Length + MemOrderStart) Mod 2) - 1) As UShort
            Dim nRetry As Integer
Retry:      nRetry += 1

            Try
                If bWrite Then ' *** Write
                    'se comincio con hi leggo la prima memo
                    If bStartHigh Then
                        Dim ValStartTmp(0) As UShort
                        O_RW_Word(R, MemType, MemIndex, ValStartTmp)
                        cStart = WordToByte(ValStartTmp(0), LOW_ORDER)
                    End If

                    'se finisco dispari, leggo l'ultima memo
                    If bEndDispari Then
                        Dim ValEndTmp(0) As UShort
                        O_RW_Word(R, MemType, MemIndex + ValueTmp.Length - 1, ValEndTmp)
                        cEnd = WordToByte(ValEndTmp(0), HIGH_ORDER)
                    End If

                    For i = 0 To ValueTmp.Length - 1
                        Dim cLow, cHigh As Byte
                        'Low
                        If i = 0 AndAlso bStartHigh Then
                            cLow = cStart
                        Else
                            cLow = Value(i * 2 - MemOrderStart)
                        End If
                        'High
                        If i = (ValueTmp.Length - 1) AndAlso bEndDispari Then
                            cHigh = cEnd
                        Else
                            cHigh = Value(i * 2 + 1 - MemOrderStart)
                        End If

                        ValueTmp(i) = ByteToWord(cLow, cHigh)
                    Next

                    O_RW_Word(W, MemType, MemIndex, ValueTmp)

                Else ' ************* Read
                    Dim myReadVarWordR As OPENcontrol.ReadVarWordR
                    Dim myReadVarWord As New OPENcontrol.ReadVarWord
                    myReadVarWord.Code = MemType
                    myReadVarWord.Index = MemIndex
                    myReadVarWord.NumVar = ValueTmp.Length
                    myReadVarWordR = OPENws.ReadVarWord(myReadVarWord)
                    If O_CheckRetError(myReadVarWordR.retval, myReadVarWordR.ErrClass, myReadVarWordR.ErrNum, String.Format("ReadVarWord({0},{1}) O_RW_Byte CNC.OSAI_OPEN", [Enum].GetName(MemType.GetType, MemType), MemIndex), szReturn) Then
                        Throw New CmsNcException(szReturn)
                        Return False
                    End If
                    For i = 0 To Value.Length - 1
                        Value(i) = WordToByte(myReadVarWordR.Value((i + MemOrderStart) \ 2), (i + MemOrderStart) Mod 2)
                    Next
                End If

                Return True
            Catch ex As System.ServiceModel.CommunicationException
                If nRetry < MAXRET Then GoTo Retry
                Throw New CmsNcException(ex.Message)
                Return False
            Catch ex As System.TimeoutException
                Throw New CmsNcException(ex.Message)
                Return False
            End Try
        End Function

        ''' <summary>
        ''' Legge o scrive Word da MEMORIE PLC
        ''' </summary>
        ''' <param name="bWrite">Se True SCRIVE, se False LEGGE</param>
        ''' <param name="MemType">Tipo di memoria Osai</param>
        ''' <param name="MemIndex">Indice di memoria</param>
        ''' <param name="Value">Matrice di valori da scrivere su scrittura o letti su lettura</param>
        ''' <returns>True se andata a buon fine</returns>
        Public Overloads Overrides Function O_RW_Word(ByVal bWrite As Boolean, ByVal MemType As MemTypeWord, ByVal MemIndex As Integer, ByRef Value() As UShort) As Boolean
            Dim szReturn As String = ""
            Dim nRetry As Integer
Retry:      nRetry += 1

            Try
                If bWrite Then ' *** Write
                    Dim myWriteVarWordR As OPENcontrol.WriteVarWordR
                    Dim myWriteVarWord As New OPENcontrol.WriteVarWord
                    myWriteVarWord.Code = MemType
                    myWriteVarWord.Index = MemIndex
                    myWriteVarWord.NumVar = Value.Length
                    ReDim myWriteVarWord.Value(Value.Length - 1)
                    Array.Copy(Value, myWriteVarWord.Value, Value.Length)
                    myWriteVarWordR = OPENws.WriteVarWord(myWriteVarWord)
                    If O_CheckRetError(myWriteVarWordR.retval, myWriteVarWordR.ErrClass, myWriteVarWordR.ErrNum, String.Format("WriteVarWord({0},{1}) O_RW_Word CNC.OSAI_OPEN", [Enum].GetName(MemType.GetType, MemType), MemIndex), szReturn) Then
                        Throw New CmsNcException(szReturn)
                        Return False
                    End If

                Else ' ************* Read
                    Dim myReadVarWordR As OPENcontrol.ReadVarWordR
                    Dim myReadVarWord As New OPENcontrol.ReadVarWord
                    myReadVarWord.Code = MemType
                    myReadVarWord.Index = MemIndex
                    myReadVarWord.NumVar = Value.Length
                    myReadVarWordR = OPENws.ReadVarWord(myReadVarWord)
                    If O_CheckRetError(myReadVarWordR.retval, myReadVarWordR.ErrClass, myReadVarWordR.ErrNum, String.Format("ReadVarWord({0},{1}) O_RW_Word CNC.OSAI_OPEN", [Enum].GetName(MemType.GetType, MemType), MemIndex), szReturn) Then
                        Throw New CmsNcException(szReturn)
                        Return False
                    End If
                    Array.Copy(myReadVarWordR.Value, Value, Value.Length)
                End If

                Return True

            Catch ex As System.ServiceModel.CommunicationException
                If nRetry < MAXRET Then GoTo Retry
                Throw New CmsNcException(ex.Message)
                Return False
            Catch ex As System.TimeoutException
                Throw New CmsNcException(ex.Message)
                Return False
            End Try
        End Function


        ''' <summary>
        ''' Legge o scrive Short da MEMORIE PLC
        ''' </summary>
        ''' <param name="bWrite">Se True SCRIVE, se False LEGGE</param>
        ''' <param name="MemType">Tipo di memoria Osai</param>
        ''' <param name="MemIndex">Indice di memoria</param>
        ''' <param name="Value">Matrice di valori da scrivere su scrittura o letti su lettura</param>
        ''' <returns>True se andata a buon fine</returns>
        Public Overloads Overrides Function O_RW_Short(ByVal bWrite As Boolean, ByVal MemType As MemTypeWord, ByVal MemIndex As Integer, ByRef Value() As Short) As Boolean
            Dim szReturn As String = ""
            Dim nRetry As Integer
Retry:      nRetry += 1

            Try
                If bWrite Then ' *** Write
                    Dim myWriteVarWordR As OPENcontrol.WriteVarWordR
                    Dim myWriteVarWord As New OPENcontrol.WriteVarWord
                    myWriteVarWord.Code = MemType
                    myWriteVarWord.Index = MemIndex
                    myWriteVarWord.NumVar = Value.Length
                    ReDim myWriteVarWord.Value(Value.Length - 1)
                    For i = 0 To Value.Length - 1
                        myWriteVarWord.Value(i) = ShortToUnsigned(Value(i))
                    Next
                    myWriteVarWordR = OPENws.WriteVarWord(myWriteVarWord)
                    If O_CheckRetError(myWriteVarWordR.retval, myWriteVarWordR.ErrClass, myWriteVarWordR.ErrNum, String.Format("WriteVarWord({0},{1}) O_RW_Short CNC.OSAI_OPEN", [Enum].GetName(MemType.GetType, MemType), MemIndex), szReturn) Then
                        Throw New CmsNcException(szReturn)
                        Return False
                    End If

                Else ' ************* Read
                    Dim myReadVarWordR As OPENcontrol.ReadVarWordR
                    Dim myReadVarWord As New OPENcontrol.ReadVarWord
                    myReadVarWord.Code = MemType
                    myReadVarWord.Index = MemIndex
                    myReadVarWord.NumVar = Value.Length
                    myReadVarWordR = OPENws.ReadVarWord(myReadVarWord)
                    If O_CheckRetError(myReadVarWordR.retval, myReadVarWordR.ErrClass, myReadVarWordR.ErrNum, String.Format("ReadVarWord({0},{1}) O_RW_Short CNC.OSAI_OPEN", [Enum].GetName(MemType.GetType, MemType), MemIndex), szReturn) Then
                        Throw New CmsNcException(szReturn)
                        Return False
                    End If
                    For i = 0 To Value.Length - 1
                        Value(i) = UnsignedToShort(myReadVarWordR.Value(i))
                    Next
                End If
                Return True
            Catch ex As System.ServiceModel.CommunicationException
                If nRetry < MAXRET Then GoTo Retry
                Throw New CmsNcException(ex.Message)
                Return False
            Catch ex As System.TimeoutException
                Throw New CmsNcException(ex.Message)
                Return False
            End Try
        End Function


        ''' <summary>
        ''' Legge o scrive Integer da MEMORIE PLC
        ''' </summary>
        ''' <param name="bWrite">Se True SCRIVE, se False LEGGE</param>
        ''' <param name="MemType">Tipo di memoria Osai</param>
        ''' <param name="MemIndex">Indice di memoria</param>
        ''' <param name="Value">Matrice di valori da scrivere su scrittura o letti su lettura</param>
        ''' <returns>True se andata a buon fine</returns>
        Public Overloads Overrides Function O_RW_DWord(ByVal bWrite As Boolean, ByVal MemType As MemTypeWord, ByVal MemIndex As Integer, ByRef Value() As UInteger) As Boolean
            Dim szReturn As String = ""
            Dim ValueTmp(Value.Length * 2 - 1) As UShort
            Dim nRetry As Integer
Retry:      nRetry += 1

            Try
                If bWrite Then ' *** Write
                    Dim myWriteVarWordR As OPENcontrol.WriteVarWordR
                    Dim myWriteVarWord As New OPENcontrol.WriteVarWord
                    myWriteVarWord.Code = MemType
                    myWriteVarWord.Index = MemIndex
                    myWriteVarWord.NumVar = ValueTmp.Length
                    For i = 0 To Value.Length - 1
                        ValueTmp(i * 2) = DWordToWord(Value(i), LOW_ORDER)
                        ValueTmp(i * 2 + 1) = DWordToWord(Value(i), HIGH_ORDER)
                    Next
                    ReDim myWriteVarWord.Value(ValueTmp.Length - 1)
                    Array.Copy(ValueTmp, myWriteVarWord.Value, ValueTmp.Length)
                    myWriteVarWordR = OPENws.WriteVarWord(myWriteVarWord)
                    If O_CheckRetError(myWriteVarWordR.retval, myWriteVarWordR.ErrClass, myWriteVarWordR.ErrNum, String.Format("WriteVarWord({0},{1}) O_RW_DWord CNC.OSAI_OPEN", [Enum].GetName(MemType.GetType, MemType), MemIndex), szReturn) Then
                        Throw New CmsNcException(szReturn)
                        Return False
                    End If

                Else ' ************* Read
                    Dim myReadVarWordR As OPENcontrol.ReadVarWordR
                    Dim myReadVarWord As New OPENcontrol.ReadVarWord
                    myReadVarWord.Code = MemType
                    myReadVarWord.Index = MemIndex
                    myReadVarWord.NumVar = ValueTmp.Length
                    myReadVarWordR = OPENws.ReadVarWord(myReadVarWord)
                    If O_CheckRetError(myReadVarWordR.retval, myReadVarWordR.ErrClass, myReadVarWordR.ErrNum, String.Format("ReadVarWord({0},{1}) O_RW_DWord CNC.OSAI_OPEN", [Enum].GetName(MemType.GetType, MemType), MemIndex), szReturn) Then
                        Throw New CmsNcException(szReturn)
                        Return False
                    Else
                        For i = 0 To Value.Length - 1
                            Value(i) = WordsToDWord(myReadVarWordR.Value(i * 2), myReadVarWordR.Value(i * 2 + 1))
                        Next
                    End If
                End If

                Return True
            Catch ex As System.ServiceModel.CommunicationException
                If nRetry < MAXRET Then GoTo Retry
                Throw New CmsNcException(ex.Message)
                Return False
            Catch ex As System.TimeoutException
                Throw New CmsNcException(ex.Message)
                Return False
            End Try
        End Function


        ''' <summary>
        ''' Legge o scrive Integer da MEMORIE PLC
        ''' </summary>
        ''' <param name="bWrite">Se True SCRIVE, se False LEGGE</param>
        ''' <param name="MemType">Tipo di memoria Osai</param>
        ''' <param name="MemIndex">Indice di memoria</param>
        ''' <param name="Value">Matrice di valori da scrivere su scrittura o letti su lettura</param>
        ''' <returns>True se andata a buon fine</returns>
        Public Overloads Overrides Function O_RW_Integer(ByVal bWrite As Boolean, ByVal MemType As MemTypeWord, ByVal MemIndex As Integer, ByRef Value() As Integer) As Boolean
            Dim szReturn As String = ""
            Dim ValueTmp(Value.Length * 2 - 1) As UShort
            Dim nRetry As Integer
Retry:      nRetry += 1

            Try
                If bWrite Then ' *** Write
                    Dim myWriteVarWordR As OPENcontrol.WriteVarWordR
                    Dim myWriteVarWord As New OPENcontrol.WriteVarWord
                    myWriteVarWord.Code = MemType
                    myWriteVarWord.Index = MemIndex
                    myWriteVarWord.NumVar = ValueTmp.Length
                    For i = 0 To Value.Length - 1
                        ValueTmp(i * 2) = IntegerToWord(Value(i), LOW_ORDER)
                        ValueTmp(i * 2 + 1) = IntegerToWord(Value(i), HIGH_ORDER)
                    Next
                    ReDim myWriteVarWord.Value(ValueTmp.Length - 1)
                    Array.Copy(ValueTmp, myWriteVarWord.Value, ValueTmp.Length)
                    myWriteVarWordR = OPENws.WriteVarWord(myWriteVarWord)
                    If O_CheckRetError(myWriteVarWordR.retval, myWriteVarWordR.ErrClass, myWriteVarWordR.ErrNum, String.Format("WriteVarDWord({0},{1}) O_RW_DWord CNC.OSAI_OPEN", [Enum].GetName(MemType.GetType, MemType), MemIndex), szReturn) Then
                        Throw New CmsNcException(szReturn)
                        Return False
                    End If

                Else ' ************* Read
                    Dim myReadVarWordR As OPENcontrol.ReadVarWordR
                    Dim myReadVarWord As New OPENcontrol.ReadVarWord
                    myReadVarWord.Code = MemType
                    myReadVarWord.Index = MemIndex
                    myReadVarWord.NumVar = ValueTmp.Length
                    myReadVarWordR = OPENws.ReadVarWord(myReadVarWord)
                    If O_CheckRetError(myReadVarWordR.retval, myReadVarWordR.ErrClass, myReadVarWordR.ErrNum, String.Format("ReadVarDWord({0},{1}) O_RW_DWord CNC.OSAI_OPEN", [Enum].GetName(MemType.GetType, MemType), MemIndex), szReturn) Then
                        Throw New CmsNcException(szReturn)
                        Return False
                    Else
                        For i = 0 To Value.Length - 1
                            Value(i) = WordsToInteger(myReadVarWordR.Value(i * 2), myReadVarWordR.Value(i * 2 + 1))
                        Next
                    End If
                End If

                Return True
            Catch ex As System.ServiceModel.CommunicationException
                If nRetry < MAXRET Then GoTo Retry
                Throw New CmsNcException(ex.Message)
                Return False
            Catch ex As System.TimeoutException
                Throw New CmsNcException(ex.Message)
                Return False
            End Try
        End Function

        ''' <summary>
        ''' Legge o scrive Double da MEMORIE PLC
        ''' </summary>
        ''' <param name="bWrite">Se True SCRIVE, se False LEGGE</param>
        ''' <param name="MemType">Tipo di memoria Osai</param>
        ''' <param name="MemIndex">Indice di memoria</param>
        ''' <param name="Value">Matrice di valori da scrivere su scrittura o letti su lettura</param>
        ''' <returns>True se andata a buon fine</returns>
        Public Overloads Overrides Function O_RW_Double(ByVal bWrite As Boolean, ByVal MemType As MemTypeDouble, ByVal MemIndex As Integer, ByRef Value() As Double) As Boolean
            Dim szReturn As String = ""
            Dim nRetry As Integer
Retry:      nRetry += 1

            Try
                If bWrite Then ' *** Write
                    Dim myWriteVarDoubleR As OPENcontrol.WriteVarDoubleR
                    Dim myWriteVarDouble As New OPENcontrol.WriteVarDouble
                    myWriteVarDouble.Code = MemType
                    myWriteVarDouble.Index = MemIndex
                    myWriteVarDouble.NumVar = Value.Length
                    ReDim myWriteVarDouble.Value(Value.Length - 1)
                    Array.Copy(Value, myWriteVarDouble.Value, Value.Length)
                    myWriteVarDoubleR = OPENws.WriteVarDouble(myWriteVarDouble)
                    If O_CheckRetError(myWriteVarDoubleR.retval, myWriteVarDoubleR.ErrClass, myWriteVarDoubleR.ErrNum, String.Format("WriteVarDouble({0},{1}) O_RW_Double CNC.OSAI_OPEN", [Enum].GetName(MemType.GetType, MemType), MemIndex), szReturn) Then
                        Throw New CmsNcException(szReturn)
                        Return False
                    End If

                Else ' ************* Read
                    Dim myReadVarDoubleR As OPENcontrol.ReadVarDoubleR
                    Dim myReadVarDouble As New OPENcontrol.ReadVarDouble
                    myReadVarDouble.Code = MemType
                    myReadVarDouble.Index = MemIndex
                    myReadVarDouble.NumVar = Value.Length
                    myReadVarDoubleR = OPENws.ReadVarDouble(myReadVarDouble)
                    If O_CheckRetError(myReadVarDoubleR.retval, myReadVarDoubleR.ErrClass, myReadVarDoubleR.ErrNum, String.Format("ReadVarDouble({0},{1}) O_RW_Double CNC.OSAI_OPEN", [Enum].GetName(MemType.GetType, MemType), MemIndex), szReturn) Then
                        Throw New CmsNcException(szReturn)
                        Return False
                    End If
                    Array.Copy(myReadVarDoubleR.Value, Value, Value.Length)
                End If

                Return True
            Catch ex As System.ServiceModel.CommunicationException
                If nRetry < MAXRET Then GoTo Retry
                Throw New CmsNcException(ex.Message)
                Return False
            Catch ex As System.TimeoutException
                Throw New CmsNcException(ex.Message)
                Return False
            End Try
        End Function

        ''' <summary>
        ''' Legge o scrive Stringhe da MEMORIE SC
        ''' </summary>
        ''' <param name="bWrite">Se True SCRIVE, se False LEGGE</param>
        ''' <param name="MemIndex">Indice di memoria</param>
        ''' <param name="MemLength">Lunghezza caratteri</param>
        ''' <param name="Value">Stringa da scrivere su scrittura o leggere su lettura</param>
        ''' <returns>True se andata a buon fine</returns>
        Public Overloads Overrides Function O_RW_Text(ByVal bWrite As Boolean, ByVal MemType As MemTypeText, ByVal MemIndex As Integer, ByVal MemLength As Integer, ByRef Value As String) As Boolean
            Dim szReturn As String = ""
            Dim nRetry As Integer
Retry:      nRetry += 1

            Try
                If bWrite Then ' *** Write
                    Dim myWriteVarTextR As OPENcontrol.WriteVarTextR
                    Dim myWriteVarText As New OPENcontrol.WriteVarText
                    myWriteVarText.Code = MemType
                    myWriteVarText.Index = MemIndex
                    myWriteVarText.Len = MemLength
                    myWriteVarText.Text = Value
                    myWriteVarText.Process = 1 'serve per le variabili SC
                    myWriteVarTextR = OPENws.WriteVarText(myWriteVarText)
                    If O_CheckRetError(myWriteVarTextR.retval, myWriteVarTextR.ErrClass, myWriteVarTextR.ErrNum, String.Format("WriteVarText({0},{1}) O_RW_Text CNC.OSAI_OPEN", [Enum].GetName(MemType.GetType, MemType), MemIndex), szReturn) Then
                        Throw New CmsNcException(szReturn)
                        Return False
                    End If

                Else ' ************* Read
                    Dim myReadVarTextR As OPENcontrol.ReadVarTextR
                    Dim myReadVarText As New OPENcontrol.ReadVarText
                    myReadVarText.Code = MemType
                    myReadVarText.Index = MemIndex
                    myReadVarText.Size = MemLength
                    myReadVarText.Process = 1 'serve per le variabili SC
                    myReadVarTextR = OPENws.ReadVarText(myReadVarText)
                    If O_CheckRetError(myReadVarTextR.retval, myReadVarTextR.ErrClass, myReadVarTextR.ErrNum, String.Format("ReadVarText({0},{1}) O_RW_Text CNC.OSAI_OPEN", [Enum].GetName(MemType.GetType, MemType), MemIndex), szReturn) Then
                        Throw New CmsNcException(szReturn)
                        Return False
                    End If
                    Value = myReadVarTextR.Text
                End If
            Catch ex As System.ServiceModel.CommunicationException
                If nRetry < MAXRET Then GoTo Retry
                Throw New CmsNcException(ex.Message)
                Return False
            Catch ex As System.TimeoutException
                Throw New CmsNcException(ex.Message)
                Return False
            End Try
        End Function



        ''' <summary>
        ''' Legge o scrive Length and Radius Offset da tabella Utensili CN
        ''' </summary>
        ''' <param name="bWrite">Se True SCRIVE, se False LEGGE</param>
        ''' <param name="ToolOffsetNumber">Numero dell'offset utensile</param>
        Public Overrides Function O_RW_ToolOffset(ByVal bWrite As Boolean, ByVal ToolOffsetNumber As Integer, ByRef CutterRadius_Wear As Double, ByRef CutterRadius_Geometry As Double, ByRef ToolLenght_Wear As Double, ByRef ToolLenght_Geometry As Double) As Boolean
            Dim szReturn As String = ""
            Dim nRetry As Integer
Retry:      nRetry += 1

            Try
                If bWrite Then ' *** Write
                    'leggo il correttore per usarlo come template
                    Dim myGetOffsetTabRecordIIR As OPENcontrol.GetOffsetTabRecordIIR
                    Dim myGetOffsetTabRecordII As New OPENcontrol.GetOffsetTabRecordII
                    myGetOffsetTabRecordII.RecordNum = ToolOffsetNumber
                    myGetOffsetTabRecordIIR = OPENws.GetOffsetTabRecordII(myGetOffsetTabRecordII)
                    If O_CheckRetError(myGetOffsetTabRecordIIR.retval, myGetOffsetTabRecordIIR.ErrClass, myGetOffsetTabRecordIIR.ErrNum, String.Format("GetOffsetTabRecordII({0}) O_RW_ToolOffset CNC.OSAI_OPEN", ToolOffsetNumber), szReturn) Then
                        Throw New CmsNcException(szReturn)
                        Return False
                    End If

                    Dim mySetOffsetTabRecordIIR As OPENcontrol.SetOffsetTabRecordIIR
                    Dim mySetOffsetTabRecordII As New OPENcontrol.SetOffsetTabRecordII
                    mySetOffsetTabRecordII.RecordNum = ToolOffsetNumber
                    mySetOffsetTabRecordII.RecordBuff = myGetOffsetTabRecordIIR.RecordBuff
                    'modifico i valori che mi interesssano
                    mySetOffsetTabRecordII.RecordBuff.DiaVal(0).ActChangeVal = CutterRadius_Wear
                    mySetOffsetTabRecordII.RecordBuff.DiaVal(0).ValOrig = CutterRadius_Geometry
                    mySetOffsetTabRecordII.RecordBuff.LenVal(0).ActChangeVal = ToolLenght_Wear
                    mySetOffsetTabRecordII.RecordBuff.LenVal(0).ValOrig = ToolLenght_Geometry

                    'scrivo il correttore
                    mySetOffsetTabRecordIIR = OPENws.SetOffsetTabRecordII(mySetOffsetTabRecordII)
                    If O_CheckRetError(mySetOffsetTabRecordIIR.retval, mySetOffsetTabRecordIIR.ErrClass, mySetOffsetTabRecordIIR.ErrNum, String.Format("SetOffsetTabRecordII({0}) O_RW_ToolOffset CNC.OSAI_OPEN", ToolOffsetNumber), szReturn) Then
                        Throw New CmsNcException(szReturn)
                        Return False
                    End If

                Else ' ************* Read
                    Dim myGetOffsetTabRecordIIR As OPENcontrol.GetOffsetTabRecordIIR
                    Dim myGetOffsetTabRecordII As New OPENcontrol.GetOffsetTabRecordII
                    myGetOffsetTabRecordII.RecordNum = ToolOffsetNumber
                    myGetOffsetTabRecordIIR = OPENws.GetOffsetTabRecordII(myGetOffsetTabRecordII)
                    If O_CheckRetError(myGetOffsetTabRecordIIR.retval, myGetOffsetTabRecordIIR.ErrClass, myGetOffsetTabRecordIIR.ErrNum, String.Format("GetOffsetTabRecordII({0}) O_RW_ToolOffset CNC.OSAI_OPEN", ToolOffsetNumber), szReturn) Then
                        Throw New CmsNcException(szReturn)
                        Return False
                    End If

                    CutterRadius_Wear = myGetOffsetTabRecordIIR.RecordBuff.DiaVal(0).ActChangeVal
                    CutterRadius_Geometry = myGetOffsetTabRecordIIR.RecordBuff.DiaVal(0).ValOrig
                    ToolLenght_Wear = myGetOffsetTabRecordIIR.RecordBuff.LenVal(0).ActChangeVal
                    ToolLenght_Geometry = myGetOffsetTabRecordIIR.RecordBuff.LenVal(0).ValOrig
                End If
            Catch ex As System.ServiceModel.CommunicationException
                If nRetry < MAXRET Then GoTo Retry
                Throw New CmsNcException(ex.Message)
                Return False
            End Try



            'Dim iodbpsd_1 As Focas1.IODBPSD_1
            'Dim odbtofs As Focas1.ODBTOFS
            'Dim nReturn As Integer
            'Dim bNcInInch As Boolean
            'Dim bTtInInch As Boolean
            'Dim valid_fig As Short
            'Dim dec_fig_in(31) As Short
            'Dim dec_fig_out(31) As Short

            'iodbpsd_1 = New Focas1.IODBPSD_1
            'odbtofs = New Focas1.ODBTOFS

            ''Leggo se il CN è impostato in Inch (parametro 0.2)
            'nReturn = Focas1.cnc_rdparam(nLibHandle(1), 0, 0, 4 + 1, iodbpsd_1)
            'If F_CheckRetError_Cnc(nReturn, "cnc_rdparam F_RW_LengthOffset CNC.FANUC") Then
            '    Throw New CmsNcException("ERR cnc_rdparam F_RW_LengthOffset CNC.FANUC")
            'End If
            'bNcInInch = (iodbpsd_1.cdata And MASK_BIT2) = MASK_BIT2

            ''Leggo se ToolTable è impostato in Inch
            'bTtInInch = Config.Options.CurrentOptions.ToolTable_Inch

            ''leggo le cifre decimali
            'nReturn = Focas1.cnc_getfigure(nLibHandle(1), 1, valid_fig, dec_fig_in, dec_fig_out)
            'If F_CheckRetError_Cnc(nReturn, "cnc_getfigure F_RW_LengthOffset CNC.FANUC") Then
            '    Throw New CmsNcException("ERR cnc_getfigure F_RW_LengthOffset CNC.FANUC")
            'End If

            'If bWrite Then ' *** Write
            '    For i = 0 To 3
            '        Dim dblTmp As Double
            '        Dim nTmp As Integer
            '        Select Case i
            '            Case 0 : dblTmp = CutterRadius_Wear
            '            Case 1 : dblTmp = CutterRadius_Geometry
            '            Case 2 : dblTmp = ToolLenght_Wear
            '            Case 3 : dblTmp = ToolLenght_Geometry
            '        End Select
            '        'moltiplico per le cifre decimali
            '        dblTmp *= 10 ^ dec_fig_in(0)
            '        'riporto all'unità di misura di Nc
            '        If bNcInInch And Not bTtInInch Then
            '            nTmp = dblTmp / 25.4
            '        ElseIf Not bNcInInch And bTtInInch Then
            '            nTmp = dblTmp * 25.4
            '        Else
            '            nTmp = dblTmp
            '        End If
            '        nReturn = Focas1.cnc_wrtofs(nLibHandle(1), ToolOffsetNumber, i, 8, nTmp)
            '        If F_CheckRetError_Pmc(nReturn, "cnc_wrtofs F_RW_ToolOffset CNC.FANUC") Then
            '            Throw New CmsNcException("ERR cnc_wrtofs F_RW_ToolOffset CNC.FANUC")
            '        End If
            '    Next

            'Else ' ************* Read
            '    For i = 0 To 3
            '        nReturn = Focas1.cnc_rdtofs(nLibHandle(1), ToolOffsetNumber, i, 8, odbtofs)
            '        If F_CheckRetError_Pmc(nReturn, "cnc_rdtofs F_RW_ToolOffset CNC.FANUC") OrElse (odbtofs.datano <> ToolOffsetNumber Or odbtofs.type <> i) Then
            '            Throw New CmsNcException("ERR cnc_rdtofs F_RW_ToolOffset CNC.FANUC")
            '        Else
            '            Dim dblTmp As Double
            '            'riporto all'unità di misura di ToolTable
            '            If bNcInInch And Not bTtInInch Then
            '                dblTmp = odbtofs.data * 25.4
            '            ElseIf Not bNcInInch And bTtInInch Then
            '                dblTmp = odbtofs.data / 25.4
            '            Else
            '                dblTmp = odbtofs.data
            '            End If
            '            'divido per le cifre decimali
            '            dblTmp /= 10 ^ dec_fig_in(0)
            '            'memorizzo il dato
            '            Select Case i
            '                Case 0 : CutterRadius_Wear = dblTmp
            '                Case 1 : CutterRadius_Geometry = dblTmp
            '                Case 2 : ToolLenght_Wear = dblTmp
            '                Case 3 : ToolLenght_Geometry = dblTmp
            '            End Select
            '        End If
            '    Next

            'End If

        End Function

        ''' <summary>
        ''' Blocca l'accesso alla tabella dei correttori
        ''' </summary>
        ''' <param name="Lock">=True: Blocca la tabella, =False: Sblocca la tabella</param>
        ''' <returns>True se andata a buon fine</returns>
        Public Overrides Function O_LockOffsetTable(ByVal Lock As Boolean) As Boolean
            Static bLocked As Boolean
            Dim szReturn As String = ""
            Dim nRetry As Integer
Retry:      nRetry += 1

            Try
                If Lock Then
                    If Not bLocked Then
                        Dim myLockTableIIR As OPENcontrol.LockTableIIR
                        Dim myLockTableII As New OPENcontrol.LockTableII
                        myLockTableII.TableNum = O_Table.OFFSET_TABLE_ID
                        myLockTableIIR = OPENws.LockTableII(myLockTableII)
                        If O_CheckRetError(myLockTableIIR.retval, myLockTableIIR.ErrClass, myLockTableIIR.ErrNum, String.Format("LockTableII({0}) O_LockOffsetTable CNC.OSAI_OPEN", myLockTableII.TableNum), szReturn) Then
                            'Throw New CmsNcException(szReturn)
                            Return False
                        End If
                        bLocked = True
                    End If
                Else
                    Dim myUnLockTableIIR As OPENcontrol.UnLockTableIIR
                    Dim myUnLockTableII As New OPENcontrol.UnLockTableII
                    myUnLockTableII.TableNum = O_Table.OFFSET_TABLE_ID
                    myUnLockTableIIR = OPENws.UnLockTableII(myUnLockTableII)
                    If O_CheckRetError(myUnLockTableIIR.retval, myUnLockTableIIR.ErrClass, myUnLockTableIIR.ErrNum, String.Format("UnLockTableII({0}) O_LockOffsetTable CNC.OSAI_OPEN", myUnLockTableII.TableNum), szReturn) Then
                        'Throw New CmsNcException(szReturn)
                        Return False
                    End If
                    bLocked = False
                End If
                Return True
            Catch ex As System.ServiceModel.CommunicationException
                If nRetry < MAXRET Then GoTo Retry
                Throw New CmsNcException(ex.Message)
                Return False
            End Try
        End Function


        ''' <summary>
        ''' Legge il numero del processo attivo
        ''' </summary>
        ''' <param name="ProcessId">Valore di ritorno del processo selezionato</param>
        ''' <returns>True se andata a buon fine</returns>
        Public Overloads Overrides Function O_GetSelectedProcess(ByRef ProcessId As Short) As Boolean
            Dim szReturn As String = ""
            Dim myGetSelectedProcessR As OPENcontrol.GetSelectedProcessR
            Dim myGetSelectedProcess As New OPENcontrol.GetSelectedProcess
            Dim nRetry As Integer
Retry:      nRetry += 1

            Try
                myGetSelectedProcessR = OPENws.GetSelectedProcess(myGetSelectedProcess)
                If O_CheckRetError(myGetSelectedProcessR.retval, myGetSelectedProcessR.ErrClass, myGetSelectedProcessR.ErrNum, "GetSelectedProcess() O_GetSelectedProcess CNC.OSAI_OPEN", szReturn) Then
                    Throw New CmsNcException(szReturn)
                    Return False
                End If

                ProcessId = UnsignedToShort(myGetSelectedProcessR.ProcNum)
                Return True
            Catch ex As System.ServiceModel.CommunicationException
                If nRetry < MAXRET Then GoTo Retry
                Throw New CmsNcException(ex.Message)
                Return False
            End Try
        End Function

        ''' <summary>
        ''' Legge la riga del programma attivo
        ''' </summary>
        ''' <param name="Line">Riga in esecuzione del programma attivo</param>
        ''' <returns>True se andata a buon fine</returns>
        Public Overloads Overrides Function O_GetActiveLineProgram(ByRef Line As String) As Boolean
            Dim szReturn As String = ""
            Dim myGetPartProgramLinesR As OPENcontrol.GetPartProgramLinesR
            Dim myGetPartProgramLines As New OPENcontrol.GetPartProgramLines
            Dim ProcessId As Short
            Dim nRetry As Integer
Retry:      nRetry += 1

            Try
                O_GetSelectedProcess(ProcessId)

                myGetPartProgramLines.ProcNum = ProcessId
                myGetPartProgramLinesR = OPENws.GetPartProgramLines(myGetPartProgramLines)
                If O_CheckRetError(myGetPartProgramLinesR.retval, myGetPartProgramLinesR.ErrClass, myGetPartProgramLinesR.ErrNum, "GetPartProgramLines() O_GetActiveLineProgram CNC.OSAI_OPEN", szReturn) Then
                    Throw New CmsNcException(szReturn)
                    Return False
                End If

                Line = myGetPartProgramLinesR.PPLine2
                Return True
            Catch ex As System.ServiceModel.CommunicationException
                If nRetry < MAXRET Then GoTo Retry
                Throw New CmsNcException(ex.Message)
                Return False
            End Try
        End Function


        ''' <summary>
        ''' Legge la tabella assi
        ''' </summary>
        ''' <param name="ProcessId">Processo selezionato</param>
        ''' <param name="AxisTable">Valore di ritorno Assi del processo selezionato</param>
        ''' <returns>True se andata a buon fine</returns>
        Public Overloads Overrides Function O_GetAxisTab(ByVal ProcessId As Short, ByRef AxisTable() As Char, ByRef AxisIdTable() As Short) As Boolean
            Dim szReturn As String = ""
            Dim i, j As Integer
            Dim myGetAxesInfo3R As OPENcontrol.GetAxesInfo3R
            Dim myGetAxesInfo3 As New OPENcontrol.GetAxesInfo3
            Dim nRetry As Integer
Retry:      nRetry += 1

            Try
                myGetAxesInfo3.AxesNum = 64
                myGetAxesInfo3R = OPENws.GetAxesInfo3(myGetAxesInfo3)
                If O_CheckRetError(myGetAxesInfo3R.retval, myGetAxesInfo3R.ErrClass, myGetAxesInfo3R.ErrNum, "GetAxesInfo3() O_RW_Word CNC.OSAI_OPEN", szReturn) Then
                    Throw New CmsNcException(szReturn)
                    Return False
                End If

                For i = 0 To 63
                    If myGetAxesInfo3R.AxOwnerList(i) = ProcessId Then
                        If (myGetAxesInfo3R.AxNameList(i) < Asc("a") Or myGetAxesInfo3R.AxNameList(i) > Asc("z")) And myGetAxesInfo3R.AxNameList(i) <> Asc("S") Then
                            AxisTable(j) = Chr(myGetAxesInfo3R.AxNameList(i))
                            AxisIdTable(j) = i + 1
                            j += 1
                        End If
                        'ElseIf myGetAxesInfo3R.AxOwnerList(i) = &HFFFF& Then 'Non esco perchè gli assi potrebbero non essere in fila
                        '    Exit For
                    End If
                Next i

                Return True
            Catch ex As System.ServiceModel.CommunicationException
                If nRetry < MAXRET Then GoTo Retry
                Throw New CmsNcException(ex.Message)
                Return False
            End Try
        End Function


    End Class

End Namespace
