Click here to Skip to main content
15,867,835 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 1.9M   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

 
GeneralThis code recognized my device immediately Pin
Bill Ewing7-Nov-08 3:28
Bill Ewing7-Nov-08 3:28 
GeneralRe: not recognizing my usb product id and vendor id Pin
yesman14-Jul-09 20:18
yesman14-Jul-09 20:18 
AnswerRe: not recognizing my usb product id and vendor id Pin
sarunasg26-Nov-09 22:04
sarunasg26-Nov-09 22:04 
QuestionUSB-At89c5131 code Pin
Nycil29-Jul-08 21:06
Nycil29-Jul-08 21:06 
GeneralHelp on USB Barcode Scanner using as HID Device Pin
Kinuis2-Jul-08 2:55
Kinuis2-Jul-08 2:55 
GeneralRe: Help on USB Barcode Scanner using as HID Device Pin
Member 331961127-Aug-08 8:42
Member 331961127-Aug-08 8:42 
GeneralRe: Help on USB Barcode Scanner using as HID Device Pin
kevinjheng28-Aug-08 19:45
kevinjheng28-Aug-08 19:45 
GeneralRe: Help on USB Barcode Scanner using as HID Device Pin
PubLee14-Sep-08 3:29
PubLee14-Sep-08 3:29 
QuestionPausing Read From USB Pin
Noman Aftab30-Jun-08 2:49
Noman Aftab30-Jun-08 2:49 
AnswerRe: Pausing Read From USB Pin
sophtware25-Jul-08 16:49
sophtware25-Jul-08 16:49 
Questionhid lib and visual c++ ... howto? Pin
Sandro Cavazzoni5-Jun-08 0:20
Sandro Cavazzoni5-Jun-08 0:20 
AnswerRe: hid lib and visual c++ ... howto? Pin
Bill Ewing7-Nov-08 3:24
Bill Ewing7-Nov-08 3:24 
AnswerRe: hid lib and visual c++ ... howto? Pin
yesman27-Aug-09 4:42
yesman27-Aug-09 4:42 
AnswerThanks for the Great Article Pin
Tradon-Dev30-May-08 6:07
Tradon-Dev30-May-08 6:07 
QuestionHow to unregister HID device Pin
abetrader15-Apr-08 6:40
abetrader15-Apr-08 6:40 
AnswerRe: How to unregister HID device Pin
nhustak17-Apr-09 4:54
nhustak17-Apr-09 4:54 
GeneralRe: How to unregister HID device Pin
ScruffR22-Jun-09 3:33
ScruffR22-Jun-09 3:33 
GeneralRe: How to unregister HID device [modified] Pin
MDeepa3-Jul-09 0:10
MDeepa3-Jul-09 0:10 
GeneralAdding to this component. Pin
Bakaneko9-Apr-08 0:39
Bakaneko9-Apr-08 0:39 
GeneralFor people having problems with sending [modified] Pin
Bakaneko8-Apr-08 12:09
Bakaneko8-Apr-08 12:09 
QuestionWPF ? Pin
Loic Berthollet1-Apr-08 6:12
Loic Berthollet1-Apr-08 6:12 
GeneralHelp 'hijacking' USB HID input Pin
Danny__T6-Feb-08 5:09
Danny__T6-Feb-08 5:09 
GeneralRe: Help 'hijacking' USB HID input Pin
Pete BSC6-Mar-08 11:30
Pete BSC6-Mar-08 11:30 
Generalthank you!!! Pin
Gil.Schmidt25-Jan-08 23:38
Gil.Schmidt25-Jan-08 23:38 
QuestionSending report to USB Device Pin
Member 32434728-Jan-08 23:55
Member 32434728-Jan-08 23:55 

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.