Click here to Skip to main content
15,898,134 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 2M   68.6K   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

 
QuestionUSB HID Pin
kingdom197713-Apr-07 2:45
kingdom197713-Apr-07 2:45 
AnswerRe: USB HID Pin
wimar15-Apr-07 21:41
wimar15-Apr-07 21:41 
GeneralRe: USB HID Pin
kinglaws16-Apr-07 7:12
kinglaws16-Apr-07 7:12 
GeneralRe: USB HID Pin
wimar17-Apr-07 7:52
wimar17-Apr-07 7:52 
GeneralRe: USB HID Pin
kinglaws17-Apr-07 8:39
kinglaws17-Apr-07 8:39 
GeneralRe: USB HID Pin
kinglaws19-Apr-07 13:24
kinglaws19-Apr-07 13:24 
GeneralRe: USB HID Pin
Iwan Budihalim16-Aug-07 2:21
Iwan Budihalim16-Aug-07 2:21 
QuestionDetecting a HID Device [modified] Pin
BalaVikram28-Mar-07 23:47
BalaVikram28-Mar-07 23:47 
Hi wimar.

I Have a card reader which is listed under the HID Devices in Windows device manager.
I need to detect from the application whether the device is found or not. I have the device ID and the Product ID. But the problem is I need to do this in Framework 1.1. Can you help me on this



Thanks in advance Rose | [Rose]


-- modified at 7:05 Thursday 29th March, 2007

B.BalaVikram.
KinGCobrA

AnswerRe: Detecting a HID Device Pin
wimar29-Mar-07 4:06
wimar29-Mar-07 4:06 
GeneralRe: Detecting a HID Device Pin
BalaVikram1-Apr-07 19:49
BalaVikram1-Apr-07 19:49 

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.