Click here to Skip to main content
6,295,667 members and growing! (14,694 online)
Email Password   helpLost your password?
Languages » C# » General     Intermediate License: The Code Project Open License (CPOL)

A USB HID Component for C#

By wimar

A component to communicate with a USB HID device
C# 2.0.NET 2.0, WinXPVS2005, Dev
Posted:22 Mar 2007
Views:201,885
Bookmarked:78 times
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
25 votes for this article.
Popularity: 5.28 Rating: 3.77 out of 5
4 votes, 16.0%
1
3 votes, 12.0%
2
1 vote, 4.0%
3
3 votes, 12.0%
4
14 votes, 56.0%
5

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.

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)

About the Author

wimar


Member

Occupation: Web Developer
Location: Netherlands Netherlands

Other popular C# articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 123 (Total in Forum: 123) (Refresh)FirstPrevNext
GeneralMy vote of 2 Pinmemberjasona226:21 18 Jun '09  
JokeDoesn't work on 64 bit Vista. Pinmembermelntess11:14 28 May '09  
GeneralRe: Doesn't work on 64 bit Vista. Pinmembermelntess13:25 28 May '09  
GeneralOMG. You are my savior. Pinmembermelntess20:12 27 May '09  
QuestionCloseHandle problem on Win XP SP3? PinmemberHenrik Danielsson9:52 9 May '09  
GeneralUSB HID with Windows Mobile 5.0 Pinmembermkohns13:38 26 Apr '09  
GeneralSourceForge Site Does Not Have Source Pinmembermike2orb13:30 14 Apr '09  
QuestionEndpoint number Pinmemberkaiwi6664:26 9 Apr '09  
GeneralNeed to develop a larger application using HID and USB , need contact Wimar PinmemberHoracio Duhart10:02 2 Apr '09  
GeneralOutput Report and Specifying Endpoints [modified] PinmemberChristopher Holland11:54 16 Mar '09  
GeneralRe: Output Report and Specifying Endpoints PinmemberChristopher Holland8:59 20 Mar '09  
GeneralRe: Output Report and Specifying Endpoints Pinmemberdberteanu5:20 3 Jun '09  
GeneralDebugging in VS C# 2008 Express PinmemberLarryRPark17:32 9 Mar '09  
Questioncan't it send data to printer? [modified] PinmemberBathildis Baek22:33 3 Mar '09  
AnswerRe: can't it send data to printer? Pinmembereeyrw9:51 19 Jun '09  
GeneralHow to get connected device info Pinmemberbarmagan3:16 26 Feb '09  
GeneralFeature Reports Pinmemberrnmisrahi11:43 22 Jan '09  
GeneralMultiple HID devices capturing before keystroke injection PinmemberGZ12345:55 20 Jan '09  
GeneralHow to disconnect a device ? Pinmembertahiticecil2:04 12 Jan '09  
GeneralRe: How to disconnect a device ? Pinmemberbarmagan3:01 26 Feb '09  
GeneralArray out of bound error Pinmemberharshanahnd16:51 6 Jan '09  
AnswerRe: Array out of bound error PinmemberYuriy Opryshko5:22 28 Jan '09  
GeneralUnable to receive data Pinmembernighteagle1:55 30 Dec '08  
GeneralRe: Unable to receive data PinmemberThe JZ8:57 31 Dec '08  
GeneralCan keyboard be captured? PinmemberBrianMarshall7:55 29 Dec '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 22 Mar 2007
Editor: Deeksha Shenoy
Copyright 2007 by wimar
Everything else Copyright © CodeProject, 1999-2009
Web13 | Advertise on the Code Project