Dil*_*ili 3 macos usb xcode iokit
我最少接触xcode和I/Okit框架.我在USB探测器中看到了USB设备的设备描述符和配置描述符.
我已经使用I/O工具包框架编写了一个xcode程序,当我们将该设备的产品ID和供应商ID作为输入时,它将usb设备名称作为输出.
/*Take the vendor and product id from console*/
printf("\nEnter the vendor id : ");
scanf("%lx",&usbVendor);
printf("\nEnter the product id :");
scanf("%lx",&usbProduct);
/* Set up a matching dictionary for the class */
matchingDict = IOServiceMatching(kIOUSBDeviceClassName);
if (matchingDict == NULL)
{
return -1; // fail
}
// Create a CFNumber for the idVendor and set the value in the dictionary
numberRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &usbVendor);
CFDictionarySetValue(matchingDict,
CFSTR(kUSBVendorID),
numberRef);
CFRelease(numberRef);
// Create a CFNumber for the idProduct and set the value in the dictionary
numberRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &usbProduct);
CFDictionarySetValue(matchingDict,
CFSTR(kUSBProductID),
numberRef);
CFRelease(numberRef);
numberRef = NULL;
/*Get an iterator.*/
kr = IOServiceGetMatchingServices(kIOMasterPortDefault, matchingDict, &iter);
if (kr != KERN_SUCCESS)
{
return -1;// fail
}
/* iterate */
while ((device = IOIteratorNext(iter)))
{
/*Display the device names */
io_name_t deviceName;
kr = IORegistryEntryGetName(device, deviceName);
if (KERN_SUCCESS != kr) {
deviceName[0] = '\0';
}
printf("\ndeviceName:%s",deviceName);
/*Free the reference taken before continuing to the next item */
IOObjectRelease(device);
}
/*Release the iterator */
IOObjectRelease(iter);
return 0;
Run Code Online (Sandbox Code Playgroud)
}
我需要对此进行修改,以便在给出usb设备的供应商和产品ID时,我将获得设备描述符和配置描述符(如USB prober中所示)作为输出.
这里我举了一个例子,代码可以改变,但输出必须是描述符(至少是设备描述符).
提前致谢...
小智 6
我想你应该下载USBProber的源代码,而不是自己搞清楚.
通过分析源代码,USBProber中提供的所有信息迟早都可以得到.
这里是下载IOUSBFamily源代码的链接,里面有USBProber. http://opensource.apple.com/tarballs/IOUSBFamily/
| 归档时间: |
|
| 查看次数: |
7826 次 |
| 最近记录: |