阅读:2491回复:17
如何从USB设备读写bulk数据
小弟用USBVIEW读该USB设备的信息如下:
Device Descriptor: bcdUSB: 0x0110 bDeviceClass: 0xFF bDeviceSubClass: 0x01 bDeviceProtocol: 0x00 bMaxPacketSize0: 0x40 (64) idVendor: 0x066F idProduct: 0x4200 bcdDevice: 0x0008 iManufacturer: 0x01 iProduct: 0x02 iSerialNumber: 0x00 bNumConfigurations: 0x01 ConnectionStatus: DeviceConnected Current Config Value: 0x01 Device Bus Speed: Full Device Address: 0x02 Open Pipes: 2 Endpoint Descriptor: bEndpointAddress: 0x01 Transfer Type: Bulk wMaxPacketSize: 0x0040 (64) bInterval: 0x00 Endpoint Descriptor: bEndpointAddress: 0x82 Transfer Type: Bulk wMaxPacketSize: 0x0040 (64) bInterval: 0x00 已知: 一 ClassGUID = {6bdd1fc5-810f-11d0-BEC7-08002BE2092F} 二 %USB\\VID_066F&PID_4200.DeviceDesc%=STIrUsb.Dev,USB\\VID_066F&PID_4200 三 SymbolicName 应在注册表的哪个位置? [编辑 - 7/21/03 by huanghaiming] |
|
最新喜欢:![]() |
沙发#
发布于:2003-08-03 23:16
huanghaiming:
你好。看到你的贴子后,我还是不太明白。请教你 几个问题 1 你是在调试usb驱动程序吧。 2 能讲讲你的正确开发流程及注意事项吗。 3 打开设备通过GUID。为什么有的inf里没有这个。 4 能讲讲数据在驱动程序里是如何流通的吗。有流程图最好。 问的很多。不好意思。 不在郁闷中成长,就在郁闷中毁灭!!! |
|
板凳#
发布于:2003-07-28 19:23
jinghuiren 兄:
我添加了新硬件“其它设备”,根据usbex3.inf,装上了usbex3.sys后怎么就读不了设备传来的数据?手里又只有设备没有仿真器。用bushound 看确实有数据传送。 C:\\>test_usbex3 r 32 w 32 Test application Test_usbex3 starting... Device found, handle open. Reading from device - 0 bytes read from device (32 requested). ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Writing to device - 0 bytes written to device (32 attempted). g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a, b, c, d, e, f, g, h, i, j, k, l, |
|
地板#
发布于:2003-07-22 10:30
呵呵,又学到了一招! :D
|
|
地下室#
发布于:2003-07-21 16:07
太粗心了,我可以打开usb设备的句柄了,谢谢!
[编辑 - 7/21/03 by huanghaiming] |
|
5楼#
发布于:2003-07-21 16:01
是在localmechain下面,不是currendconfig
|
|
6楼#
发布于:2003-07-21 15:42
joyup!你瞧。
|
|
7楼#
发布于:2003-07-21 15:39
你好,joyup!
但我的注册表里怎么就没有象你那样的symblicname,我只有这个设备的inf和sys文件。 |
|
8楼#
发布于:2003-07-21 15:38
没关系
|
|
9楼#
发布于:2003-07-21 15:32
正是,谢谢joyup,我没有发过什么帖了,事先就给分了,所以没法给joyup和jinghuiren分,不好意思!!
|
|
10楼#
发布于:2003-07-21 15:27
不知道这个是不是你想要的
|
|
11楼#
发布于:2003-07-21 15:26
#define Usbex2Device_CLASS_GUID \\ jinghuiren你好! (它)Usbex2Device_CLASS_GUID 是我定义的, 这个是不是就是.inf的ClassGUID [Version] Signature = \"$Windows NT$\" Class = Infrared provider = %ST% ClassGUID = {6bdd1fc5-810f-11d0-BEC7-08002BE2092F} DriverVer = 07/02/2001,1.24.0.0 CatalogFile = stirusb.cat 只有inf和sys文件,我如何在应用程序查寻guid或设备名称 |
|
12楼#
发布于:2003-07-21 15:13
下面是别人提供的一个简单例程,我没有验证过,但你可以作为参考
/* USB_Createfile :打开一个设备接口文件 pGuid: 指向设备接口标识Guid InterfaceIndex: 设备接口号 Example: HANDLE hUsb1 = USB_Createfile((LPGUID)&USB1_GUID,0); */ HANDLE USB_Createfile( GUID* pGuid, DWORD InterfaceIndex) { // Get handle to relevant device information set HDEVINFO info = SetupDiGetClassDevs(pGuid, NULL, NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE); if(info==INVALID_HANDLE_VALUE) { return NULL; } // Get interface data for the requested MemberIndex SP_INTERFACE_DEVICE_DATA ifdata; ifdata.cbSize = sizeof(ifdata); if(!SetupDiEnumDeviceInterfaces(info, NULL, pGuid, InterfaceIndex, &ifdata)) { SetupDiDestroyDeviceInfoList(info); return NULL; } // Get size of symbolic link name DWORD ReqLen; SetupDiGetDeviceInterfaceDetail(info, &ifdata, NULL, 0, &ReqLen, NULL); PSP_INTERFACE_DEVICE_DETAIL_DATA ifDetail = (PSP_INTERFACE_DEVICE_DETAIL_DATA)(new char[ReqLen]); if( ifDetail==NULL) { SetupDiDestroyDeviceInfoList(info); return NULL; } // Get symbolic link name ifDetail->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA); if( !SetupDiGetDeviceInterfaceDetail(info, &ifdata, ifDetail, ReqLen, NULL, NULL)) { SetupDiDestroyDeviceInfoList(info); delete ifDetail; return NULL; } // Open file HANDLE pDevicefile = CreateFile( ifDetail->DevicePath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if( pDevicefile==INVALID_HANDLE_VALUE) pDevicefile = NULL; delete ifDetail; SetupDiDestroyDeviceInfoList(info); return pDevicefile; } |
|
13楼#
发布于:2003-07-21 15:09
#define Usbex2Device_CLASS_GUID \\
{ 0x6bdd1fc5, 0x810f, 0x11d0, { 0xbe, 0xc7, 0x08, 0x00, 0x2b, 0xe2, 0x09, 0x2f } } 上面这个好像是你设备的guid,根据这个guid用楼上那击个SetupDixxx就能得到设备的SymbolicName,然后用它可以打开设备的句柄 |
|
14楼#
发布于:2003-07-21 13:17
谢谢!我没有源码,只有inf和sys文件,我如何在应用程序查寻guid或设备名称,我不知道怎么下手?
打开设备方法用符号链接和输出接口,后者有两个类是CDeviceInterface, 和 CdeviceInterfaceClass。 //请你有时间的话可以看我所附的测试源码。 HidD_GetHidGuid(&GUID); SetupDiGetClassDevs SetupDiEnumDeviceInterfaces SetupDiGetDeviceInterfaceDetail 能获得guid吗? [编辑 - 7/21/03 by huanghaiming] [编辑 - 7/21/03 by huanghaiming] |
|
|
15楼#
发布于:2003-07-21 13:05
你提供的资料还是不行
如果你有驱动源代码的话可以到里面去找,或者是guid或者是设备名,这个guid不是classguid。 |
|
16楼#
发布于:2003-07-21 12:41
谢谢你的回答
Root Hub: USB#ROOT_HUB#4&249b90f2&0#{f18a0e88-c30c-11d0-8815-00a0c906bed8} Hub Power: Self Power Number of Ports: 2 Power switching: None Compound device: No No Over-current Protection (Bus Power Only) 设备名称是sigmatel usb-irda dongle .inf文件里的ClassGUID = {6bdd1fc5-810f-11d0-BEC7-08002BE2092F} 不是你指的guid吗 #define Usbex2Device_CLASS_GUID \\ { 0x6bdd1fc5, 0x810f, 0x11d0, { 0xbe, 0xc7, 0x08, 0x00, 0x2b, 0xe2, 0x09, 0x2f } } printf(\"Test application Test_usbex2 starting...\\n\"); hDevice = OpenByInterface( &ClassGuid, 0, &Error); if (hDevice == INVALID_HANDLE_VALUE) { printf(\"ERROR opening device: (%0x) returned from CreateFile\\n\", GetLastError()); Exit(1); } else { printf(\"Device found, handle open.\\n\"); } 程序运行结果: Test application Test_usbex2 starting... ERROR opening device: (0) returned from CreateFile Exiting... Press any key to continue [编辑 - 7/21/03 by huanghaiming] |
|
17楼#
发布于:2003-07-21 12:28
有classGUID不行的,你要么知道设备的guid,要吗知道设备的名字,比如“ Ezusb-0 ”什么的,否则无法打开设备的句柄的,因此也就无法读取数据。
|
|