我正在尝试为没有太多经验的MacO编写宾得相机USB驱动程序。我已经能够使用“使用USB设备接口”中的示例代码与摄像机进行通信,但前提是我使用异步通知并且弹出并重新连接摄像机。它似乎工作,如果在调试期间,代码在安装之前捕获相机。我想在没有通知和CFRunloop的情况下这样做,所以我现在正在尝试使用IOServiceGetMatchingServices()。我可以获取设备,配置,执行DeviceRequest甚至创建设备接口,获取它的类但USBInterfaceOpen失败。我想我需要为其中一个端点设置一个管道,这样DeviceRequest的工作原理不仅仅是获取状态,而且我无法通过打开接口。谢谢
编辑:
所以在我看来,唯一的接口是IOUSBHostInterface @ 0,这是用于大容量存储访问,对吗?所以我想尝试使用DeviceRequest发送命令 - 我设想的控制接口 - 是唯一的选项,但失败了,错误代码为e000404f。我相信我可以正确地制定命令,因为我可以看到Wireshark中的字节,但整个数据包与我在PC USB上看到的不同。也许我还没有得到正确的命令字节?
+-o K-5 II@14200000 <class IORegistryEntry:IOService:IOUSBNub:IOUSBDevice, id 0x100002645, registered, matched, active, busy 0 (2976 ms), retai$
| {
| "sessionID" = 116428207269670
| "USBSpeed" = 3
| "IOServiceLegacyMatchingRegistryID" = 4294977095
| "idProduct" = 328
| "bDeviceClass" = 0
| "IOPowerManagement" = {"PowerOverrideOn"=Yes,"CapabilityFlags"=32768,"MaxPowerState"=2,"DevicePowerState"=2,"ChildrenPowerState"=2,"Driver$
| "bcdDevice" = 263
| "USB Product Name" = "K-5 II"
| "AppleUSBAlternateServiceRegistryID" = 4294977095
| "locationID" = 337641472
| "kUSBSerialNumberString" = "4585468"
| "bDeviceSubClass" = 0
| "kUSBCurrentConfiguration" = 1
| "IOCFPlugInTypes" = {"9dc7b780-9ec0-11d4-a54f-000a27052861"="IOUSBFamily.kext/Contents/PlugIns/IOUSBLib.bundle"}
| "bDeviceProtocol" = 0
| "USBPortType" = 0
| "USB Vendor Name" = "PENTAX"
| "idVendor" = 9723
| "USB Serial Number" = "4585468"
| "IOGeneralInterest" = "IOCommand is not serializable"
| "kUSBVendorString" = "PENTAX"
| "IOClassNameOverride" = "IOUSBDevice"
| }
|
+-o AppleUSBHostLegacyClient <class IORegistryEntry:IOService:AppleUSBHostLegacyClient, id 0x100002648, !registered, !matched, active, busy 0$
| {
| "IOPowerManagement" = {"DevicePowerState"=0,"CurrentPowerState"=1,"CapabilityFlags"=65536,"MaxPowerState"=2,"DriverPowerState"=1}
| }
|
+-o AppleUSBHostCompositeDevice <class IORegistryEntry:IOService:AppleUSBHostCompositeDevice, id 0x100002650, !registered, !matched, active, $
| {
| "IOProbeScore" = 50000
| "CFBundleIdentifier" = "com.apple.driver.usb.AppleUSBHostCompositeDevice"
| "IOProviderClass" = "IOUSBHostDevice"
| "IOClass" = "AppleUSBHostCompositeDevice"
| "bDeviceSubClass" = 0
| "IOMatchCategory" = "IODefaultMatchCategory"
| "kUSBPreferredConfiguration" = 1
| "bDeviceClass" = 0
| }
|
+-o IOUSBHostInterface@0 <class IORegistryEntry:IOService:IOUSBNub:IOUSBInterface, id 0x100002652, registered, matched, active, busy 0 (1112 $
| {
| "USBPortType" = 0
| "IOCFPlugInTypes" = {"2d9786c6-9ef3-11d4-ad51-000a27052861"="IOUSBFamily.kext/Contents/PlugIns/IOUSBLib.bundle"}
| "bcdDevice" = 263
| "USBSpeed" = 3
| "idProduct" = 328
| "bConfigurationValue" = 1
| "bInterfaceSubClass" = 6
| "locationID" = 337641472
| "IOGeneralInterest" = "IOCommand is not serializable"
| "IOServiceLegacyMatchingRegistryID" = 4294977107
| "IOClassNameOverride" = "IOUSBInterface"
| "AppleUSBAlternateServiceRegistryID" = 4294977107
| "idVendor" = 9723
| "bInterfaceProtocol" = 80
| "bAlternateSetting" = 0
| "bInterfaceNumber" = 0
| "bInterfaceClass" = 8
| }
|
+-o IOUSBMassStorageInterfaceNub <class IORegistryEntry:IOService:IOUSBMassStorageInterfaceNub, id 0x100002654, registered, matched, active$
| {
| "IOClass" = "IOUSBMassStorageInterfaceNub"
| "idProduct" = 328
| "bInterfaceProtocol" = 80
| "USB Device Info" = {"bcdDevice"=263,"idProduct"=328,"kUSBVendorString"="PENTAX","bConfigurationValue"=1,"kUSBSerialNumberString"="458$
| "bcdDevice" = 263
| "IOProviderClass" = "IOUSBHostInterface"
| "Physical Interconnect Location" = "External"
| "USB Product Name" = "K-5 II"
| "IOPowerManagement" = {"DevicePowerState"=1,"CurrentPowerState"=1,"CapabilityFlags"=32768,"MaxPowerState"=1,"DriverPowerState"=1}
| "IOProbeScore" = 50000
| "locationID" = 337641472
| "kUSBSerialNumberString" = "4585468"
| "bInterfaceSubClass" = 6
| "bInterfaceClass" = 8
| "Physical Interconnect" = "USB"
| "bConfigurationValue" = 1
| "IOMatchCategory" = "IODefaultMatchCategory"
| "CFBundleIdentifier" = "com.apple.iokit.IOUSBMassStorageDriver"
| "bInterfaceNumber" = 0
| "idVendor" = 9723
| "USB Mass Storage Trace ID" = 2736782607644622848
| "kUSBVendorString" = "PENTAX"
| }
|
+-o IOUSBMassStorageDriverNub <class IORegistryEntry:IOService:IOUSBMassStorageDriverNub, id 0x100002656, registered, matched, active, bu$
| {
| "IOClass" = "IOUSBMassStorageDriverNub"
| "CFBundleIdentifier" = "com.apple.iokit.IOUSBMassStorageDriver"
| "IOProviderClass" = "IOUSBMassStorageInterfaceNub"
| "USB Mass Storage Trace ID" = 2736782607644622848
| "IOPowerManagement" = {"ChildrenPowerState"=1,"DevicePowerState"=1,"CurrentPowerState"=1,"CapabilityFlags"=32768,"MaxPowerState"=1,"$
| "idProduct" = 328
| "IOProbeScore" = 0
| "bConfigurationValue" = 1
| "bInterfaceSubClass" = 6
| "IOMatchCategory" = "IODefaultMatchCategory"
| "kUSBVendorString" = "PENTAX"
| "USB Product Name" = "K-5 II"
| "USB Device Info" = {"bcdDevice"=263,"idProduct"=328,"kUSBVendorString"="PENTAX","bConfigurationValue"=1,"kUSBSerialNumberString"="4$
| "Physical Interconnect" = "USB"
| "idVendor" = 9723
| "bInterfaceProtocol" = 80
| "Physical Interconnect Location" = "External"
| "bInterfaceNumber" = 0
| "bInterfaceClass" = 8
| }
|
+-o IOUSBMassStorageDriver <class IORegistryEntry:IOService:IOSCSIProtocolInterface:IOSCSIProtocolServices:IOUSBMassStorageDriver, id 0$
| {
| "IOClass" = "IOUSBMassStorageDriver"
| "CFBundleIdentifier" = "com.apple.iokit.IOUSBMassStorageDriver"
| "IOProviderClass" = "IOUSBMassStorageDriverNub"
| "Write Time Out Duration" = 30000
| "USB Mass Storage Trace ID" = 2736782607644622848
| "IOPowerManagement" = {"ChildrenPowerState"=1,"DevicePowerState"=1,"CurrentPowerState"=1,"CapabilityFlags"=32768,"MaxPowerState"=1$
| "Read Time Out Duration" = 30000
| "IOProbeScore" = 0
| "IOUnit" = 16
| "IOMatchCategory" = "IODefaultMatchCategory"
| "Retry Count" = 20
| "Protocol Characteristics" = {"Physical Interconnect"="USB","Read Time Out Duration"=30000,"Physical Interconnect Location"="Exter$
| "bInterfaceProtocol" = 80
| "Physical Interconnect Location" = "External"
| "No INQUIRY VPD Pages" = Yes
| }
|
+-o IOSCSILogicalUnitNub@0 <class IORegistryEntry:IOService:IOSCSIProtocolInterface:IOSCSIProtocolServices:IOSCSIPeripheralDeviceNub:$
| {
| "TPGS Information" = 0
| "Peripheral Device Type" = 0
| "Vendor Identification" = "PENTAX"
| "SCSI Logical Unit Number" = 0
| "IOMatchCategory" = "SCSITaskUserClientIniter"
| "Product Identification" = "DSC_K-5_II"
| "Protocol Characteristics" = {"Physical Interconnect"="USB","Read Time Out Duration"=30000,"SCSI Logical Unit Number"=0,"Physica$
| "IOUnitLUN" = 0
| "Product Revision Level" = "1.07"
| }
|
+-o IOSCSIPeripheralDeviceType00 <class IORegistryEntry:IOService:IOSCSIProtocolInterface:IOSCSIPrimaryCommandsDevice:IOSCSIBlockCo$
| {
| "IOClass" = "IOSCSIPeripheralDeviceType00"
| "CFBundleIdentifier" = "com.apple.iokit.IOSCSIBlockCommandsDevice"
| "IOProviderClass" = "IOSCSIPeripheralDeviceNub"
| "IOMaximumBlockCountRead" = 256
| "IOPowerManagement" = {"CapabilityFlags"=49216,"MaxPowerState"=4,"ActivityTickles"=58,"IdleTimerPeriod"=200000,"DevicePowerSta$
| "IOMaximumBlockCountWrite" = 256
| "IOProbeScore" = 5000
| "Peripheral Device Type" = 0
| "IOMatchCategory" = "IODefaultMatchCategory"
| "IOMaximumByteCountWrite" = 131072
| "WriteCacheState" = No
| "IOMaximumByteCountRead" = 131072
| }
|
+-o IOBlockStorageServices <class IORegistryEntry:IOService:IOBlockStorageDevice:IOBlockStorageServices, id 0x100002660, register$
| {
| "IOMinimumSegmentAlignmentByteCount" = 4
| "device-type" = "Generic"
| "Device Characteristics" = {"Vendor Name"="PENTAX","Product Name"="DSC_K-5_II","Product Revision Level"="1.07"}
| "Protocol Characteristics" = {"Physical Interconnect"="USB","Read Time Out Duration"=30000,"SCSI Logical Unit Number"=0,"Phy$
| }
|
+-o IOBlockStorageDriver <class IORegistryEntry:IOService:IOStorage:IOBlockStorageDriver, id 0x100002661, registered, matched, $
| {
| "IOPropertyMatch" = {"device-type"="Generic"}
| "IOProbeScore" = 0
| "IOProviderClass" = "IOBlockStorageDevice"
| "IOClass" = "IOBlockStorageDriver"
| "CFBundleIdentifier" = "com.apple.iokit.IOStorageFamily"
| "Statistics" = {"Operations (Write)"=6,"Latency Time (Write)"=0,"Bytes (Read)"=2269184,"Errors (Write)"=0,"Total Time (Rea$
| "IOMatchCategory" = "IODefaultMatchCategory"
| "IOGeneralInterest" = "IOCommand is not serializable"
| }
|
+-o PENTAX DSC_K-5_II Media <class IORegistryEntry:IOService:IOStorage:IOMedia, id 0x100002664, registered, matched, active, $
| {
| "Removable" = Yes
| "Content" = "FDisk_partition_scheme"
| "Whole" = Yes
| "Leaf" = No
| "BSD Name" = "disk2"
| "Ejectable" = Yes
| "Preferred Block Size" = 512
| "IOMediaIcon" = {"IOBundleResourceFile"="Removable.icns","CFBundleIdentifier"="com.apple.iokit.IOStorageFamily"}
| "BSD Minor" = 8
| "IOGeneralInterest" = "IOCommand is not serializable"
| "Writable" = Yes
| "BSD Major" = 1
| "Size" = 16147022336
| "IOBusyInterest" = "IOCommand is not serializable"
| "Open" = Yes
| "Content Hint" = ""
| "BSD Unit" = 2
| }
|
+-o IOMediaBSDClient <class IORegistryEntry:IOService:IOMediaBSDClient, id 0x100002665, registered, matched, active, busy 0$
| {
| "IOClass" = "IOMediaBSDClient"
| "IOMatchCategory" = "IOMediaBSDClient"
| "IOProbeScore" = 30000
| "IOProviderClass" = "IOMedia"
| "IOResourceMatch" = "IOBSD"
| "CFBundleIdentifier" = "com.apple.iokit.IOStorageFamily"
| }
|
+-o IOFDiskPartitionScheme <class IORegistryEntry:IOService:IOStorage:IOPartitionScheme:IOFDiskPartitionScheme, id 0x100002$
| {
| "IOPropertyMatch" = {"Whole"=Yes}
| "IOProbeScore" = 3000
| "IOMatchCategory" = "IOStorage"
| "IOClass" = "IOFDiskPartitionScheme"
| "IOProviderClass" = "IOMedia"
| "CFBundleIdentifier" = "com.apple.iokit.IOStorageFamily"
| "Content Mask" = "FDisk_partition_scheme"
| "Content Table" = {"0xA9"="NetBSD","0x82"="Linux_Swap","0x01"="DOS_FAT_12","0xA7"="Apple_Rhapsody_UFS","0x0B"="DOS_FAT$
| }
|
+-o Untitled 1@1 <class IORegistryEntry:IOService:IOStorage:IOMedia, id 0x10000266b, registered, matched, active, busy 0 $
| {
| "Removable" = Yes
| "Content" = "DOS_FAT_32"
| "Whole" = No
| "Leaf" = Yes
| "BSD Name" = "disk2s1"
| "Ejectable" = Yes
| "Preferred Block Size" = 512
| "Base" = 4194304
| "BSD Minor" = 9
| "IOGeneralInterest" = "IOCommand is not serializable"
| "Writable" = Yes
| "Partition ID" = 1
| "BSD Major" = 1
| "Size" = 16142827520
| "IOBusyInterest" = "IOCommand is not serializable"
| "Open" = Yes
| "Content Hint" = "DOS_FAT_32"
| "BSD Unit" = 2
| }
|
+-o IOMediaBSDClient <class IORegistryEntry:IOService:IOMediaBSDClient, id 0x10000266c, registered, matched, active, bu$
{
"IOClass" = "IOMediaBSDClient"
"IOMatchCategory" = "IOMediaBSDClient"
"IOProbeScore" = 30000
"IOProviderClass" = "IOMedia"
"IOResourceMatch" = "IOBSD"
"CFBundleIdentifier" = "com.apple.iokit.IOStorageFamily"
}
首先,返回的错误代码是什么?我猜kIOReturnExclusiveAccess
,但肯定知道这很好。
其次,设备是否作为复合设备报告?在这种情况下,您不应该尝试打开USB设备,而应该打开您感兴趣的USB接口。
如果仍然失败,或者它不是复合设备,则此问题通常意味着另一个驱动程序已经声明了该设备。检查IORegistryExplorer.app或ioreg
命令行工具,找出设备打开的进程或内核驱动程序。
我想我有理由解决我的问题。我发现确实,为了命令摄像机,我需要发送批量命令,因为摄像机控制是通过批量控制进行隧道传输的。您发出一个批量命令,其中包含相机将响应的嵌入式自定义命令。
我通过使用Wireshark在PC上与PK_Tether通话时看到了批量命令。 (另一个有趣的事实是pk_tether无法访问大容量存储,除非我在相机卡插槽中有SD卡。)
所以现在我必须找出如何发出批量命令,所以我会在一个新线程上问这个问题。