Click here to Skip to main content
15,888,454 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

 
GeneralMultiple instances of the same device Pin
Thomas Kjørnes7-Jul-10 11:25
Thomas Kjørnes7-Jul-10 11:25 
GeneralNeed to close application to connect find device again [modified] Pin
witekm30-Jun-10 19:12
witekm30-Jun-10 19:12 
GeneralThanks Pin
Member 66486821-Jun-10 4:40
Member 66486821-Jun-10 4:40 
QuestionUsing in seperate class ? Pin
borisdekat6-Jun-10 8:07
borisdekat6-Jun-10 8:07 
AnswerRe: Using in seperate class ? Pin
Erik Haverkamp25-Mar-11 23:51
Erik Haverkamp25-Mar-11 23:51 
GeneralWindows 7 64-bit Pin
SamNasr6-May-10 4:39
SamNasr6-May-10 4:39 
GeneralRe: Windows 7 64-bit Pin
dvrotsos3-Sep-10 9:22
dvrotsos3-Sep-10 9:22 
GeneralRe: Windows 7 64-bit Pin
SamNasr3-Sep-10 9:48
SamNasr3-Sep-10 9:48 
GeneralRe: Windows 7 64-bit Pin
dvrotsos3-Sep-10 12:02
dvrotsos3-Sep-10 12:02 
GeneralRe: Windows 7 64-bit Pin
PhantomHawk30-Sep-10 6:43
PhantomHawk30-Sep-10 6:43 
GeneralRe: Windows 7 64-bit Pin
mikah trent17-May-11 4:57
mikah trent17-May-11 4:57 
GeneralRe: Windows 7 64-bit Pin
Member 1003725110-Feb-15 12:23
Member 1003725110-Feb-15 12:23 
GeneralRe: Windows 7 64-bit Pin
melntess8-Jul-11 11:11
melntess8-Jul-11 11:11 
QuestionSolution: Losing Input Reports? Pin
faav4-May-10 10:24
faav4-May-10 10:24 
GeneralI don't understand how to use the example project Pin
12313s4-May-10 8:05
12313s4-May-10 8:05 
Questionthere are a new version of it? Pin
hilbi8830-Apr-10 23:22
hilbi8830-Apr-10 23:22 
GeneralHappy but Perplexed Pin
gregmemphis20-Feb-10 21:15
gregmemphis20-Feb-10 21:15 
GeneralRe: Happy but Perplexed Pin
Hosenite19-Mar-10 9:53
Hosenite19-Mar-10 9:53 
GeneralRe: Happy but Perplexed [modified] Pin
aklein5315-Feb-11 11:48
aklein5315-Feb-11 11:48 
QuestionCapability Questions Pin
jschaenzle6-Feb-10 6:47
jschaenzle6-Feb-10 6:47 
GeneralMy vote of 1 Pin
Render_V1-Feb-10 19:42
Render_V1-Feb-10 19:42 
GeneralFailed to create handle when opening form again Pin
ric_vas11-Jan-10 10:57
ric_vas11-Jan-10 10:57 
GeneralRe: Failed to create handle when opening form again - update Pin
ric_vas12-Jan-10 6:50
ric_vas12-Jan-10 6:50 
GeneralWinEr: 00000005 Pin
cabron1238-Jan-10 5:36
cabron1238-Jan-10 5:36 
GeneralRe: WinEr: 00000005 Pin
Hosenite14-Jan-10 9:46
Hosenite14-Jan-10 9: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.