Author Topic: General Visual Basic Example  (Read 4295 times)

moreis62

  • Full Member
  • ***
  • Posts: 102
    • View Profile
    • http://www.myway.com/
General Visual Basic Example
« on: March 19, 2005, 12:56:39 am »
This example uses VB to initialize 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 open the U4xx device and initialize the ports. The VBLIB files need to be included as part of this project.
The communication with the U4xx is done by transferring a group of eight bytes via the WriteUSBdevice call of the U4xx VB library. Eight bytes are returned from the device and read via the ReadUSBdevice U4xx VB call. These bytes are located in two arrays that are defined below.
Option Explicit
Dim OutBuffer(10) As Byte
Dim InBuffer(10) As Byte
When the form for this project is loaded, a call to OpenUSBdevice with the appropriate parameters returns true if the device has been detected.
The OpenUSBdevice parameters are used to find the device. A single parameter (in this example the string "U401") will open the first device located that matches that string. Multiple parameters allow devices to be opened via manufacturer name, VID, etc.
When a single parameter is used, the other parameters should be either 0, or a null string, as in the example.
Multiple parameters are used when device selection refinement is necessary, such as when multiple U4xx devices are used on a single machine. In that case, the serial number string should be used to refine the selection.

' Form load
' When the form is loaded at startup, find the hardware.
' Indicate status in "DeviceStatus" box.

Private Sub Form_Load()

    If OpenUSBdevice("U401", "", 0, 0, 0, "") Then
        DeviceStatus.Caption = "USB Device Found"
    Else
        DeviceStatus.Caption = "USB Device Not Found"
    End If

End Sub
Calling the function WriteReadUSB moves the eight command bytes of the array "OutBuffer" to the device and fills "InBuffer" with the 8 bytes sent from the U4xx.
' USB Transfer

Public Sub WriteReadUSB()
   
    Call WriteUSBdevice(AddressFor(OutBuffer(0)), 8)
    DoEvents
    Call ReadUSBdevice(AddressFor(InBuffer(0)), 8)

End Sub
The single button on the form of this application example transmits the InitPorts Command string of 00-00-00-00-00-00-00-00 to the U4xx.
' Button: Cmd

' Send a command to the device

Private Sub Cmd_Click()

    OutBuffer(0) = &H0
    OutBuffer(1) = &H0
    OutBuffer(2) = &H0
    OutBuffer(3) = &H0
    OutBuffer(4) = &H0
    OutBuffer(5) = &H0
    OutBuffer(6) = &H0
    OutBuffer(7) = &H0
   
    Call WriteReadUSB
       
End Sub

 
 
 
« Last Edit: March 19, 2005, 12:58:04 am by moreis62 »
ISMAEL LEDESMA.