5,138,728 members and growing! (16,247 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

An component to comunicate with a usb hid device
C# 2.0, C#Windows, .NET, .NET 2.0, WinXPVS2005, VS, Dev

Posted: 22 Mar 2007
Updated: 22 Mar 2007
Views: 124,040
Announcements



Search    
Advanced Search
Sitemap
14 votes for this Article.
Popularity: 4.27 Rating: 3.73 out of 5
2 votes, 14.3%
1
2 votes, 14.3%
2
0 votes, 0.0%
3
2 votes, 14.3%
4
8 votes, 57.1%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

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 aswell as the component itself.

Background

The component is based on various sources. A good start for USB in C# is the following website: http://www.vsj.co.uk/articles/display.asp?id=600. Also the book USB COMPLETE (third edition) by Jan Axelson is a must read for everyone wishing to incorperate USB HID into 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. Also 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

First version, currently in developement and updates will be posted if there is need for.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

wimar



Occupation: Web Developer
Location: Netherlands Netherlands

Other popular C# articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 52 (Total in Forum: 52) (Refresh)FirstPrevNext
Subject  Author Date 
GeneralHow to unregister HID devicememberabetrader7:40 15 Apr '08  
GeneralAdding to this component.memberBakaneko1:39 9 Apr '08  
GeneralFor people having problems with sending [modified]memberBakaneko13:09 8 Apr '08  
GeneralWPF ?memberLoic Berthollet7:12 1 Apr '08  
GeneralHelp 'hijacking' USB HID inputmemberDanny__T6:09 6 Feb '08  
GeneralRe: Help 'hijacking' USB HID inputmemberPete BSC12:30 6 Mar '08  
Generalthank you!!!memberGil.Schmidt0:38 26 Jan '08  
QuestionSending report to USB DevicememberMember 32434720:55 9 Jan '08  
QuestionHID devce not detectedmemberSamir Karve23:34 20 Nov '07  
GeneralSending Data with Sniffermemberdrdoc12313:41 13 Nov '07  
GeneralDoes not work on 64 bit Vista?memberGeorge Helyar15:32 5 Nov '07  
GeneralRe: Does not work on 64 bit Vista?memberGeorge Helyar4:49 7 Nov '07  
GeneralRe: Problems with 64-bit WindowsmemberRenniePet5:36 28 Apr '08  
GeneralRe: Problems with 64-bit WindowsmemberGeorge Helyar9:46 28 Apr '08  
GeneralRe: Problems with 64-bit WindowsmemberRenniePet10:32 28 Apr '08  
GeneralCan't find my usb flash drivemembereythimis6:09 15 Oct '07  
GeneralRe: Can't find my usb flash drivememberwimar8:18 22 Oct '07  
GeneralRe: Can't find my usb flash drivememberDoug Squires7:07 24 Oct '07  
GeneralGeneral USB data transfermemberRick818:54 24 Sep '07  
GeneralFindSpecifiedDevice ProblemmemberIwan Budihalim0:55 27 Aug '07  
GeneralRe: FindSpecifiedDevice ProblemmemberIwan Budihalim2:53 27 Aug '07  
GeneralRe: FindSpecifiedDevice Problemmembertaithien21:44 22 Jan '08  
GeneralRe: FindSpecifiedDevice Problemmembersbeaubien8:41 18 Mar '08  
GeneralHID Device NamememberIwan Budihalim3:48 16 Aug '07  
GeneralRe: HID Device Namememberwimar8:52 16 Aug '07  

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: Sean Ewington
Copyright 2007 by wimar
Everything else Copyright © CodeProject, 1999-2008
Web10 | Advertise on the Code Project