Online Development Notebook > Index > ODN > Raw Device Programming

Raw Device Programming


(Note: The easiest way to interface to the device in Windows is through the USBm DLL Programming method.)

You can directly communicate with the Windows API using the device raw commands to program the USB interface boards. The raw commands are described here. Use this method of interfacing to the USB device only if your programming language has no support for using the DLL.

For VB the support files (those with a .bas extension) separate the bulk of the interface details from the main VB application.

The operations that control the USB device are commands that write data to the device and read data from the device. These two function calls provide a way for commands to be sent to the device, and replies read. The "payload" of the functions is the "raw" device command.

To write E7h to port A use the command 01-E7-00-00-00-00-00-00

Visual Basic Programming

The sample programs that are a part of the ODN have been written in Visual Basic version 6.0. A group of files, the "VBLIB" are used to hide the complexity of interfacing to the U4xx. These files are adapted from the files created by John Hyde, author of "USB Design by Example" and a DLL from Dan Appleman, author of "Visual Basic Programmer's guide to the Win32 API". The files of the VB library and the DLL can be downloaded (all application files) from this site.

By using these visual basic files developed by John, anyone exploring how the USB HID interface is programmed can use John's excellent book as a guide. The book explains in detail about USB devices and the HID interface to the PC. The U4xx examples use the methods developed by John, but do not go into any detail.

The basic files are:

osinterface.bas

hidinterface.bas

miscfunc.bas

The osinterface.bas file defines all of the API routines and data structures necessary to communicate with the USB subsystem. The hidinterface.bas file contains the helper functions for opening, closing, writing to, and reading from the U4xx. Miscfunc.bas has some generic hex, string, and ASCII helper functions.

The function "OpenUSBdevice" opens the first device that matches the data in the function's parameters. The parameters are:

NameOfDevice$ - The device product name "U401".

ManufactOfDevice$ - The device manufacturer name "USBmicro".

VIDOfDevice - The Vendor Identification - 0DE7

PIDOfDevice - The Product Identification - 0191

DIDOfDevice - The Device ID (or device version) - 0100

SerNumOfDevice$ - The serial number of the device (specific to the purchased U401)

Unused parameters should be 0 or the null string, as appropriate.

The "ReadUSBdevice" function and the 'WriteUSBdevice" function transfer data to and from the open USB device.

The "CloseUSBdevice" function closes the connection to the U4xx.

DLL Support for Examples

To operate the samples, a library file is necessary.

The DLL file is:

apigid32.dll

The DLL should be copied to the Windows system directory. (Obtained as part of the VBLIB download, above.)

The support files are included with the application samples and also located here (all application files).


Hardware:  U401 USB Interface    U421 USB Interface
Programming:  USBm DLL Programming    Download Files
Application Notes:  U4x1 Application Notes    Misc Applications and Information    FAQ