|Online Development Notebook > Index > U4x1 Application Notes > App0: Cmd Test > App0: VB Implementation with USBm.dll|
App0: VB Implementation with USBm.dll
The VB project includes the file USBmAPI.bas. This file acts as the interface between the VB project code and the USBm.dll. Each function in the DLL has a corresponding declaration in this basic file, so that the VB compiler can correctly match the called parameters. This application uses the USBm.dll interface, but uses the DLL commands USBm_ReadDevice and USBm_WriteDevice to send the raw commands.
| ' Discover device(s)|
' First U4xx device
If USBm_DeviceValid(0) Then
DeviceStatus.Caption = "USB Device Found"
DeviceStatus.BackColor = &H1FF00
result = USBm_DeviceMfr(0, workstr)
Manufact.Caption = "Made by: " & Hex$(USBm_DeviceVID(0)) & ": " & workstr
result = USBm_DeviceProd(0, workstr)
Device.Caption = Hex$(USBm_DevicePID(0)) + ": " + workstr
DevVersion.Caption = Hex$(USBm_DeviceDID(0))
result = USBm_DeviceSer(0, workstr)
Serial.Caption = workstr
DeviceStatus.Caption = "USB Device Not Found"
DeviceStatus.BackColor = &H1FF
USBm_FindDevices is called to have the DLL find the U4x1 devices attached to all USB buses. The devices are found and assigned to an internal table. The device table starts at 0, so the first U4x1 device found would be device 0. The second USB device would be device 1, and so on.
The sample application addresses a single U4x1 device, the first (0) device. If a valid device 0 is found, then get some general information from e device, such as the serial number.
Send a command to the U4x1
| ' Send a command to the device|
Private Sub Cmd_Click()
' Get bytes from input boxes
OutBuffer(0) = ReturnHexByte(Byte0.Text)
OutBuffer(1) = ReturnHexByte(Byte1.Text)
OutBuffer(2) = ReturnHexByte(Byte2.Text)
OutBuffer(3) = ReturnHexByte(Byte3.Text)
OutBuffer(4) = ReturnHexByte(Byte4.Text)
OutBuffer(5) = ReturnHexByte(Byte5.Text)
OutBuffer(6) = ReturnHexByte(Byte6.Text)
OutBuffer(7) = ReturnHexByte(Byte7.Text)
' Copy data to display box
StatusBox.AddItem "> " + _
TwoHexCharacters$(OutBuffer(0)) + " " + _
TwoHexCharacters$(OutBuffer(1)) + " " + _
TwoHexCharacters$(OutBuffer(2)) + " " + _
TwoHexCharacters$(OutBuffer(3)) + " " + _
TwoHexCharacters$(OutBuffer(4)) + " " + _
TwoHexCharacters$(OutBuffer(5)) + " " + _
TwoHexCharacters$(OutBuffer(6)) + " " + _
' Write command to device, and get reply
' Copy data to display box
StatusBox.AddItem " " + _
TwoHexCharacters$(InBuffer(0)) + " " + _
TwoHexCharacters$(InBuffer(1)) + " " + _
TwoHexCharacters$(InBuffer(2)) + " " + _
TwoHexCharacters$(InBuffer(3)) + " " + _
TwoHexCharacters$(InBuffer(4)) + " " + _
TwoHexCharacters$(InBuffer(5)) + " " + _
TwoHexCharacters$(InBuffer(6)) + " " + _
StatusBox.AddItem " "
' USB Transfer
Public Sub WriteReadUSB()
USBm_WriteDevice 0, OutBuffer(0)
USBm_ReadDevice 0, InBuffer(0)
This code shows what is done when the command button is pressed. First, the bytes that are in the input boxes (take a look at the form) are copied to an array. Those command bytes are then copied to the display.
The call to WriteReadUSB is the communication with the U4x1 device. WriteReadUSB transfers the command to the USB device, and gets the reply from the device. The device reply is then copied to the display.
Download all application files: (all application files)
|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