macOS 开发 - USB 信息


一、通过系统报告查看

本机 —> 系统报告 —> 硬件—>USB

在这里插入图片描述


二、通过 IORegistryExplorer 获取详细信息

IORegistryExplorer 下载地址:
https://download.csdn.net/download/lovechris00/10317601
在这里插入图片描述


三、通过 IOKit.framework 编码获取

-(void)getUSBInfo{
    
    CFMutableDictionaryRef properties = 0;
    kern_return_t status = KERN_SUCCESS;
    
    io_registry_entry_t service = IORegistryEntryFromPath(kIOMasterPortDefault, "IOUSB:/");
    status = IORegistryEntryCreateCFProperties(service,&properties,kCFAllocatorDefault,kNilOptions );
    
    if (status){
        NSLog(@"status : %d",status);
    }else{
        NSDictionary *pro = (__bridge NSDictionary *)properties;
        NSLog(@"\n\n properties : %@-------\n\n",pro);
        for (NSString *key in pro.allKeys) {
            id data = pro[key];
            if ([data isKindOfClass:[NSData class]]) {
                NSString *value = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
                NSLog(@"%@ : %@",key,value);
            }else{
                NSLog(@"%@ - %@",key,data);
            }
        }
    }
    
    //获取子节点
    io_iterator_t iterator = IO_OBJECT_NULL;
    status = IORegistryEntryGetChildIterator(service,kIOUSBPlane,&iterator);
    
    kern_return_t    kr;
    io_registry_entry_t usb;
    io_name_t        name;
    
    while((usb = IOIteratorNext(iterator))) {
        
        NSLog(@"\n\n---------------");
        if( KERN_SUCCESS == IORegistryEntryGetName(usb, name)){
            printf(name);
        }
        
        assert( KERN_SUCCESS == (kr = IORegistryEntryCreateCFProperties(usb, &properties, kCFAllocatorDefault, kNilOptions )));
        
        NSLog(@"\nproperties : %@\n",(__bridge NSDictionary *)properties);
    }
    
    IOObjectRelease(usb);
    CFRelease(properties);
    IOObjectRelease(service);
}

USB 部分日志类似如下:

---------------
DataTraveler 3.0
properties : {
    "Built-In" = 0;
    "Bus Power Available" = 450;
    "Device Speed" = 3;
    IOCFPlugInTypes =     {
        "9dc7b780-9ec0-11d4-a54f-000a27052861" = "IOUSBFamily.kext/Contents/PlugIns/IOUSBLib.bundle";
    };
    IOClassNameOverride = IOUSBDevice;
    IOGeneralInterest = "IOCommand is not serializable";
    IOPowerManagement =     {
        CapabilityFlags = 65536;
        CurrentPowerState = 3;
        DevicePowerState = 0;
        DriverPowerState = 3;
        MaxPowerState = 4;
    };
    IOUserClientClass = IOUSBDeviceUserClientV2;
    PortNum = 11;
    "USB Address" = 2;
    "USB Product Name" = "DataTraveler 3.0";
    "USB Serial Number" = 08606E6D3FE5B011581A0F09;
    "USB Vendor Name" = Kingston;
    bDeviceClass = 0;
    bDeviceProtocol = 0;
    bDeviceSubClass = 0;
    bMaxPacketSize0 = 9;
    bNumConfigurations = 1;
    bcdDevice = 272;
    bcdUSB = 768;
    iManufacturer = 1;
    iProduct = 2;
    iSerialNumber = 3;
    idProduct = 5734;
    idVendor = 2385;
    kUSBCurrentConfiguration = 1;
    locationID = 347078656;
    "non-removable" = no;
    sessionID = 1579503837;
    uid = "USB:09511666B011581A0F09";
}



四、通过命令行获取


1、$ system_profiler SPUSBDataType

