Click here to Skip to main content
Licence CPOL
First Posted 22 Mar 2007
Views 721,831
Downloads 16,037
Bookmarked 159 times

A USB HID Component for C#

By | 22 Mar 2007 | Article
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.

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

Web Developer

Netherlands Netherlands

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionWhy is myPSP_DEVICE_INTERFACE_DETAIL_DATA.cbSize set to 5 [modified] Pinmember__John_4:03 16 May '12  
Questionusing HID to invoke SendInput key press events [modified] Pinmembermurmand3:48 30 Apr '12  
GeneralMy vote of 4 Pinmemberamccombs2:57 14 Apr '12  
GeneralMy vote of 1 PinmemberClifford Nelson10:24 11 Apr '12  
GeneralRe: My vote of 1 PinmemberClifford Nelson11:41 14 Apr '12  
BugWindows 7. Failed to create device file WinEr:00000005 PinmemberMember 253745620:44 10 Apr '12  
GeneralRe: Windows 7. Failed to create device file WinEr:00000005 PinmemberJason Stern10:51 1 May '12  
Questionusing MDI Form... Pinmemberjuhwan7520:34 25 Mar '12  
QuestionChanges for Win7 64 bit PinmemberBernhard Hiller1:59 23 Mar '12  
AnswerRe: Changes for Win7 64 bit Pinmembermohsen2536new22:44 28 Apr '12  
Questionyou are genius! Pinmemberjuhwan7521:05 22 Mar '12  
GeneralGreat lib! Pinmemberhawking112221:54 9 Feb '12  
QuestionDocumentation.chm file not viewable PinmemberTerry Biberdorf9:44 3 Feb '12  
AnswerRe: Documentation.chm file not viewable Pinmemberdaveped3:33 18 Mar '12  
GeneralMy vote of 5 PinmemberMr-H 201011:54 24 Jan '12  
GeneralMy vote of 5 PinmemberSunCross8:45 5 Nov '11  
Questionusb problem Pinmemberivanovici mihai0:15 5 Nov '11  
AnswerRe: usb problem Pinmemberharpreet9019:55 16 Nov '11  
AnswerRe: usb problem Pinmemberdaveped3:51 18 Mar '12  
QuestionHelp with the event implementation PinmemberEnie30003:14 15 Oct '11  
QuestionMissing Byte? PinmemberPGP_Protector10:37 14 Oct '11  
QuestionWindows CE PinmemberFiendlive12:08 21 Sep '11  
QuestionThat't cool Pinmemberwavelet120820:56 13 Sep '11  
QuestionObject reference not set to an object. PinmemberMember 361864617:18 11 Sep '11  
QuestionDoes with this work with Visual Studio 2010 PinmemberMember 806060811:46 31 Aug '11  

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

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

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 22 Mar 2007
Article Copyright 2007 by wimar
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid