WinUsb HowTo program

Telechargé par registforum
How to Use WinUSB to
Communicate with a USB Device
March30,2009
Abstract
Independenthardwarevendors(IHVs)whomanufactureUSBdevicesmustoften
provideawayforapplicationstoaccessthedevice’sfeatures.Historically,thishas
meantusingtheWindows®DriverModel(WDM)toimplementafunctiondriverfor
thedeviceandinstallingthedriverinthedevicestackabovesystemsupplied
protocoldrivers.TheWindowsDriverFoundation(WDF)isnowthepreferredmodel
forUSBdrivers.ItprovidesIHVswiththreeoptionsforprovidingaccesstoaUSB
device:
ImplementingausermodedriverbyusingtheWDFusermodedriverframework
(UMDF).
ImplementingakernelmodedriverbyusingtheWDFkernelmodedriver
framework(KMDF).
InstallingWinUsb.sysasthedevice’sfunctiondriverandprovidinganapplication
thataccessesthedevicebyusingtheWinUSBAPI.
Thiswhitepaperprovidesguidelinesforwhentouseeachoptionandincludesa
detailedwalkthroughofhowtoinstallWinUsb.sysasadevice’sfunctiondriverand
usetheWinUSBAPItocommunicatewiththedevice.
Thisinformationappliesforthefollowingoperatingsystems:
Windows7
WindowsServer®2008
WindowsVista®
WindowsXP
Referencesandresourcesdiscussedherearelistedattheendofthispaper.
Forthelatestinformation,see:
http://www.microsoft.com/whdc/connect/usb/winusb_howto.mspx
HowtoUseWinUSBtoCommunicatewithaUSBDevice‐2
March30,2009
©2009MicrosoftCorporation.Allrightsreserved.
Disclaimer: This is a preliminary document and may be changed substantially prior to final commercial
release of the software described herein.
The information contained in this document represents the current view of Microsoft Corporation on the
issues discussed as of the date of publication. Because Microsoft must respond to changing market
conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot
guarantee the accuracy of any information presented after the date of publication.
This White Paper is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS,
IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS DOCUMENT.
Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under
copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or
transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or
for any purpose, without the express written permission of Microsoft Corporation.
Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights
covering subject matter in this document. Except as expressly provided in any written license agreement
from Microsoft, the furnishing of this document does not give you any license to these patents, trademarks,
copyrights, or other intellectual property.
Unless otherwise noted, the example companies, organizations, products, domain names, e-mail addresses,
logos, people, places and events depicted herein are fictitious, and no association with any real company,
organization, product, domain name, email address, logo, person, place or event is intended or should be
inferred.
© 2009 Microsoft Corporation. All rights reserved.
Microsoft, MSDN, Windows, Windows Server, and Windows Vista are either registered trademarks or
trademarks of Microsoft Corporation in the United States and/or other countries.
The names of actual companies and products mentioned herein may be the trademarks of their respective
owners.
Revision History
DateChange
March30,2009 Addedadditionalinformationforcommunicatingwithendpoints.
December6,2007 AddedasectiononDFUtotheWinUSBFAQ.
RemovedthenotefromTable1indicatingthatWinUSBdoesnotsupport
WinUSBselectivesuspendonWindowsXP.
August30,2007Created
HowtoUseWinUSBtoCommunicatewithaUSBDevice‐3
March30,2009
©2009MicrosoftCorporation.Allrightsreserved.
Contents
Introduction ................................................................................................................... 4
SummaryofWinUSB,UMDF,andKMDFCapabilities.................................................... 5
GuidelinesforProvidingAccesstoUSBDevices ............................................................ 6
IntroductiontoWinUSB ................................................................................................. 6
WinUSBFAQ................................................................................................................... 7
HowtoInstallWinUsb.sysasaFunctionDriver............................................................. 8
HowtoUsetheWinUSBAPI ........................................................................................ 12
ObtainaHandletotheDeviceandInitializeWinUSB ............................................. 12
ObtaintheDevicePath........................................................................................ 13
ObtainaFileHandlefortheDevice..................................................................... 15
InitializeWinUSB ................................................................................................. 15
ConfiguretheDevice................................................................................................ 15
CommunicatewithEndpoints.................................................................................. 17
ControlRequests ................................................................................................. 17
WinUSBI/ORequests .......................................................................................... 19
WinUSBWriteRequests ...................................................................................... 19
DefaultWinUSBWriteBehavior.......................................................................... 20
WinUSBReadRequests ....................................................................................... 20
DefaultWinUSBReadBehavior........................................................................... 20
PipePolicies......................................................................................................... 21
WinUSBPowerManagement.............................................................................. 23
SelectiveSuspend ................................................................................................ 23
DetectingIdle ...................................................................................................... 24
FutureFeatureConsiderations .................................................................................... 24
Summary ...................................................................................................................... 24
Resources ..................................................................................................................... 24
HowtoUseWinUSBtoCommunicatewithaUSBDevice‐4
March30,2009
©2009MicrosoftCorporation.Allrightsreserved.
Introduction
Independenthardwarevendors(IHVs)whomanufactureUSBdevicesmusttypically
provideawayforapplicationstoaccessthedevice’sfeatures.Historically,thishas
meantusingtheWindows®DriverModel(WDM)toimplementafunctiondriverfor
thedeviceandinstallingthedriverinthedevicestackabovesystemsupplied
protocoldriverssuchasUsbhub.sysorUsbccgp.sys.Thefunctiondriverexposesa
deviceinterfacethatapplicationsusetoobtainthedevice’sfilehandle.Theycanthen
usethehandletocommunicatewiththedriverbycallingWindowsAPIfunctionssuch
asReadFileandDeviceIoControl.
DriversarethemostflexiblewaytoprovideaccesstoaUSBdeviceandallowthe
devicetobeaccessedbyanyapplication,includingmultipleconcurrentapplications.
However,driversrequireasignificantdevelopmenteffort,andsomedevicesare
simpleenoughthattheydonotrequirethefullsupportofacustomfunctiondriver.
Forexample,devicessuchasmachinecontrollersordataloggersaretypically
accessedonlybyasingleapplicationthatwaswrittenspecificallyfortheassociated
device.Inthesecases,WinUSBprovidesasimpleralternativetoimplementinga
customUSBdriver.
WinUSBwasdevelopedconcurrentlywiththeWindowsDriverFoundation(WDF)and
isavailableforWindowsXPandlaterversionsofWindows.Itincludesakernelmode
driver,WinUsb.sys,whichisanintegralpartofWDFusermodedriverframework
(UMDF)supportforUSBdrivers.However,forUSBdevicesthatareaccessedbyonly
asingleapplication,vendorscanofteninstallWinUsb.sysastheirdevice’sfunction
driverinsteadofimplementingacustomdriver.Theapplicationcanthenconfigure
thedeviceandaccessitsendpointsbyusingtheWinUSBAPI.
ForthoseUSBdevicesthatrequirethefeaturesofacustomfunctiondriver,the
preferredapproachisWDF.TheWDFprogrammingmodelanddevicedriverinterface
(DDI)makesWDFUSBdriversmucheasiertoimplementthanequivalentWDM
drivers.YoucanimplementWDFUSBdriversineitherofthefollowingways:
Usetheusermodedriverframework(UMDF)toimplementusermodeUSB
driversformostUSBdevicesforWindowsXPandlater.
Usethekernelmodedriverframework(KMDF)toimplementkernelmodeUSB
driversforanyUSBdeviceforWindows2000andlater.
Thiswhitepaperdescribeshowtochoosethebestwaytoprovideapplicationswith
accesstoaUSBdeviceandanswerssomecommonquestionsaboutWinUSB.The
bulkofthepaperisadetailedwalkthrough—includingcodesamples—ofhowto
installWinUsb.sysasaUSBdevice’sfunctiondriverandhowtousetheWinUSBAPI
tocommunicatewiththedevicefromanapplication.
HowtoUseWinUSBtoCommunicatewithaUSBDevice‐5
March30,2009
©2009MicrosoftCorporation.Allrightsreserved.
TheexamplesinthispaperarebasedontheOSRUSBFX2LearningKitdevice,butyou
caneasilyextendtheprocedurestootherUSBdevices.Figure1isasimplified
diagramoftheFX2deviceandshowsitskeyfeatures.
USB
Socket
USB
Chip
Light Bar
Toggle Switches
LED Panel
Remote Wakeup
Switch
Figure 1. OSR USB FX2 Learning Kit device
Summary of WinUSB, UMDF, and KMDF Capabilities
Table1summarizesthecapabilitiesofWinUSB,UMDFUSBdrivers,andKMDFUSB
drivers.
Table1.WDFUSBFeatureSupport
RequirementsWinUSBUMDFKMDF
Supportsmultipleconcurrentapplications.NoYesYes
Isolatesdriveraddressspacefromapplicationaddressspace.NoYesNo
Supportsbulk,interrupt,andcontroltransfers.YesYesYes
Supportsisochronoustransfers.NoNoYes
Supportstheinstallationofkernelmodedriverssuchasfilter
driversabovetheUSBdriver.
NoNoYes
Supportsselectivesuspendandwait/wakeYesYesYes
Table2summarizeswhichWDFoptionsaresupportedbydifferentversionsof
Windows.
Table2.WDFUSBWindowsSupport
RequirementsWinUSBUMDFKMDF
WindowsVistaandlaterYes1Yes1Yes
WindowsServer2003NoNoYes
WindowsXPYes2Yes2Yes
Windows2000 NoNoYes3
Notes:
1WinUSBandUMDFaresupportedonlyonx86andx64versionsofWindows.
2WINUSBandUMDFaresupportedonWindowsXPwithservicepack2orlater.
3KMDFissupportedonWindows2000withServicePack4orlater.
1 / 25 100%

WinUsb HowTo program

Telechargé par registforum
La catégorie de ce document est-elle correcte?
Merci pour votre participation!

Faire une suggestion

Avez-vous trouvé des erreurs dans linterface ou les textes ? Ou savez-vous comment améliorer linterface utilisateur de StudyLib ? Nhésitez pas à envoyer vos suggestions. Cest très important pour nous !