Click here to Skip to main content
Click here to Skip to main content

A USB HID Component for C#

By , 22 Mar 2007
 

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
No Biography provided

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

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionLocking the USB Barcode Scanner InputmemberPasan Indeewara2-Jun-13 19:29 
QuestionUsbLibrary.UsbHidPortmemberkainraz27-May-13 7:57 
GeneralMy vote of 5memberWolf_124-Apr-13 19:50 
Questionuse your application can't send data to HID device,how to solve?memberxuyunhai16-Apr-13 21:58 
QuestionDoes anybody know how to disconnect from the SpecifiedDevice?memberMozgC20-Jan-13 3:39 
AnswerRe: Does anybody know how to disconnect from the SpecifiedDevice?membershowwei200410-Apr-13 18:45 
Questionproblem with reference in usb hid component for c hsrp . what is the possible solution of this kind of warning. plz helpmembersefat_23571121-Dec-12 9:52 
QuestionDataRecievedEventHandlermemberMember 967835411-Dec-12 22:33 
Questionmore than a device with same vid&pid?memberminkiaprof2-Nov-12 7:00 
QuestionC# - How to get the FriendlyName from USB Serial Port?membersilvio pontes29-Aug-12 18:24 
QuestionUse the component twicememberbeattiet999-Aug-12 17:57 
AnswerRe: Use the component twicememberbeattiet999-Aug-12 19:02 
QuestionI can not receive the responce from the devicememberMember 43415761-Jun-12 11:02 
GeneralRe: I can not receive the responce from the devicememberVladimir N.20-Jul-12 0:34 
GeneralRe: I can not receive the responce from the devicememberarpizt14-Aug-12 16:24 
I also facing the same issues. "OnDataRecieved" event not firing.
About the ReportID? How I can check it? Is it depends on data size the I scan?
GeneralRe: I can not receive the responce from the devicememberVladimir N.14-Aug-12 16:54 
QuestionWhy is myPSP_DEVICE_INTERFACE_DETAIL_DATA.cbSize set to 5 [modified]member__John_16-May-12 4:03 
Questionusing HID to invoke SendInput key press events [modified]membermurmand30-Apr-12 3:48 
AnswerRe: using HID to invoke SendInput key press eventsmemberVladimir N.8-Jul-12 22:08 
GeneralMy vote of 4memberamccombs14-Apr-12 2:57 
GeneralMy vote of 1memberClifford Nelson11-Apr-12 10:24 
GeneralRe: My vote of 1memberClifford Nelson14-Apr-12 11:41 
BugWindows 7. Failed to create device file WinEr:00000005memberMember 253745610-Apr-12 20:44 
GeneralRe: Windows 7. Failed to create device file WinEr:00000005memberJason Stern1-May-12 10:51 
GeneralRe: Windows 7. Failed to create device file WinEr:00000005memberGlen Harvy30-May-12 23:36 
GeneralRe: Windows 7. Failed to create device file WinEr:00000005memberDeveloperDotNet14-Aug-12 18:45 
GeneralRe: Windows 7. Failed to create device file WinEr:00000005memberGlen Harvy15-Aug-12 6:55 
Questionusing MDI Form...memberjuhwan7525-Mar-12 20:34 
QuestionChanges for Win7 64 bitmemberBernhard Hiller23-Mar-12 1:59 
AnswerRe: Changes for Win7 64 bitmembermohsen2536new28-Apr-12 22:44 
AnswerRe: Changes for Win7 64 bitmemberlipengutd24-Jul-12 3:03 
Questionyou are genius!memberjuhwan7522-Mar-12 21:05 
GeneralGreat lib!memberhawking11229-Feb-12 21:54 
QuestionDocumentation.chm file not viewablememberTerry Biberdorf3-Feb-12 9:44 
AnswerRe: Documentation.chm file not viewablememberdaveped18-Mar-12 3:33 
GeneralMy vote of 5memberMr-H 201024-Jan-12 11:54 
GeneralMy vote of 5memberSunCross5-Nov-11 8:45 
Questionusb problemmemberivanovici mihai5-Nov-11 0:15 
AnswerRe: usb problemmemberharpreet9016-Nov-11 19:55 
AnswerRe: usb problemmemberdaveped18-Mar-12 3:51 
QuestionHelp with the event implementationmemberEnie300015-Oct-11 3:14 
QuestionMissing Byte?memberPGP_Protector14-Oct-11 10:37 
QuestionWindows CEmemberFiendlive21-Sep-11 12:08 
QuestionThat't coolmemberwavelet120813-Sep-11 20:56 
QuestionObject reference not set to an object.memberMember 361864611-Sep-11 17:18 
QuestionDoes with this work with Visual Studio 2010memberMember 806060831-Aug-11 11:46 
AnswerRe: Does with this work with Visual Studio 2010memberGS-Scooter1-Sep-11 4:54 
GeneralRe: Does with this work with Visual Studio 2010 - (Don't send all zeros in record)memberMember 80606081-Sep-11 5:43 
GeneralRe: Does with this work with Visual Studio 2010 - (Don't send all zeros in record)memberGS-Scooter1-Sep-11 5:55 
QuestionVendor Name / Product Namememberuniqo814-Aug-11 20:43 

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

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