Imports System
Imports System.Runtime.InteropServices
Imports System.Text

Public Class HartDLL_Iface
    '*************
    '* Constants *
    '*************
    'Handles
    Public Const INVALID_DRV_HANDLE = -1
    Public Const INVALID_SRV_HANDLE = -1
    'Boolean
    Public Const T_TRUE = 1
    Public Const T_FALSE = 0
    'Bits
    Public Const T_SET = 1
    Public Const T_CLEAR = 0
    'Master ID
    Public Const SLV_PRIM = 0
    Public Const SLV_SCND = 1
    'Baud Rates
    Public Const CBR_1200 = 1200
    Public Const CBR_2400 = 2400
    Public Const CBR_4800 = 4800
    Public Const CBR_9600 = 9600
    Public Const CBR_19200 = 19200
    Public Const CBR_38400 = 38400
    'Service Comon Report Codes
    Public Const SRV_EMPTY = 0
    Public Const SRV_NO_DEV_RESP = 1
    Public Const SRV_COMM_ERR = 2
    Public Const SRV_INVALID_HANDLE = 3
    Public Const SRV_IN_PROGRESS = 4
    Public Const SRV_SUCCESSFUL = 5
    'Quality of ce
    Public Const DRV_NO_WAIT = 0
    Public Const DRV_WAIT = 1
    'Endians
    Public Const MSB_FIRST = 0
    Public Const LSB_FIRST = 1
    'Slave Mode
    Public Const SLAVE_DISABLED = 0
    Public Const SLAVE_ENABLED = 1
    'Response codes
    Public Const HRT_RSPCODE_CMD_NOT_IMPL = &H40

    '**************
    '* Structures *
    '**************
    <StructLayout(Runtime.InteropServices.LayoutKind.Sequential)> _
    Structure T_strConfiguration
      Public uiBaudrate As UInteger
      Public byNumPreambles As Byte
      Public byNumRetries As Byte
      Public byRetryIfBusy As Byte
      Public byInitialMaster As Byte
      Public byAddressingMode As Byte
      Public byDoNotUseRtsDtr As Byte
      Public usAddTimeOut As UShort
      Public usAddGapTime As UShort
      Public usAddRtsOffDelay As UShort
      Public bySendJabberOctet As Byte
    End Structure

    <StructLayout(Runtime.InteropServices.LayoutKind.Sequential)> _
    Structure T_strConnection
      Public byManuId As Byte
      Public byDevId As Byte
      Public byNumPreambles As Byte
      Public byCmdRevNum As Byte
      Public bySpecRevCode As Byte
      Public bySwRev As Byte
      Public byHwRev As Byte
      Public byHartFlags As Byte
      Public byError As Byte
      Public byResp_1 As Byte
      Public byResp_2 As Byte
      Public byUsedRetries As Byte
      Public bDeviceInBurstMode As Byte
      Public byReserved1 As Byte
      Public byReserved2 As Byte
      Public byReserved3 As Byte
      <MarshalAs(UnmanagedType.ByValArray, SizeConst:=5)> Public abyUniqueID() As Byte
    End Structure

    <StructLayout(Runtime.InteropServices.LayoutKind.Sequential)> _
    Structure T_strConfirmation
      public byCmd as Byte
      Public byResp_1 As Byte
      Public byResp_2 As Byte
      Public byError As Byte
      Public byUsedRetries As Byte
      Public bDeviceBursting As Byte
      Public sDuration As UShort
      Public uiAppKey As UInteger
      public byReserved1 as Byte
      Public byReserved2 As Byte
      Public byReserved3 As Byte
      Public byDataLen As Byte
      <MarshalAs(UnmanagedType.ByValArray, SizeConst:=64)> Public aby_Data() As Byte
    End Structure

    <StructLayout(Runtime.InteropServices.LayoutKind.Sequential)> _
    Structure T_strDataBuffer
      Public byDataLen As Byte
      <MarshalAs(UnmanagedType.ByValArray, SizeConst:=64)> Public aby_Data() As Byte
    End Structure

    '*************
    '* Functions *
    '*************
    <DllImport("BaHartDrv60.dll", CharSet:=CharSet.Ansi)> _
    Public Shared Function BHDrv_OpenChannel(ByVal usComPort As UShort) As Integer
    End Function

    <DllImport("BaHartDrv60.dll", CharSet:=CharSet.Ansi)> _
    Public Shared Sub BHDrv_CloseChannel(ByVal hChannel As Integer)
    End Sub

    <DllImport("BaHartDrv60.dll", CharSet:=CharSet.Ansi)> _
    Public Shared Sub BHDrv_GetConfiguration(ByVal hChannel As Integer, ByRef strConfiguration As T_strConfiguration)
    End Sub

    <DllImport("BaHartDrv60.dll", CharSet:=CharSet.Ansi)> _
    Public Shared Sub BHDrv_SetConfiguration(ByVal hChannel As Integer, ByRef strConfiguration As T_strConfiguration)
    End Sub

    <DllImport("BaHartDrv60.dll", CharSet:=CharSet.Ansi)> _
    Public Shared Function BHDrv_ConnectByAddr(ByVal hChannel As Integer, ByVal byAddr As Byte, ByVal byQOS As Byte, ByVal byNumRetries As Byte) As Integer
    End Function

    <DllImport("BaHartDrv60.dll", CharSet:=CharSet.Ansi)> _
    Public Shared Function BHDrv_ConnectByTagName(ByVal hChannel As Integer, ByRef byTagName() As Byte, ByVal byQOS As Byte, ByVal byNumRetries As Byte) As Integer
    End Function

    <DllImport("BaHartDrv60.dll", CharSet:=CharSet.Ansi)> _
    Public Shared Function BHDrv_ConnectByUniqueID(ByVal hChannel As Integer, ByRef byUniqueID() As Byte, ByVal byQOS As Byte, ByVal byNumRetries As Byte) As Integer
    End Function

    <DllImport("BaHartDrv60.dll", CharSet:=CharSet.Ansi)> _
    Public Shared Sub BHDrv_FetchConnection(ByVal hService As Integer, ByRef strConnection As T_strConnection)
    End Sub

    <DllImport("BaHartDrv60.dll", CharSet:=CharSet.Ansi)> _
    Public Shared Function BHDrv_DoCommand(ByVal hChannel As Integer, ByVal byCmd As Byte, ByVal byQOS As Byte, ByRef pbyData As Byte, ByVal byLen As Byte, ByVal uiAppKey As UInteger, ByRef byUniqueID As Byte) As UInteger
    End Function

    <DllImport("BaHartDrv60.dll", CharSet:=CharSet.Ansi)> _
    Public Shared Function BHDrv_IsServiceCompleted(ByVal hService As Integer) As Byte
    End Function

    <DllImport("BaHartDrv60.dll", CharSet:=CharSet.Ansi)> _
    Public Shared Sub BHDrv_FetchConfirmation(ByVal hService As Integer, ByRef strConfirmation As T_strConfirmation)
    End Sub

    <DllImport("BaHartDrv60.dll", CharSet:=CharSet.Ansi)> _
    Public Shared Sub BHDrv_PutInt8(ByVal byData As Byte, ByVal byOffs As Byte, ByRef pbyData As Byte)
    End Sub

    <DllImport("BaHartDrv60.dll", CharSet:=CharSet.Ansi)> _
    Public Shared Sub BHDrv_PutInt16(ByVal usData As UShort, ByVal byOffs As Byte, ByRef pbyData As Byte, ByVal byEndian As Byte)
    End Sub

    <DllImport("BaHartDrv60.dll", CharSet:=CharSet.Ansi)> _
    Public Shared Sub BHDrv_PutInt24(ByVal uiData As UInteger, ByVal byOffs As Byte, ByRef pbyData As Byte, ByVal byEndian As Byte)
    End Sub

    <DllImport("BaHartDrv60.dll", CharSet:=CharSet.Ansi)> _
    Public Shared Sub BHDrv_PutInt32(ByVal uiData As UInteger, ByVal byOffs As Byte, ByRef pbyData As Byte, ByVal byEndian As Byte)
    End Sub

    <DllImport("BaHartDrv60.dll", CharSet:=CharSet.Ansi)> _
    Public Shared Sub BHDrv_PutFloat(ByVal fData As Single, ByVal byOffs As Byte, ByRef pbyData As Byte, ByVal byEndian As Byte)
    End Sub

    <DllImport("BaHartDrv60.dll", CharSet:=CharSet.Ansi)> _
    Public Shared Sub BHDrv_PutPackedASCII(ByVal sb As StringBuilder, ByVal byLen As Byte, ByVal byOffs As Byte, ByRef pbyData As Byte)
    End Sub

    <DllImport("BaHartDrv60.dll", CharSet:=CharSet.Ansi)> _
    Public Shared Sub BHDrv_PutOctets(ByRef pbySrcData As Byte, ByVal byLen As Byte, ByVal byOffs As Byte, ByRef pbyDstData As Byte)
    End Sub

    <DllImport("BaHartDrv60.dll", CharSet:=CharSet.Ansi)> _
    Public Shared Sub BHDrv_PutString(ByVal sb As StringBuilder, ByVal byLen As Byte, ByVal byOffs As Byte, ByRef pbyData As Byte)
    End Sub

    <DllImport("BaHartDrv60.dll", CharSet:=CharSet.Ansi)> _
    Public Shared Function BHDrv_PickInt8(ByVal byOffs As Byte, ByRef pbyData As Byte) As Byte
    End Function

    <DllImport("BaHartDrv60.dll", CharSet:=CharSet.Ansi)> _
    Public Shared Function BHDrv_PickInt16(ByVal byOffs As Byte, ByRef pbyData As Byte, ByVal byEndian As Byte) As UShort
    End Function

    <DllImport("BaHartDrv60.dll", CharSet:=CharSet.Ansi)> _
    Public Shared Function BHDrv_PickInt24(ByVal byOffs As Byte, ByRef pbyData As Byte, ByVal byEndian As Byte) As UInteger
    End Function

    <DllImport("BaHartDrv60.dll", CharSet:=CharSet.Ansi)> _
    Public Shared Function BHDrv_PickInt32(ByVal byOffs As Byte, ByRef pbyData As Byte, ByVal byEndian As Byte) As UInteger
    End Function

    <DllImport("BaHartDrv60.dll", CharSet:=CharSet.Ansi)> _
    Public Shared Function BHDrv_PickFloat(ByVal byOffs As Byte, ByRef pbyData As Byte, ByVal byEndian As Byte) As Single
    End Function

    <DllImport("BaHartDrv60.dll", CharSet:=CharSet.Ansi)> _
    Public Shared Sub BHDrv_PickPackedASCII(ByVal sb As StringBuilder, ByVal byLen As Byte, ByVal byOffs As Byte, ByRef pbyData As Byte)
    End Sub

    <DllImport("BaHartDrv60.dll", CharSet:=CharSet.Ansi)> _
    Public Shared Sub BHDrv_PickOctets(ByRef pbyDstData As Byte, ByVal byLen As Byte, ByVal byOffs As Byte, ByRef pbySrcData As Byte)
    End Sub

    <DllImport("BaHartDrv60.dll", CharSet:=CharSet.Ansi)> _
    Public Shared Sub BHDrv_PickString(ByVal sb As StringBuilder, ByVal byLen As Byte, ByVal byOffs As Byte, ByRef pbyData As Byte)
    End Sub
End Class
