Online Development Notebook > Index > 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 U4x1 examples use the methods developed by John, but do not go into any detail.

The basic files are:




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 U4x1. 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:


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).

Raw Command Summary

The Command Table below summarizes all of the allowed U4xx commands. The Command Name is for easy reference to the command, it is the command number given below in hexadecimal format that is used in the first byte of the command string for the command. The individual command pages that follow this summary give detailed information on the format and use of these commands.

Empty entries in the table indicate unused command values. These values are reserved.

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

Command Name # Description
InitPorts 00 Initialize both 8 bit ports as passive inputs
WriteA 01 Write to port A
WriteB 02 Write to port B
WriteABit 03 Write masked values to port A
WriteBBit 04 Write masked values to port B
ReadA 05 Read port A
ReadB 06 Read port B
SetBit 07 Set a single line⁄bit high
ResetBit 08 Reset a single line⁄bit low
DirectionA 09 Port A direction
DirectionB 0A Port B direction
StrobeWrite2 0B Strobe Write
StrobeRead2 0C Strobe Read
StrobeWrites 0D Multi-byte Strobe Write
StrobeReads 0E Multi-byte Strobe Read
ReadLatchesCmd 0F  
InitLCD 10 Init LCD
LCDCmd 11 Write LCD command
LCDData 12 Write LCD data
InitSPI 14 Init SPI pins and SPI control attributes
SPIMaster 15 Send⁄Receive SPI data as a master
SPISlaveWrite 16 Write SPI slave message
SPISlaveRead 17 Read SPI slave message
Wire2ControlCmd 18  
Wire2Data 19  
Stepper 1C Control two stepper motor digital channels
Reset1Wire 1D Select pin for 1-wire bus and send reset command to the bus.
Write1WireBit 1E Write to 1-wire bus
Read1WireBit 1F Read from 1-wire bus


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

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

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

This page is created with TreePad