0

IOUSBDeviceInterface245(Mac OS X の IOKit から) 情報 (製品名など) を取得しようとしています:
コード #1

io_iterator_t iterator;
io_object_t   usb_device  
SInt32 score = 0;
kern_return_t kr = IOServiceGetMatchingServices(kIOMasterPortDefault,     
                                           IOServiceNameMatching("AppleUSBOHCI"),    
                                           &iterator);   
IOCFPlugInInterface     **plugin_interface = NULL; 
IOUSBDeviceInterface245 **usb_interface    = NULL;
// ...
// enumerate devices (usb_device = IOIteratorNext(iterator))
// ...
IOReturn return_code = IOCreatePlugInInterfaceForService(usb_device,  
                                                  kIOUSBDeviceUserClientTypeID, 
                                                  kIOCFPlugInInterfaceID,  
                                                  &plugin_interface,
                                                  &score);
HRESULT h_result = (*pluginInterface)->QueryInterface(pluginInterface,
                                  CFUUIDGetUUIDBytes(kIOUSBDeviceInterfaceID245), 
                                  (LPVOID)&usb_interface);
IODestroyPlugInInterface(pluginInterface);

UInt8 product_string_index;
return_code = (*usb_interface)->USBGetProductStringIndex(usb_interface,  
                                                         &product_string_index);
// Next, getting a product string by string's index. To do so, we need to send  
// IOUSBDevRequest (with type "kUSBRqGetDescriptor") to the current USB-device.
// Code bellow - is a pseudocode:
char *product_name = malloc(128);
get_string_by_index(usb_interface, product_string_index, product_string, 128);

このコードは、現在動作中のすべてのデバイスでうまく機能しますが、サスペンド (「スリープ」)
デバイスでは機能しません (product_nameは単なる空白文字列です)。

しかし、このコードを使用すると:
コード #2

 CFMutableDictionaryRef child_properties = CFDictionaryCreateMutable(NULL, 0,  
                                                                NULL,NULL);
 kern_return_t kr;
 io_service_t io_service;
 // iterator = iterator for "AppleUSBOHCI" or "AppleUSBEHCI" services
 while((io_service = IOIteratorNext(iterator))) {      
    io_iterator_t   children_iterator;
    kernel_return = IORegistryEntryGetChildIterator(io_service, kIOServicePlane,  
                                                   &children_iterator);
    io_registry_entry_t child;
    while((child = IOIteratorNext(children_iterator))) {
      // Create a CFDictionary with usb-device's properties
      IORegistryEntryCreateCFProperties(child, &child_properties,  
                                        kCFAllocatorDefault, 
                                        kNilOptions);
      NSLog(@"%@",[(NSDictionary*)child_properties valueForKey:@"USB Product Name"]);
    }
  }

それはすべてのデバイスでまったく機能しています(理由はわかりません)。

このコードでサスペンドされたデバイスをウェイクアップしようとしました(コード#1を使用):

(*usb_interface)->USBDeviceSuspend(usb_interface, false);

しかし何も変わっていません。

私が気づいたことの 1 つ - コード #1 は、文字列値 (文字列のインデックスによって取得される) を除いて、スリープ状態のデバイスのすべてのプロパティに対して完全に機能しています。

更新:
それで、私の質問は、最初のコード ブロックで使用するためにデバイスの一時停止を解除するにはどうすればよいですか?
ありがとうございました。

4

1 に答える 1

1

文字列はデバイスから直接読み取られるため(コード#1のように)、中断されたデバイスから文字列を読み取ることはできません(中断されているため、応答できません)。これらを直接読み取るには、最初にデバイスの一時停止を解除する必要があります(ドライバーによって一時停止されている場合は、これは悪い考えかもしれません。また、成功を確認することを忘れないでください)

標準の文字列を読み取りたい場合は、2番目のコードブロック(デバイスから既にフェッチされているプロパティを読み取る)を使用します。

于 2011-09-11T11:21:19.093 に答える