ADU  Series - USB Data Acquisition Interface SDK 

AduHid Quick Start Tutorial - with Visual Basic

This tutorial describes a Visual Basic program that communicates with an ADU device.

A Quick Start Tutorial is also available for the C language.

AduHid DLL

The AduHid DLL controls an ADU USB device. The main channel of communication between the PC and the ADU USB device is the ADU Device Pipe.

ADU Device Pipe

  • sends commands to the ADU device
  • receives responses from the ADU device


Declaring a Handle

A handle is required to control the device pipe connection. Declare it in the (General) (Declarations) of the form's code.

        Dim aduHandle As Long

Establishing a Connection

Establish a connection between the PC and the ADU USB device by calling AduDeviceOpen. The function returns a handle that is required in all subsequent function calls.

        aduHandle = OpenAduDevice(0)

Writing Commands

Send commands to the ADU USB device with the AduDeviceWrite function. The example shows a query for the status of relay 1.

        Dim iRC As Long
        iRC = WriteAduDevice(aduHandle, "RPK1", 4, 0, 0)

Reading Responses

Read the response from the ADU USB device with the AduDeviceRead function. The example code retrieves the results for the preceding status query.

        Dim iRC As Long
        Dim sResponse As String * 8

        iRC = ReadAduDevice(aduHandle, sResponse, 7, 0, 0)

After the ReadAduDevice function finishes the sBuffer contains the status of relay 1, either 0 (off) or 1 (on).
Note: This sample program is so minimal that the only way to see the results is to set a breakpoint on the ReadAduDevice statement and inspect the sResponse field with the debugger.

Closing the Connection

Close the connection to the ADU USB device with the AduDeviceClose function.

        CloseAduDevice (aduHandle)

Function Declarations

The AduHid functions are declared in a module that must be added to the Visual Basic project. Copy the following into the (General) (Declarations) of a new module.

        Declare Function OpenAduDevice Lib "AduHid.DLL" _
        (ByVal iTimeout As Long) As Long

        Declare Function WriteAduDevice Lib "AduHid.DLL" _
        (ByVal aduHandle As Long, ByVal lpBuffer As String, _
        ByVal lNumberOfBytesToWrite As Long, _
        ByRef lBytesWritten As Long, ByVal iTimeout As Long) As Long

        Declare Function ReadAduDevice Lib "AduHid.DLL" _
        (ByVal aduHandle As Long, ByVal lpBuffer As String, _
        ByVal lNumberOfBytesToRead As Long, _
        ByRef lBytesRead As Long, ByVal iTimeout As Long) As Long

        Declare Function CloseAduDevice Lib "AduHid.DLL" _
        (ByVal iHandle As Long) As Long

Minimal Program Listing

Here is the source code for the minimal program.

Form1.frm

VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   3135
   ClientLeft      =   90
   ClientTop       =   375
   ClientWidth     =   4620
   LinkTopic       =   "Form1"
   ScaleHeight     =   3135
   ScaleWidth      =   4620
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton Close 
      Caption         =   "Close"
      Height          =   495
      Left            =   3240
      TabIndex        =   3
      Top             =   2040
      Width           =   1215
   End
   Begin VB.CommandButton Read 
      Caption         =   "Read"
      Height          =   495
      Left            =   3240
      TabIndex        =   2
      Top             =   1440
      Width           =   1215
   End
   Begin VB.CommandButton Write 
      Caption         =   "Write"
      Height          =   495
      Left            =   3240
      TabIndex        =   1
      Top             =   840
      Width           =   1215
   End
   Begin VB.CommandButton Open 
      Caption         =   "Open"
      Height          =   495
      Left            =   3240
      TabIndex        =   0
      Top             =   240
      Width           =   1215
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim aduHandle As Long
Private Sub Close_Click()
CloseAduDevice (aduHandle)
End Sub

Private Sub Open_Click()
aduHandle = OpenAduDevice(0)
End Sub

Private Sub Read_Click()
Dim iRC As Long
Dim sResponse As String * 8

iRC = ReadAduDevice(aduHandle, sResponse, 7, 0, 0)

End Sub

Private Sub Write_Click()
Dim iRC As Long

iRC = WriteAduDevice(aduHandle, "RPK1", 4, 0, 0)
End Sub

Module1.bas

Attribute VB_Name = "Module1"
Declare Function OpenAduDevice Lib "AduHid.DLL" _
(ByVal iTimeout As Long) As Long

Declare Function WriteAduDevice Lib "AduHid.DLL" _
(ByVal aduHandle As Long, ByVal lpBuffer As String, _
ByVal lNumberOfBytesToWrite As Long, _
ByRef lBytesWritten As Long, ByVal iTimeout As Long) As Long

Declare Function ReadAduDevice Lib "AduHid.DLL" _
(ByVal aduHandle As Long, ByVal lpBuffer As String, _
ByVal lNumberOfBytesToRead As Long, _
ByRef lBytesRead As Long, ByVal iTimeout As Long) As Long

Declare Function CloseAduDevice Lib "AduHid.DLL" _
(ByVal iHandle As Long) As Long

Additional Checks

A production program requires checks to ensure correct operation. Read the other pages on this web site for more information.