macos - 以编程方式 "unplug and replug"在 OS X 中加载新驱动程序的 USB 设备?

标签 macos installation usb driver iokit

我正在 OS X 中开发一个安装程序,为 USB 设备安装 IOKit 驱动程序,我试图让它在最后不需要重新启动。安装程序正确安装驱动程序并重建kext缓存,运行后,如果我拔下并重新插入USB设备,它会正确加载新驱动程序并且一切正常。

但是,我不想要求用户物理拔下设备以便加载新驱动程序。必须有一种方法让 OS X 以编程方式加载新驱动程序 - 实际上模拟设备被拔出并再次插入,或类似的东西。我该怎么做呢?到目前为止,谷歌搜索的时间没有任何结果,所以任何帮助将不胜感激!

最佳答案

IOUSBDeviceInterface187::USBDeviceReEnumerate() 会做你想做的。唯一的问题是找到所有感兴趣的设备并使用 IOServiceGetMatchingServices() 手动调用它们。 .

/*!
@function USBDeviceReEnumerate
@abstract   Tells the IOUSBFamily to reenumerate the device.
@discussion This function will send a terminate message to all clients of the IOUSBDevice (such as 
            IOUSBInterfaces and their drivers, as well as the current User Client), emulating an unplug 
            of the device. The IOUSBFamily will then enumerate the device as if it had just 
            been plugged in. This call should be used by clients wishing to take advantage 
            of the Device Firmware Update Class specification.  The device must be open to use this function. 
@availability This function is only available with IOUSBDeviceInterface187 and above.
@param      self Pointer to the IOUSBDeviceInterface.
@param      options A UInt32 reserved for future use. Ignored in current implementation. Set to zero.
@result     Returns kIOReturnSuccess if successful, kIOReturnNoDevice if there is no connection to an IOService,
            or kIOReturnNotOpen if the device is not open for exclusive access.
*/

IOReturn (*USBDeviceReEnumerate)(void *self, UInt32 options);

查看 IOKit/usb/IOUSBLib.h

关于macos - 以编程方式 "unplug and replug"在 OS X 中加载新驱动程序的 USB 设备?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12786922/

相关文章:

wix - 如何从 UI WixUI_Minimal 内置的 Wix 安装程序中删除许可证对话框

android - 如何使用JNA调用C的_IOR宏?

macos - 我无法连接 Mac OS X 的数模转换器 (USB)

swift - 检测以太网/wifi 网络变化

macos - 在桌面上叠加图像

compiler-errors - HAWQ安装错误

windows - 如何在另一个安装程序中创建安装程序?

java - AOA USB 连接问题

macos - 适用于 Mac OS X 的 RAD 工具。有吗?

ios - 如何在 SpriteKit 中为带有物理体的迷宫创建路径