$ system_profiler SPUSBDataType
USB:

    USB 3.0 Bus:

      Host Controller Driver: AppleUSBXHCILPT
      PCI Device ID: 0x9c31 
      PCI Revision ID: 0x0004 
      PCI Vendor ID: 0x8086 

        DataTraveler 3.0:

          Product ID: 0x1666
          Vendor ID: 0x0951  (Kingston Technology Company)
          Version: 1.10
          Serial Number: 08606E6D3FE5B011581A0F09
          Speed: Up to 5 Gb/sec
          Manufacturer: Kingston
          Location ID: 0x14b00000 / 2
          Current Available (mA): 900
          Current Required (mA): 504
          Extra Operating Current (mA): 0
          ...

2、$ ioreg -Src IOUSBDevice

如果希望输出 xml 数据,命令可以改为 $ ioreg -Src IOUSBDevice -a

$ ioreg -Src IOUSBDevice
+-o AppleUSBXHCI Root Hub Simulation@14000000  <class AppleUSBRootHubDevice, id 0x10000031$
    {
      "iManufacturer" = 0
      "bNumConfigurations" = 1
      "idProduct" = 32775
      "bMaxPacketSize0" = 8
      "Built-In" = Yes
      "iProduct" = 0
      "USB Product Name" = "AppleUSBXHCI Root Hub Simulation"
      "iSerialNumber" = 0
      "bDeviceClass" = 9
      "IOPowerManagement" = {"DevicePowerState"=0,"CurrentPowerState"=4,"CapabilityFlags"=$
      "IOUserClientClass" = "IOUSBDeviceUserClientV2"
      "locationID" = 335544320
      "bDeviceSubClass" = 255
      "bcdUSB" = 256
      "non-removable" = "yes"
      "IOCFPlugInTypes" = {"9dc7b780-9ec0-11d4-a54f-000a27052861"="IOUSBFamily.kext/Conten$
      "bDeviceProtocol" = 3
      "USB Vendor Name" = "Apple Inc."
      "Device Speed" = 3
      "idVendor" = 1452
      "IOClassNameOverride" = "IOUSBRootHubDevice"
    }
    

+-o DataTraveler 3.0@14b00000  <class AppleUSBDevice, id 0x100000320, registered, matched,$
  | {
  |   "sessionID" = 1579503837
  |   "iManufacturer" = 1
  |   "bNumConfigurations" = 1
  |   "idProduct" = 5734
  |   "bcdDevice" = 272
  |   "Bus Power Available" = 450
  |   "USB Address" = 2
  |   "bMaxPacketSize0" = 9
  |   "iProduct" = 2
  |   "iSerialNumber" = 3
  |   "bDeviceClass" = 0
  |   "Built-In" = No
  |   "locationID" = 347078656
  |   "bDeviceSubClass" = 0
  |   "bcdUSB" = 768
  |   "USB Product Name" = "DataTraveler 3.0"
  |   "PortNum" = 11
  |   "non-removable" = "no"
  |   "IOCFPlugInTypes" = {"9dc7b780-9ec0-11d4-a54f-000a27052861"="IOUSBFamily.kext/Conten$
  |   "bDeviceProtocol" = 0
  |   "IOUserClientClass" = "IOUSBDeviceUserClientV2"
  |   "IOPowerManagement" = {"DevicePowerState"=0,"CurrentPowerState"=3,"CapabilityFlags"=$
  |   "kUSBCurrentConfiguration" = 1
  |   "Device Speed" = 3
  |   "USB Vendor Name" = "Kingston"
  |   "idVendor" = 2385
  |   "uid" = "USB:09511666B011581A0F09"
  |   "IOGeneralInterest" = "IOCommand is not serializable"
  |   "USB Serial Number" = "08606E6D3FE5B011581A0F09"
  |   "IOClassNameOverride" = "IOUSBDevice"
  | }
  | 
  +-o AppleUSBInterface@0  <class AppleUSBInterface, id 0x100000327, registered, matched, $



参考资料


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

编程乐园

请我喝杯伯爵奶茶~!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值