Click here to Skip to main content
6,822,613 members and growing! (16,433 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.NET2.0, WinXPVS2005, Dev
Posted:22 Mar 2007
Views:259,179
Bookmarked:95 times
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
29 votes for this article.
Popularity: 5.52 Rating: 3.77 out of 5
5 votes, 17.2%
1
3 votes, 10.3%
2
1 vote, 3.4%
3
4 votes, 13.8%
4
16 votes, 55.2%
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 178 (Total in Forum: 178) (Refresh)FirstPrevNext
QuestionCapability Questions Pinmemberjschaenzle7:47 6 Feb '10  
GeneralMy vote of 1 PinmemberRender_V20:42 1 Feb '10  
GeneralFailed to create handle when opening form again Pinmemberric_vas11:57 11 Jan '10  
GeneralRe: Failed to create handle when opening form again - update Pinmemberric_vas7:50 12 Jan '10  
GeneralWinEr: 00000005 Pinmembercabron1236:36 8 Jan '10  
GeneralRe: WinEr: 00000005 PinmemberHosenite10:46 14 Jan '10  
Generalvb.net code Pinmemberste19907:25 21 Dec '09  
GeneralRe: vb.net code Pinmembersnuffybox23:09 24 Dec '09  
GeneralUSBhidport PinmemberJ imran19:32 5 Dec '09  
Generalcan I control the power line of usb port PinmemberJ imran17:59 5 Dec '09  
QuestionIDs Pinmembernarutonaf17:00 12 Nov '09  
AnswerRe: IDs Pinmembernarutonaf18:29 13 Nov '09  
GeneralI can not receive data from device :( Pinmemberhande5410:32 8 Oct '09  
GeneralRe: I can not receive data from device :( Pinmembernarutonaf11:09 18 Nov '09  
GeneralRe: I can not receive data from device :( Pinmemberhande549:50 24 Nov '09  
GeneralRe: I can not receive data from device :( Pinmembernarutonaf10:43 24 Nov '09  
GeneralRe: I can not receive data from device :( Pinmemberhande5411:44 24 Nov '09  
GeneralRe: I can not receive data from device :( Pinmembernarutonaf7:49 25 Nov '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  
GeneralRe: Got ERROR_NO_TOKEN ( 1008) when CreateFile Pinmemberijingle14:25 14 Nov '09  
GeneralDoes this work in Windows 2000? Pinmembermelntess10:45 6 Oct '09  
GeneralRe: Does this work in Windows 2000? PinmemberJ imran17:30 5 Dec '09  
GeneralIs it possible? Pinmemberrice-_-16:49 9 Sep '09  
Generalproblem with USBlyzer PinmemberMember 391114021:57 8 Sep '09  

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads.

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