Version 1.20
06/14/11
Copyright (C) 2003 - 2011
All rights reserved
USB HID API Library
Develop custom USB HID applications
using existing Windows drivers!
for software
developers, engineers,
and programmers
by K.A. Delahoussaye
Delahoussaye Consulting
web: www.kadtronix.com
email: info@kadtronix.com
When using this library to develop your USB HID device, there are no device drivers to create since the API uses existing Windows HID class drivers. Used primarily for keyboards, mice, and joysticks, the HID class is also well-suited for special-purpose applications including access and control of custom-developed devices. UsbHidApi encapsulates API calls that give you easy access to your device. These API calls can be used in any development environment that accepts DLLs (e.g., Microsoft Visual C++ or Visual Basic).
Device Class | Typical Use |
Audio | Sound card |
Communications | Modem, network |
Human Interface | Keyboard, mouse |
Still Image Capture | Still camera |
Printer | Printer |
Mass Storage | Disk drive, flash drive |
Hub | USB hub |
Video | Camera |
Wireless | Bluetooth |
There are standard device drivers available for each class. If a device does not fall into one of these classes or the device has special requirements, a custom driver must be provided. The UsbHidApi library uses the HID class and therefore does not require a custom driver. While the HID class is typically used for devices such as keyboards, mice, and joysticks, the class is well-suited for custom-developed devices as well.
The maximum defined transfer rate for the HID class is 64K bytes/sec. For more information, please refer to the following resource:
http://www.usb.org/developers/hidpage
Kadtronix
web: http://www.kadtronix.com
email: sales@kadtronix.com
When executed, the following dialog screen image will appear on
your monitor display:
The Visual C++ 6 generic demo project source code is located on your
PC as follows:
To run the Visual Basic generic demo, first open the following folder:
The U4x1 demo is provided only for Visual C++ and was developed
primarily for showing how to access a UsbMicro U4x1 device. When
executed, the following dialog screen image will appear on your monitor
display:
The Visual C++ U4x1 demo project source code is located on your PC as follows:
A trial version of the UsbHidApi is available for free
download.
The trial version is unregistered software that is fully operational,
but
displays periodic pop-up messages. Visit the Kadtronix website
for
download details.
Your device hardware may be plugged into any available USB
port using
a compatible cable. Since drivers pre-exist under Windows, you
may
plug in the device at any time, before or after installing the
UsbHidApi.
The Generic demo uses static linking while the U4x1demo uses dynamic linking. You may reference the appropriate demo for further details.
(This file is included in the distribution within the "VC++"
sub-folder.)
In addition, functions have been exported for compatibility with certain ANSI C compilers such as LabView and LabWindows/CVI. For these situations, a special header file has been created named UsbHidApi_2.h and is located in the "ANSI C" folder. This is a specially modified version of the original header (UsbHidApi.h) and is intended only for use with ANSI C applications. To use, copy the file to your project space and add the following statement to your C source file:
This statement serves to include or
add the file to your application. Also add the following library
file to your list of build objects
(located in the "VC++" folder):
For additional information, see the
following online resources:
(Note: Kadtronix can only provide limited
support for LabView and LabWindows applications. Demo applications for
LabView or LabWindows/CVI are not available.)
/*------ Report Descriptor Group ---------------------*/
/* This is a basic report descriptor. All data in the */
/* reports are vendor defined and therefore the host */
/* doesn't care what we
transfer
*/
BYTE code abromReportDescriptor[SIZEOF_REPORT_DESCRIPTOR] =
{
0x06, 0xA0, 0xFF, // Usage Page (FFA0H = vendor defined)
0x09, 0x01, // Usage (vendor defined)
0xA1, 0x01, // Start Collection (Application)
// INPUT DEFINITION
0x09, 0x01, // Usage (vendor defined)
0x15, 0x00, // Logical Minimum (0)
0x25, 0xff, // Logical Maximum (255)
0x75, 0x08, // Report Size ( 8 BITS)
0x95, EP1_MAX_REPORT_SIZE, // Report Count (16 Bytes)
0x81, 0x00, // Input (Data, Variable, Absolute)
// OUTPUT DEFINITION
0x09, 0x02, // Usage (vendor defined)
0x75, 0x08, // Report Size (8 BITS)
0x95, EP0_MAX_REPORT_SIZE, // Report Count (16 Bytes)
0x91, 0x00, // 0utput (Data, Variable, Absolute)
0xC0 // End Collection
};
For more information, please refer to the following resource:
http://www.usb.org/developers/hidpage
The library defines a device structure called mdeviceList.
Used primarily by the GetList( ) function, this structure defines an
entry
in a device list. The mdeviceList structure definition is
listed below.
The UsbHidApi library provides a number of functions for use by
your application. Examples of their use can be found in the demonstrations.
int
CUsbHidApi::GetList(
unsigned
int VendorID,
unsigned
int ProductID,
char
*Manufacturer,
char
*SerialNum,
char
*DeviceName,
mdeviceList
*pList,
int
nMaxDevices);
Parameter descriptions:
VendorID
// Vendor ID to search (0xffff if unused)
ProductID
// Product ID to search (0xffff if unused)
Manufacturer
//
Manufacturer
(NULL if unused)
SerialNum
// Serial number to search (NULL if unused)
DeviceName
// Device name to search (NULL if unused)
pList
// Caller's array for storing device(s)
nMaxDevices
// Size of the caller's array list (no.entries)
int
CUsbHidApi::Open(
unsigned
int VendorID,
unsigned
int ProductID,
char
*Manufacturer,
char
*SerialNum,
char
*DeviceName,
int
bAsync)
Parameter descriptions:
VendorID
// Vendor ID to search (0xffff if unused)
ProductID
// Product ID to search (0xffff if unused)
Manufacturer
//
Manufacturer
(NULL if unused)
SerialNum
// Serial number to search (NULL if unused)
DeviceName
// Device name to search (NULL if unused)
bAsync
// Set TRUE for non-blocking read requests.
int CUsbHidApi::Read(void *Buf)
Parameter description:
Buf
// Pointer to the caller's storage buffer
int CUsbHidApi::Write(void *Buf)
Parameter description:
Buf
// Pointer to the caller's storage buffer
void
CUsbHidApi::GetReportLengths
(
int
*input_len,
int
*output_len)
Parameter descriptions:
input_len
// Pointer for storing input report length
output_len
// Pointer for storing output report length
void CUsbHidApi::SetInterface (int iface)
Parameter description:
iface
// Interface (-1 if unused)
int
CUsbHidApi::GetInterface
(void)
void CUsbHidApi::SetCollection (int col)
Parameter description:
col
// Collection (-1 if unused)
int
CUsbHidApi::GetCollection
(void)
void
CUsbHidApi::CloseRead(void)
void
CUsbHidApi::CloseWrite(void)
int CUsbHidApi::GetLibVersion(LPSTR buf)
buf // Pointer to buffer for storing the version string
Refer to the following resources for additional information:
The following tables present pin-out information:
Pin Number | USB Interface Signal |
7 | +5V USB from PC |
9 | GND |
15 | PA.0 - Port A bit 0 |
16 | PA.1 - Port A bit 1 |
17 | PA.2 - Port A bit 2 |
18 | PA.3 - Port A bit 3 |
19 | PA.4 - Port A bit 4 [SPI SS (slave-mode only)] |
20 | PA.5 - Port A bit 5 [SPI MOSI] |
21 | PA.6 - Port A bit 6 [SPI MISO] |
22 | PA.7 - Port A bit 7 [SPI SCLK] |
23 | PB.0 - Port B bit 0 |
24 | PB.1 - Port B bit 1 |
25 | PB.2 - Port B bit 2 |
26 | PB.3 - Port B bit 3 |
27 | PB.4 - Port B bit 4 |
28 | PB.5 - Port B bit 5 |
29 | PB.6 - Port B bit 6 |
30 | PB.7 - Port B bit |
Pin Number | USB Interface Signal |
14 | +5V USB from PC |
9 | GND |
1 | PA.0 - Port A bit 0 |
2 | PA.1 - Port A bit 1 |
3 | PA.2 - Port A bit 2 |
4 | PA.3 - Port A bit 3 |
24 | PA.4 - Port A bit 4 [SPI SS (slave-mode only)] |
23 | PA.5 - Port A bit 5 [SPI MOSI] |
22 | PA.6 - Port A bit 6 [SPI MISO] |
21 | PA.7 - Port A bit 7 [SPI SCLK] |
5 | PB.0 - Port B bit 0 |
20 | PB.1 - Port B bit 1 |
6 | PB.2 - Port B bit 2 |
19 | PB.3 - Port B bit 3 |
7 | PB.4 - Port B bit 4 |
18 | PB.5 - Port B bit 5 |
8 | PB.6 - Port B bit 6 |
17 | PB.7 - Port B bit 7 |
Pin Number | USB Interface Signal |
J1-10 |
+5V USB from PC |
J1-9 |
GND |
J1-1 | PA.0 - Port A bit 0 |
J1-2 | PA.1 - Port A bit 1 |
J1-3 | PA.2 - Port A bit 2 |
J1-4 | PA.3 - Port A bit 3 |
J1-5 | PA.4 - Port A bit 4 [SPI SS (slave-mode only)] |
J1-6 | PA.5 - Port A bit 5 [SPI MOSI] |
J1-7 | PA.6 - Port A bit 6 [SPI MISO] |
J1-8 | PA.7 - Port A bit 7 [SPI SCLK] |
n/a | PB.0 -
Port B bit 0 [Relay 1] |
n/a | PB.1 -
Port B bit 1 [Relay 2] |
J4-1 | PB.2 - Port B bit 2 |
J4-2 | PB.3 - Port B bit 3 |
J4-3 | PB.4 - Port B bit 4 |
J4-4 | PB.5 - Port B bit 5 |
J4-5 | PB.6 - Port B bit 6 |
J4-6 | PB.7 - Port B bit 7 |