tangyu20020202
驱动牛犊
驱动牛犊
  • 注册日期2005-03-06
  • 最后登录2005-06-02
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1673回复:1

这是一段显示USB设备信息的C++程序,请教大家

楼主#
更多 发布于:2005-04-22 23:07
这是一段显示USB设备信息的C++程序:
void CTestUSBDlg::ShowCenctInfo(PUSB_NODE_CONNECTION_INFORMATION connectionInfo)
{
ShowMessage(strShow);
strShow.Format(\"Connect index:[port:%d]\\r\\n\",
connectionInfo->ConnectionIndex);
ShowMessage(strShow);
strShow.Format(\"Device Class:0x%X\\r\\n
VenderID:0x%X\\r\\n
ProductID:0x%X\\r\\n\",
connectionInfo->DeviceDescriptor.bDeviceClass,
connectionInfo->DeviceDescriptor.idVendor,
connectionInfo->DeviceDescriptor.idProduct);
ShowMessage(strShow);
strShow.Format(\"iManufacturer:0x%X\\r\\n
iSerialNumber:0x%X\\r\\n\",
connectionInfo->DeviceDescriptor.iManufacturer,
connectionInfo->DeviceDescriptor.iSerialNumber);
ShowMessage(strShow);
if(connectionInfo->LowSpeed)
strShow=\"Bus Speed: low\\r\\n\";
else
strShow=\"Bus Speed: full\\r\\n\";
ShowMessage(strShow);
strShow.Format(\"Device Address:0x%X\\r\\n
Open Pipes:0x%X\\r\\n\",
connectionInfo->DeviceAddress,
connectionInfo->NumberOfOpenPipes);
ShowMessage(strShow);

}
其中函数的变量connectionInfo,PUSB_NODE_CONNECTION_INFORMATION这个类是在usbioctl.h里定义的,原文如下:
typedef struct _USB_NODE_CONNECTION_INFORMATION {
ULONG ConnectionIndex;
/* usb device descriptor returned by this device during enumeration */
USB_DEVICE_DESCRIPTOR DeviceDescriptor;
UCHAR CurrentConfigurationValue;
BOOLEAN LowSpeed;
BOOLEAN DeviceIsHub;
USHORT DeviceAddress;
ULONG NumberOfOpenPipes;
USB_CONNECTION_STATUS ConnectionStatus;
USB_PIPE_INFO PipeList[0];
} USB_NODE_CONNECTION_INFORMATION, *PUSB_NODE_CONNECTION_INFORMATION;

USB_NODE_CONNECTION_INFORMATION中的USB_DEVICE_DESCRIPTOR是在usb100.h里定义的,原文如下:
typedef struct _USB_DEVICE_DESCRIPTOR {
UCHAR bLength;
UCHAR bDescriptorType;
USHORT bcdUSB;
UCHAR bDeviceClass;
UCHAR bDeviceSubClass;
UCHAR bDeviceProtocol;
UCHAR bMaxPacketSize0;
USHORT idVendor;
USHORT idProduct;
USHORT bcdDevice;
UCHAR iManufacturer;
UCHAR iProduct;
UCHAR iSerialNumber;
UCHAR bNumConfigurations;
} USB_DEVICE_DESCRIPTOR, *PUSB_DEVICE_DESCRIPTOR;

例如,插上USB设备后运行,最后在文本框里的显示结果是这样:
Connect index:[port:1]
Device Class:0x0
VenderID:0x6FF
ProductID:0x8000
iManufacturer:0x1
iSerialNumber:0x3
Bus Speed:full
Device Address:0x1
Open Pipes:0x2

我不懂的地方就是以上每项信息对应的变量的具体内容,为什么差不多都是16进制的1位数字呢?
这些数字具体代表什么意思呢?比如说Device Class:0x0代表什么类型的USB设备呢?iManufacturer:0x1代表哪个制造商呢?
我是想将USB设备信息显示出来,让一般人能看得懂,但这些16进制数代表的意思实在不知道,我没法去转化。
想请大家帮帮忙给我解释一下每一项信息的意思,或者分析一下上述2个类的每个变量的具体意义。非常感谢!
Descriptor
驱动牛犊
驱动牛犊
  • 注册日期2005-03-13
  • 最后登录2006-01-19
  • 粉丝0
  • 关注0
  • 积分2分
  • 威望1点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2005-04-23 16:00
建议你先看一下USB规范,尤其是描述符(Descriptor),可以解决你所有的问题。

Device Class:0x0代表什么?抄一段给你
Class code (assigned by the USB).
If this field is reset to zero, each interface
within a configuration specifies its own
class information and the various
interfaces operate independently.
If this field is set to a value between 1 and
FEH, the device supports different class
specifications on different interfaces and
the interfaces may not operate
independently. This value identifies the
class definition used for the aggregate
interfaces. (For example, a CD-ROM
device with audio and digital data
interfaces that require transport control to
eject CDs or start them spinning.)
If this field is set to FFH, the device class
is vendor-specific.
来源:Page 197 in
《Universal Serial Bus Specification Revision 1.1》
(http://www.usb.org/developers/docs/usbspec.zip)

iManufacturer:0x1不代表哪个制造商,是制造商描述字符串索引号。VenderID:0x6FF才是制造商ID号,具体定义到www.usb.org下载。(http://www.usb.org/developers/tools/comp_dump)
游客

返回顶部