Click here to Skip to main content
15,885,366 members
Articles / Programming Languages / C#
Article

A USB HID Component for C#

Rate me:
Please Sign up or sign in to vote.
4.12/5 (86 votes)
22 Mar 2007CPOL1 min read 2M   68.5K   240   339
A component to communicate with a USB HID device

Introduction

This article is about a USB HID component which enables you to communicate with HID devices over USB. There is no default component available for USB at this moment, and this component should provide you with a good starting point when writing your own USB HID enabled applications.

This article provides a sample application as well as the component itself.

Background

The component is based on various sources. A good start for USB in C# is this website. Also the book USB COMPLETE (third edition) by Jan Axelson is a must read for anyone wishing to incorporate USB HID into her/his application.

The component is developed during a project at the Avans Hogeschool in 's-Hertogenbosch, The Netherlands.

Using the Code

In the provided sample application, there is a good demonstration on how to include the component. Moreover, the use of the component is very well demonstrated. The only thing that must be done in your own application is implementing the events.

You'll also have to override the following functions in your form, so that your program is USB aware. In the property box, you'll have to provide a vendor and product id of your USB device in order to detect the correct device.

C#
protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);
usb.RegisterHandle(Handle);
}
protected override void WndProc(ref Messagea m)
{
usb.ParseMessages(ref m);
base.WndProc(ref m); // pass message on to base form
}

Points of Interest

A mouse is always in use by Windows, and cannot be captured by your own application. This also applies to HID devices in use by other applications.

History

  • 22nd March, 2007: First version, currently in development

Updates will be posted if there is a need for them.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Netherlands Netherlands
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralRe: How to get the friendly name of HID device? Pin
WuRichard1-Sep-09 5:22
WuRichard1-Sep-09 5:22 
GeneralRe: How to get the friendly name of HID device? Pin
rice-_-8-Sep-09 23:51
rice-_-8-Sep-09 23:51 
Questionreceive data doesn't fire Pin
tolgakayahan24-Aug-09 23:10
tolgakayahan24-Aug-09 23:10 
AnswerRe: receive data doesn't fire Pin
tolgakayahan26-Aug-09 1:18
tolgakayahan26-Aug-09 1:18 
GeneralRe: receive data doesn't fire Pin
tolgakayahan2-Sep-09 12:40
tolgakayahan2-Sep-09 12:40 
GeneralRe: receive data doesn't fire Pin
Member 5600194-Sep-09 3:14
Member 5600194-Sep-09 3:14 
GeneralRe: receive data doesn't fire Pin
tolgakayahan13-Sep-09 5:51
tolgakayahan13-Sep-09 5:51 
GeneralRe: receive data doesn't fire Pin
yahaiyakhan29-Sep-09 1:25
yahaiyakhan29-Sep-09 1:25 
GeneralRe: receive data doesn't fire Pin
hande548-Oct-09 9:21
hande548-Oct-09 9:21 
GeneralRe: receive data doesn't fire Pin
becktoan31-Oct-09 17:11
becktoan31-Oct-09 17:11 
GeneralRe: receive data doesn't fire Pin
becktoan31-Oct-09 17:17
becktoan31-Oct-09 17:17 
GeneralRe: receive data doesn't fire Pin
kaiwi66623-Nov-09 23:51
kaiwi66623-Nov-09 23:51 
GeneralRe: receive data doesn't fire Pin
Ayman Alterawi28-May-11 2:45
Ayman Alterawi28-May-11 2:45 
GeneralRe: receive data doesn't fire Pin
RichRobinson20-Sep-11 7:32
RichRobinson20-Sep-11 7:32 
GeneralYou Rock My Face Pin
blackey024-Aug-09 15:55
blackey024-Aug-09 15:55 
GeneralAwesome! Thanks :) Pin
omie654125-Jul-09 7:02
omie654125-Jul-09 7:02 
QuestionUSB Polling Time - USB HUB Pin
bublabla20-Jul-09 20:33
bublabla20-Jul-09 20:33 
GeneralMy vote of 2 Pin
jasona2218-Jun-09 5:21
jasona2218-Jun-09 5:21 
JokeDoesn't work on 64 bit Vista. Pin
melntess28-May-09 10:14
melntess28-May-09 10:14 
GeneralRe: Doesn't work on 64 bit Vista. Pin
melntess28-May-09 12:25
melntess28-May-09 12:25 
GeneralRe: Doesn't work on 64 bit Vista. Pin
Yuriy Opryshko17-Aug-09 23:34
Yuriy Opryshko17-Aug-09 23:34 
GeneralRe: Doesn't work on 64 bit Vista. Pin
Yuriy Opryshko18-Aug-09 1:06
Yuriy Opryshko18-Aug-09 1:06 
GeneralOMG. You are my savior. Pin
melntess27-May-09 19:12
melntess27-May-09 19:12 
QuestionCloseHandle problem on Win XP SP3? Pin
Henrik Danielsson9-May-09 8:52
Henrik Danielsson9-May-09 8:52 
AnswerRe: CloseHandle problem on Win XP SP3? Pin
gunnibaba16-Feb-11 12:46
gunnibaba16-Feb-11 12:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.