'
' libreria  : VBlib
' file      : ComCNOsaiS10WS 
'
' funzioni  : connessione con CN OSAI come classe - override metodi per vecchissime versioni pre WinNbi con S10WLK32.dll
'              usa la vecchissima DLL OSAI !!!
'
' copyright 2008-2016 C.Viviani
'
Imports Microsoft.Win32
Imports System.Runtime.InteropServices

Public Class ComCNOSAI_S10WLK32

    Inherits ComCNOsai

    Private magic_number As Short

    Private OSAI_StationName As String, OSAI_RemoteName As String
    Private OSAI_CardNumber As Short, OSAI_SessionNum As Short

   Private OSAI_OLD_NC As S10DLLPRJ.S10DLL

   '
   Public Sub New(ByRef szRemoteName As String, ByRef b_debug As Boolean)

        MyBase.New(szRemoteName, b_debug)

    End Sub

    Public Overrides Function OpenSession() As Boolean


      'OSAI_OLD_NC = New S10DLLPRJ.S10DLL

      If IniRead.b_verbose Then Log.write(" OpenSession   ")


        ' OSAI_OLD_NC.sz_remote_name = NomeCn

        If IniRead.b_verbose Then Log.write(" OpenSession  sz_remote_name :  " & OSAI_OLD_NC.sz_remote_name.ToString)

        'apro una sessione col CN
        Connected = OSAI_OLD_NC.s10_connect()

        If IniRead.b_verbose Then Log.write(" OpenSession  Connected :  " & Connected.ToString)


        Return Connected

    End Function

    Public Overrides Function CloseSession() As Boolean

        If Connected Then

            Call OSAI_OLD_NC.S10_disconnect()

        End If

        Return True

    End Function

    '------------------------------
    ' Lettura variabile Short su Cn
    '------------------------------
    Public Overrides Function ReadShortVar(ByVal szVar As stVAR, Optional ByVal nProcess As Integer = 1) As Short

        Dim n_var As Short = -9999

        '       If IniRead.b_verbose Then Log.write(" ReadShortVar  : " & szVar.nAddress.ToString)

        Try
            n_var = OSAI_OLD_NC.S10_read_plc_var_word(szVar.nAddress)

        Catch ex As Exception

            MsgBox(ex.Message)

        End Try

        Return n_var

    End Function
    ' -------------------------------
    ' Scrittura variabile Short su Cn
    '---------------------------------
    Public Overrides Function WriteShortVar(ByVal szVar As stVAR, ByVal nValue As Short, Optional ByVal nProcess As Integer = 1) As Boolean

        Return OSAI_OLD_NC.S10_write_plc_var_word(szVar.nAddress, nValue)

    End Function

    Public Overrides Function Is_NC_running() As Boolean

        Return Connected

    End Function


#Region " NON IMPLEMENTATE"

    '--------------------------------
    ' Lettura multi variabile MW su Cn
    '--------------------------------
    Public Overrides Function ReadMultipleVarMW(ByVal nAddress As Integer, ByRef nValues() As Short, ByVal nNumVarToRead As Short, Optional ByVal nProcess As Integer = 1) As Boolean
        MsgBox(" function ReadMultipleVarMW non implemented in S10WLK32")
        Return False
    End Function


    '--------------------------------
    ' Lettura variabile SC su Cn
    '--------------------------------
    Public Overrides Function ReadSCVar(ByVal nIndex As Integer, ByVal nNumChar As Integer, Optional ByVal nProcess As Integer = 1) As String
        MsgBox(" function WriteSCVar non implemented in S10WLK32")
        Return " ERROR : function WriteSCVar non implemented in S10WLK32"

    End Function

    ' ---------------------------------
    ' Scrittura variabile SC su Cn
    '----------------------------------
    Public Overrides Function WriteSCVar(ByVal nIndex As Integer, ByVal nNumChar As Integer, ByVal szText As String, Optional ByVal nProcess As Integer = 1) As Boolean
        MsgBox(" function WriteSCVar non implemented in S10WLK32")
        Return False
    End Function

    '------------------------------
    ' Lettura variabile E su Cn
    '------------------------------
    Public Overrides Function ReadVarE(ByVal szVar As stVAR, Optional ByVal nProcess As Integer = 1) As Double

        MsgBox(" function ReadVarE non implemented in S10WLK32")
        Return -99999.99

    End Function

    Public Overrides Function NcProcessStatus(ByRef ncInfo As CndexLinkDotNet.Cndex.PROCDATA, Optional ByVal nProcess As Integer = 1) As Boolean
        MsgBox(" function NcProcessStatus non implemented in S10WLK32")
        Return False
    End Function

    ' -------------------------------------------------
    ' Lettura stato macchina su processo passato per parametro
    '--------------------------------------------------
    Public Overrides Function GetMachineStatus(Optional ByVal nProcess As Integer = 1) As Byte
        MsgBox(" function GetMachineStatus non implemented in S10WLK32")
        Return False
    End Function

#End Region

    '--------------------------------------------------------------------------------------------------------
    '--------------------------------------------------------------------------------------------------------



End Class

