Online Development Notebook > Index > Programming Overview > General VB DLL Example

General Visual Basic Example using USBm.dll


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.


Hardware:  U401 USB Interface    U421 USB Interface   U451 USB Interface

Programming:  USBm DLL Programming    Download Files

Application Notes:  U4x1 Application Notes    Misc Applications and Information    FAQ

While every effort has been made to make sure that the information posted on this site is correct, the author can not be held liable for any damages whatsoever for losses as a result of the application of this information. Use this information at your own risk.

USBmicro can design your custom and semi-custom USB product. Email about USB design can be directed to " Robert " at usbmicro.com.

Copyright © USBmicro, L.L.C., 2002-2010

Previous  |  Next ]     [ Up  |  First  |  Last ]     (Article 21 of 126)

This page is created with TreePad