1

我正在编写一个打开 USB 设备并传输一些数据的应用程序。我正在关注开发人员示例中的 UsbSimpleNotificationExample。该示例为唯一的供应商 ID 和产品 ID 添加通知并分配回调。但是对于我的应用程序,我有多个 PID 和一个 VID。如何添加具有单个 Vid 和多个 PID 的字典条目?如果我将 CFDictionarySetValue 与 2 个 PID 一起使用,则第二个 Pid 调用会覆盖第一个字典值。因此,我无法正确匹配 IOServiceAddMatchingNotification 回调。我可以尝试哪些其他选择?

4

2 回答 2

1

为什么不尝试仅添加供应商 ID?

然后您的匹配项应包括所有产品 ID。

于 2009-02-07T02:13:18.997 回答
0

晚了6年……对不起。

这是你如何做到的:

CFMutableDictionaryRef  matchingDict = IOServiceMatching ( kIOUSBDeviceClassName );
if ( matchingDict )
{
    UInt32        usbVendor = k_MyVendorID;
    CFNumberRef   refVendorId = CFNumberCreate ( kCFAllocatorDefault, kCFNumberIntType, &usbVendor );
    CFDictionarySetValue ( matchingDict, CFSTR ( kUSBVendorID ), refVendorId );
    CFRelease ( refVendorID );
    CFDictionarySetValue ( matchingDict, CFSTR ( kUSBProductID ), CFSTR ( "*" ) );   // This is a wildcard, so we find any device.
}

注意通配符。

于 2014-03-20T15:40:52.943 回答