windows驱动开发(四)WDK源码UsbSamp例⼦的编译及使
⽤
英语短文带翻译欢迎⼤家提出意见,⼀起讨论!
需要源码的请独与我联系.
⼀、例⼦介绍
UsbSamp是你安装完WinDDK后⾃带的⼀个USB例⼦,在D:\WINDDK\7600.16385.1\src\usb\usbsamp下.
演⽰了如何通过WDF将⼤量及等时的数据传送到⼀个通⽤的USB设备。
此例⼦是针对Intel 82930 USB测试板。它包含⼀个控制台的应⽤程序来初始化
传送并获得在设备的I/O endpoints上的信息。它也演⽰了如果⽤基于GUID的设备名和
pips名。
⼆、编译例⼦:
whereareyou
1、usbsamp_new.SYS⽂件的编译
删除新建时产⽣的⽂件,然后把D:\WINDDK\7600.16385.1\src\usb\usbsamp\sys下的.c .h .rc⽂件拷到我们的⼯程⽬录下,编组成⼯程:sources内容如下:
这⾥不得不提⼀下编译出错:
如果⼤家把此错误在⽹上搜索,⼀般都没有⼈解答。
解决⽅法是在sources ⾥添加以下选项:
KMDF_VERSION_MAJOR=1
MSC_WARNING_LEVEL=/W4 /WX
==================================================================================================
编译产⽣了我们想要的sys ⽂件
1>1>e:\g2\fft\usbdri~1\usbsam~1\usbsam~1\bulkrwr.obj : error LNK2019: unresolved external symbol _WdfDriverGlobals referenced in func 13. 1>1>e:\g2\fft\usbdri~1\usbsam~1\usbsam~1\objchk_win7_x86\i386\usbsamp_new.sys : error LNK1120: 2 unresolved externals
2、⽂件的编译
新建⼀个DDK Project⼯程,模板选择Native Application
jamy把D:\WINDDK\7600.16385.1\src\usb\usbsamp\exe下的testapp.c与组织进⼯程
sources内容为:
33.
编译后得到
三、安装驱动
确保你已经有.inf⽂件,且⽂件中有相关设备的VID/PID、描述text。如果没有⾃⼰编辑。
这⾥我⽤系统⾃带的GenInf⼯具来产⽣.inf⽂件.
⾃动产⽣usbsamp.inf⽂件后右击选择安装即可。
On Windows XP and later:
azu1. "Found New Hardware Wizard" dialog box will appear. Here lect the radio button labeled "Install from a list of specific location
(Advanced)" and then hit the "Next" button.
2. In the following screen lect the radio button labeled " Search the best driver in the locations" and then lect "Include this
location in the arch path" and specify the target media or the directory where the INF and SYS files are copied and then hit the "Next" button.
3. The system will scan the directory and pick up the matching INF and start the installation. You will get a Hardware Installation
Warning dialog stating that your driver has not pasd Windows Logo Testing. Hit "Continue Anyway" button.
4. The system will copy the KMDF coinstaller (wdfcoinstallerMMmmm.dll), driver, INF file, load the driver and start the device. If every
thing goes fine, you will get "Completing the Found New Hardware Wizard". Hit the "Finish" button and the installation is complete.
5. You should be able to e the device in the Device manager under "Universal Serial Bus controllers"
Testing
company的复数You can to test the device. This console application enumerates the interface registered by the driver and opens the device to nd read, write or ioctl requests bad on the command line options.
< -u <-- Will dump all the descriptors and endpoint information.
< -r 1024 -w 1024 -c 100 -v <-- This command first writes 1024 bytes of data to bulk out endpoint (pipe1), and then reads 1024 bytes from bulk in endpoint (pipe1), and compares the read buffer with write buffer to e if they match. If the buffer contents match, it performs this operation 100 times.
To read and write to bulk endpoints you can run one or more of the commands simultaneously. The driver is multi-thread safe so it can handle multiple request at a time.
< -r 65536 <--- by default, the device reads pipe0
< -w 65536 <--- by default, the device write to pipe1
< -r 65536 -i pipe02 <--- read 65536 bytes from pipe02
< -w 65536 -o pipe03 <--- write 65536 bytes to pipe03
To read and write to Isochronous endpoints you can run one or more of the commands simultaneously.
< -r 510 -i pipe04
< -w 510 -o pipe05
管子英文< -w 10245 -o pipe05 -r 1024 -i pipe04 -c 100 -v怎么学好日常英语口语
ufc是什么意思啊扩展阅读
INF⽂件全称Information File⽂件,是Winodws操作系统下⽤来描述设备或⽂件等数据信息的⽂件。INF⽂件是由标准的ASCII码组成,您可以⽤任何⼀款⽂字编辑器查看修改其中的内容。⼀般我们总是认为INF⽂件是系统设备的驱动程序,其实这是错误的认识,Windows之所以在安装某些硬件的驱动
时提⽰需要INF⽂件是因为INF⽂件为该设备提供了⼀个全⾯描述硬件参数和相应驱动⽂件(DLL⽂件)的信息。就好⽐我们看着说明书安装电脑硬件⼀样,我们就是Windows系统,说明书就是INF⽂件。INF⽂件功能⾮常强⼤,⼏乎能完成⽇常操作的所有功能。您可以把它看成是Windows系统底下的超强批初理。要熟练掌握和理解甚⾄是编写INF⽂件需要对其内部结构有相当的认识。下⾯就让我们来深⼊到INF⽂件中的内部⼀窥其真⾯貌吧!
INF⽂件的组成有节(Sections),键(Key)和值(value)三部分。
关键节有
[Version]版本描述信息,主要⽤于版本控制。
[Strings]字符串信息,⽤于常量定义。
[DestinationDirs]定义系统路径信息。
[SourceDisksNames]指明源盘信息。
[SourceDisksNames]指明源盘⽂件名。
[DefaultInstall]开始执⾏安装。
其它的节可以⾃定义,下⾯⽤⼀实例来具体讲解。
程序代码
[Version]
Signature=$Chicago$
Provider=%Author%
[Strings]
Product="添加⽂件关联演⽰"
Version="1.0"
Author="Xunchi"
Copyright="Copyright 2005"
CustomFile="inf" ;修改您需要的⽂件名后缀
Program="NOTEPAD.EXE" ;修改您需要关联的应⽤程序名
[Add.Reg]
HKCR,"."%CustomFile%,"",FLG_ADDREG_TYPE_SZ ,%CustomFile%File专业职务
HKCR,%CustomFile%File,"",FLG_ADDREG_TYPE_SZ,安装信息
HKCR,%CustomFile%"File\shell","",FLG_ADDREG_TYPE_SZ,open
HKCR,%CustomFile%"File\shell\open\command","",FLG_ADDREG_TYPE_SZ,%program% %1
[DefaultInstall]
AddReg=Add.Reg
在[Version]节中"Signature"项定义了该INF⽂件需要运⾏在何种操作系统版本中。有$Windows NT$, $Chicago$, or $Windows 95$三个值供选择,⼀般选择$Chicago$即可。项Provider中定义了该⽂件的创作来源,%Author%指引⽤Author项的值。您也可⾃定其它项来描述该INF⽂件的版本信息。该INF⽂件的作⽤是关联⽂件,所以主要是对注册表的操作,我们来看[Add.Reg]节,共四条语句,格式
都是⼀样。HKCR表⽰根HKEY_CLASSES_ROOT,第⼆个参数是⼦键的路径名,第三个参数是表明值的类型,最后是值(具体见附表)。以上都是对操作的定义与过程,在节[DefaultInstall]中是开始执⾏要安装的流程,AddReg表明是对注册表进⾏操作,操作对象是Add.Reg节中的定义。如果您把AddReg换成DelReg则是删除注册表中的键值。当⿏标单击该INF⽂件在弹出的菜单中选择“安装”就开始执⾏您所定义的操作。该⽰例在系统的INF⽂件右键菜单中增加了查看编辑功能并设置了默认动作,因为在安装了不了解的INF⽂件有可能对系统产⽣不良的影响,这样双击⽂件就可打开编辑该⽂件了。
再看看INF⽂件在⽂件操作⽅⾯的能⼒吧。请看下⾯的⼀个例⼦。
程序代码
[Version]
Signature=$Chicago$
Provider=%Author%
[Strings]
Product="⽂件复制和安装演⽰"
Version="1.0"
Author="Xunchi"
Copyright="Copyright 2005"
[FileList]
< ;此⽂件已在当前⽬录下,下同。
[FileList1]
<frostbite
[DestinationDirs]
FileList=11 ;安装到Windows的系统⽬录
FileList1=10 ;安装到Windows⽬录
[DefaultInstall]
Copyfiles=FileList,FileList1