USBmicro

Your source for USB electrical device interface products.

  • Home
  • Services
    • Design
    • Contact USBmicro
  • Where to buy…
You are here: Home / Documentation / Programming Overview / Visual Basic Example

Visual Basic Example

This example uses VB to interface to the U4xx. The very minimum application would be to open the USB device and transmit a single command. This example shows the code that it takes to use USBm.dll to open the U4xx device and initialize the ports.

VB Declaration

Public Declare Function USBm_About _
    Lib “USBm.dll” _
        (ByVal aboutstring As String) _
    As Integer

The declaration for the file “USBm.dll” is included in the Visual Basic project by including the file “USBmAPI.bas”. This example declaration above will return the “about” string contained in the DLL. All of the DLL functions are declared in “USBmAPI.bas”.

VB Example

    USBm_About strng
    frmMain.lstInfo.AddItem “About the USBm DLL: ” & strng

This code fragment shows that strng is loaded with the “about” text of the DLL. Assuming that the form called “Main” exists with a text box called “Info”, the “about” information will be made visible to the user.

Dim w As Integer
    ‘ Search for device(s)
    w = USBm_FindDevices

    ‘ Test return value
    If (w) Then
        frmMain.lstInfo.AddItem (”  Devices found.”)
    Else
        frmMain.lstInfo.AddItem (”  Devices not found.”)
    End If

This code fragment shows the call needed in order to find the devices on the bus. This DLL function needs to be called before any other device communication. Assuming that the form called “Main” exists with a text box called “Info”, the found⁄not found message will be made visible to the user.

  USBm_InitPorts (0)

This code fragment initializes the ports of device 0.

Documentation

Open all | Close all