我试图为MacOs编写一个没有多少经验的宾得相机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"
}发布于 2019-03-03 15:14:52
我想我的问题是有原因的。我发现,实际上,为了控制摄像机,我需要发送大量命令,因为相机控件是通过批量控制隧道化的。您可以使用内置的自定义命令发出大容量命令,摄像机将对其作出响应。
我在PC上看到了使用Wireshark与PK_Tether对讲相机时使用的批量命令。(另一个有趣的事实是,除非我在相机卡插槽中有一个SD卡,否则pk_tether无法访问大容量存储。)
因此,现在我必须了解如何发出批量命令,所以我将在一个新线程上问这个问题。
发布于 2019-02-27 13:08:59
首先,返回的错误代码是什么?我猜是kIOReturnExclusiveAccess,但最好能确定一下。
第二,设备报告为复合设备吗?在这种情况下,您不应该尝试打开USB设备,而应该打开您感兴趣的USB接口。
如果仍然失败,或者它不是一个复合设备,这个问题通常意味着另一个驱动程序已经声明了该设备。使用IORegistryExplorer.app或ioreg命令行工具检查哪些进程或内核驱动程序打开了设备。
https://stackoverflow.com/questions/54896251
复制相似问题