There are many USB devices, so searching and reading and writing USB devices is essential. However, there is very little information about USB read/write. Here, VC ++ is used to demonstrate some methods for obtaining USB information.
I. Enumeration of USB devices
You can obtain device information by enumerating the USB controller-> enumerating the USB hub-> enumerating the ports of the hub->.
Enumeration controller:
wsprintf(HCName, "////.//HCD%d", HCNum);
hHCDev = CreateFile(HCName,
GENERIC_WRITE,
FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
NULL);
The USB master controller on the computer is named hcd1 and hcd2. Use ccreatefile by Controller name
Open it. You can use deviceiocontrol to get the name of the driver and the name of the hub connected to it. Use ccreatefile to open the hub and obtain the connection information. Again
Enumerate the ports of the hub to obtain the connected device information.
Ii. Enumeration of HID Devices
The HID device is a standard man-machine interface specification defined by Microsoft. Such as USB mouse and USB game handle. You do not need to find the guid of a specific device.
Hidd_gethidguid (& guidhid) to get the guid. With guid
Setupdienumdeviceinterfaces can be used to determine whether a device is connected. If such devices are connected through
Setupdigetdeviceinterfacedetail obtains its device path information. Use ccreatefile
Open it and use hidd_getattributes to obtain its basic attribute information. You can use deviceiocontrol to obtain more detailed attributes. In this Code, if
The USB game handle is inserted to obtain the information. However, I do not know why XP cannot obtain the USB mouse information.
USB flash drive with three enumerations
Use getdrivetype first
The API obtains the device type. If the type is removable (of course, some large-capacity USB flash drives may be reported as fixed, other methods are required to determine), that is, the USB flash drive. Use
Ccreatefile
After the function is enabled, use the deviceiocontrol parameter ioctl_storage_query_property to obtain its properties.
Iv. Conclusion
The sample project is compiled in WINXP + xpddk + vc6. There are many types of USB devices, which are also special. The control software varies with the hardware of different manufacturers.
Different ictl codes are not easy to find ). This makes the USB port access device less convenient than the serial port. This routine only shows the basic access methods. Some problems have not been solved.
I hope you will be able to notify me or post it out.
Thanks for the Code such as USB port and USB view.
Contact: daisun1998@163.net