Click here to Skip to main content
6,594,088 members and growing! (16,104 online)
Email Password   helpLost your password?
Languages » C# » General     Intermediate License: The Code Project Open License (CPOL)

A USB HID Component for C#

By wimar

A component to communicate with a USB HID device
C# 2.0.NET 2.0, WinXPVS2005, Dev
Posted:22 Mar 2007
Views:235,252
Bookmarked:89 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
28 votes for this article.
Popularity: 5.53 Rating: 3.82 out of 5
4 votes, 14.3%
1
3 votes, 10.7%
2
1 vote, 3.6%
3
4 votes, 14.3%
4
16 votes, 57.1%
5

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


Member

Occupation: Web Developer
Location: Netherlands Netherlands

Other popular C# articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 156 (Total in Forum: 156) (Refresh)FirstPrevNext
GeneralI can not receive data from device :( Pinmemberhande5410:32 8 Oct '09  
GeneralGot ERROR_NO_TOKEN ( 1008) when CreateFile PinmemberNam Tu5:12 7 Oct '09  
GeneralRe: Got ERROR_NO_TOKEN ( 1008) when CreateFile PinmemberNam Tu1:34 8 Oct '09  
GeneralDoes this work in Windows 2000? Pinmembermelntess10:45 6 Oct '09  
GeneralIs it possible? Pinmemberrice-_-16:49 9 Sep '09  
Generalproblem with USBlyzer PinmemberMember 391114021:57 8 Sep '09  
GeneralHow to get the friendly name of HID device? PinmemberWuRichard9:20 27 Aug '09  
GeneralRe: How to get the friendly name of HID device? [modified] Pinmemberyesman18:36 30 Aug '09  
GeneralRe: How to get the friendly name of HID device? PinmemberWuRichard6:22 1 Sep '09  
GeneralRe: How to get the friendly name of HID device? Pinmemberrice-_-0:51 9 Sep '09  
Questionreceive data doesn't fire Pinmembertolgakayahan0:10 25 Aug '09  
AnswerRe: receive data doesn't fire Pinmembertolgakayahan2:18 26 Aug '09  
GeneralRe: receive data doesn't fire Pinmembertolgakayahan13:40 2 Sep '09  
GeneralRe: receive data doesn't fire PinmemberMember 5600194:14 4 Sep '09  
GeneralRe: receive data doesn't fire Pinmembertolgakayahan6:51 13 Sep '09  
GeneralRe: receive data doesn't fire Pinmemberyahaiyakhan2:25 29 Sep '09  
GeneralRe: receive data doesn't fire Pinmemberhande5410:21 8 Oct '09  
GeneralRe: receive data doesn't fire Pinmemberbecktoan18:11 31 Oct '09  
GeneralRe: receive data doesn't fire Pinmemberbecktoan18:17 31 Oct '09  
GeneralYou Rock My Face Pinmemberblackey0216:55 4 Aug '09  
GeneralAwesome! Thanks :) Pinmemberintelomkar8:02 25 Jul '09  
QuestionUSB Polling Time - USB HUB Pinmemberbublabla21:33 20 Jul '09  
GeneralMy vote of 2 Pinmemberjasona226:21 18 Jun '09  
JokeDoesn't work on 64 bit Vista. Pinmembermelntess11:14 28 May '09  
GeneralRe: Doesn't work on 64 bit Vista. Pinmembermelntess13:25 28 May '09  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 22 Mar 2007
Editor: Deeksha Shenoy
Copyright 2007 by wimar
Everything else Copyright © CodeProject, 1999-2009
Web15 | Advertise on the Code Project