Click here to Skip to main content
Licence CPOL
First Posted 22 Mar 2007
Views 660,151
Downloads 12,579
Bookmarked 156 times

A USB HID Component for C#

By wimar | 22 Mar 2007
A component to communicate with a USB HID device
5 votes, 9.6%
1
3 votes, 5.8%
2
1 vote, 1.9%
3
7 votes, 13.5%
4
36 votes, 69.2%
5
4.58/5 - 52 votes
5 removed
μ 4.10, σa 2.34 [?]

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
QuestionDocumentation.chm file not viewable PinmemberTerry Biberdorf10:44 3 Feb '12  
GeneralMy vote of 5 PinmemberMr-H 201012:54 24 Jan '12  
GeneralMy vote of 5 PinmemberSunCross9:45 5 Nov '11  
Questionusb problem Pinmemberivanovici mihai1:15 5 Nov '11  
AnswerRe: usb problem Pinmemberharpreet9020:55 16 Nov '11  
QuestionHelp with the event implementation PinmemberEnie30004:14 15 Oct '11  
QuestionMissing Byte? PinmemberPGP_Protector11:37 14 Oct '11  
QuestionWindows CE PinmemberFiendlive13:08 21 Sep '11  
QuestionThat't cool Pinmemberwavelet120821:56 13 Sep '11  
QuestionObject reference not set to an object. PinmemberMember 361864618:18 11 Sep '11  
QuestionDoes with this work with Visual Studio 2010 PinmemberMember 806060812:46 31 Aug '11  
AnswerRe: Does with this work with Visual Studio 2010 PinmemberGS-Scooter5:54 1 Sep '11  
GeneralRe: Does with this work with Visual Studio 2010 - (Don't send all zeros in record) PinmemberMember 80606086:43 1 Sep '11  
GeneralRe: Does with this work with Visual Studio 2010 - (Don't send all zeros in record) PinmemberGS-Scooter6:55 1 Sep '11  
QuestionVendor Name / Product Name Pinmemberuniqo8121:43 4 Aug '11  
AnswerRe: Vendor Name / Product Name Pinmemberuniqo819:20 8 Aug '11  
GeneralRe: Vendor Name / Product Name Pinmemberivanovici mihai1:17 5 Nov '11  
QuestionCreateFile returns -1 (Failed to create device file WinEr:00000005) Pinmemberblackbondi3:00 30 Jul '11  
AnswerRe: CreateFile returns -1 (Failed to create device file WinEr:00000005) Pinmemberyosmany6:58 2 Sep '11  
QuestionUsbHidPort1.SpecifiedDevice.Dispose() PinmemberTony Palumbo15:24 10 Jul '11  
QuestionI'm wanting to communicate with my Tripp Lite UPS via USB - but it's already opened. Pinmembermyklk9:10 10 Jun '11  
QuestionRe: I'm wanting to communicate with my Tripp Lite UPS via USB - but it's already opened. Pinmembermhandzlik6:26 7 Nov '11  
Questionit will always return null and it won't select any device... PinmemberMEhran.NET1:31 17 May '11  
AnswerRe: it will always return null and it won't select any device... Pinmembermikah trent6:06 17 May '11  
GeneralRe: it will always return null and it won't select any device... [modified] PinmemberMEhran.NET1:12 18 May '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
Web04 | 2.5.120206.1 | Last Updated 22 Mar 2007
Article Copyright 2007 by wimar
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid