- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的问题是我想手动处理插入 USB 设备时的处理方式。我不希望操作系统对插入的 USB 设备执行任何操作,除了在插入时通知我其类型和 ID 之外它们已插入。然后我可以从那里选择要应用的适当驱动程序,或者使用自定义代码手动对其执行某些操作。
我已阅读 this关于 MacOS 如何处理 USB,它说:
If you want your driver selected above others, all you need to do is add key value pairs for the device your driver is for which cause your driver to get a really high score. Usually it's enough to just put keys in for your vendor id/model. However, I think you can override the matching method (device drivers are written in a restricted set of C++) to give your driver a really high score.
我还发现了这 3 个库,用于获取有关 USB 驱动器中的内容的通知:
我只是不确定这些库是否会在发生任何事情之前(在自动选择并应用任何设备驱动程序之前)中断操作系统处理的所有 USB 设备。我希望除了我能够访问上述库之一中的设备及其类型之外什么都不会发生,但我不确定他们是否会这样做。
除此之外我没有太多代码:
var usb = require('usb')
usb.getDeviceList()
但我想这将在操作系统已经选择并应用默认驱动程序之后解决插入的设备问题。我想做这样的事情:
usb.blockDefaultOSDeviceHandler()
usb.on('device:plugged_in', function(data){
if (data.type == 'keyboard') {
if (data.modelNumber == '123') {
// allow
usb.applyKeyboardDriver('abc', data.modelNumber)
usb.on('keyboard:event', logKeyboardEvent)
} else {
throw new Error('Unrecognized device')
}
}
})
我希望该库能够中断操作系统的所有默认行为,这样我就可以自己处理插入 USB 设备时应该执行的操作。原因可能是因为 USB 设备是一个键盘,它会自动开始输入某些键。我想知道它是键盘,需要密码和我预先批准的特定驱动程序。诸如此类的事情。
我希望在操作系统应用其默认处理规则之前访问任何新插入的 USB 设备。然后能够编写代码来手动处理每个插入的设备的操作。
如果它只能在 C 语言中实现,那么知道如何在 C 语言中实现它会比使用 Node.js 更好。
最佳答案
答案就在 Apple 关于 USB 设备的文档中。基本上,您想要覆盖自定义驱动程序中的 probe
函数,让它返回最高分数,以便覆盖所有其他驱动程序,并像平常一样实现驱动程序。 Here是一些有关驱动程序选择和实例化过程的有用文档。
Before a device—or any service provider—can be used, a driver for it must be found and loaded into the kernel. The I/O Kit defines a flexible, three-phase matching process that narrows a pool of candidate drivers down to one or more drivers. The final candidate (or, if multiple candidates, the m ost eligible one) is then loaded and given the first opportunity to manage the device or service provider.
...
Each device driver, considered as a loadable kernel extension (KEXT), must define one or more personalities that specify the kinds of devices it can support.
...
Because a driver can contain multiple matching dictionaries, each one defining a different personality for the driver, the same driver code can be loaded for different devices. For purposes of competition, the I/O Kit treats each personality as if it were a driver. If, in any single personality, all of the properties required by the family match, the driver’s code is loaded and given a chance to run for that device.
...
One common property of personalities is the probe score. A probe score is an integer that reflects how well-suited a driver is to drive a particular device. A driver may have an initial probe-score value in its personality and it may implement a probe function that allows it to modify this default value, based on its suitability to drive a device. As with other matching values, probe scores are specific to each family. That’s because once matching proceeds past the class-matching stage, only personalities from the same family compete. For more information on probe scores and what a driver does in the probe function, see Device Probing.
...
At boot time and at any time devices are added or removed, the process of driver matching occurs for each detected device (or other service provider). The process dynamically locates the most suitable driver in /System/Library/Extensions for the device or service.
...
As described in Driver Matching in the chapter Architectural Overview the matching process is triggered when a bus controller driver scans its bus and detects a new device attached to it. For each detected device the controller driver creates a nub. The I/O Kit then initiates the matching process and obtains the values from the device to use in matching (for example, examining the PCI registers). Once a suitable driver is found for the nub, the driver is registered and loaded. That driver, in turn, may create its own nub (possibly through behavior inherited from its family), which initiates the matching process to find a suitable driver.
...
The matching process proceeds as follows:
- In the class matching step, the I/O Kit narrows the list of potential drivers by eliminating any drivers of the wrong class for the provider service (that is, the nub). For example, all driver objects that descend from a SCSI class can be ruled out when the search is for a USB driver.
- In the passive matching step, the driver’s personality (specified in a driver’s XML information property list) is examined for properties specific to the provider’s family. For example, the personality might specify a particular vendor name.
- In the active matching step, the driver’s probe function is called with reference to the nub it is being matched against. This function allows the driver to communicate with the device and verify that it can in fact drive it. The driver returns a probe score that reflects its ability to drive the device. See Device Probing for more information. During active matching, the I/O Kit loads and probes all candidate drivers, then sorts them in order of highest to lowest probe score.
...
The I/O Kit then chooses the remaining driver with the highest probe score and starts it. If the driver successfully starts, it is added to the I/O Registry and any remaining driver candidates are discarded. If it does not start successfully, the driver with the next highest probe score is started, and so on. If more than one driver is in the pool of possible candidates, the more generic driver typically loses out to the more specific driver if both claim to be able to drive the device.
...
The probe score is a signed 32-bit integer initialized to a value specified in the driver’s personality (or to zero if not explicitly initialized).
...
A driver, in its probe function, returns a driver object (IOService *) if the probe was successful and returns zero otherwise. The returned object is usually the driver itself, but the driver can return another driver that is more suited to the provider. The probe score is an in-out parameter, which probe can modify based on what it discovers about the device.
...
After all drivers have probed the device, the one with the highest probe score is attached and its startfunction, which must be implemented by all drivers, is invoked. The start function initializes the device hardware and prepares it for operation. If the driver succeeds in starting, it returns true; the remaining candidate driver instances are discarded and the driver that started successfully continues operating. If the driver cannot initialize the hardware it must leave the hardware in the state it was in when start was invoked and return false. The failing driver is then detached and discarded, and the candidate driver with the next highest probe score is given a chance to start.
这不能用 Node.js 来完成,除非(可能)使用 Node 中的 C/C++ 扩展。
关于c - 如何手动处理MacBook上所有插入的USB设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54047821/
我在一本名为 "USB in a NutShell" 的相当棒的书中找到了中断传输提供可靠的传输(通过错误检测和自动重试)。 但我想知道,这能保证有一天不会按顺序交换转移吗?至于总线是串行的,我的猜测
USB 2.0 specifies 4 种传输类型(在第 5.4 节传输类型中): 控制转移 同步传输 中断传输 批量转账 第 5.8 节说批量传输提供: Access to the USB on a
在我正在研究的 SoC 中,有 USB EHCI 兼容 Controller 。 所有 EHCI Controller 都可以作为主机或设备工作吗? EHCI Linux 驱动程序是否涵盖此类 Con
我有一个 USB 调制解调器,它经常掉线。发生这种情况时,我将其从 USB 端口拔出并重新插入,它会立即返回信号;我可以编写一个程序来执行此操作而无需物理断开调制解调器与端口的连接吗? 最佳答案 正如
我正在尝试使用 libusb 与 USB 设备通信,但我觉得自己在比赛的第一站被绊倒了。我确切地知道我需要与哪些端点交谈,等等,但我什至做不到那么远。本质上,我有: usb_device *dev =
是否有工具可以验证在枚举过程中读取的 USB 设备描述符?我遇到过这样的情况,我购买的设备(实验室设备)的 USB 设备描述符不是很有效,并且无法被操作系统正确识别为“加载设备描述符失败”。我知道这并
我正在从事一个需要将信号从外部世界传输到计算机的项目。我有一个生成模拟信号的源,这个信号需要通过 USB 在 PC 上传输。这是我的问题:什么是接口(interface)? 我从源头获得的模拟信号,是
我想知道降低/提高 USB 端口的输出功率在技术上是否可行? 我自己也持怀疑态度,但我要求确定。 最佳答案 如上所述,是的。要获得超过 500mA (USB 2.0) 的电流,请使用组合电缆并联两个或
我正在尝试制作一个 HID USB 设备。我搜索了一下,发现键盘的输出有 8 个字节。第一个字节是修饰符,第二个字节是保留字节,其余 6 个字节是关键代码。我认为在某些情况下,例如“prtsc”,需要
我们正在寻找一个虚拟 USB 链接模拟器;这个程序或服务应该 链接虚拟COM port到仅接受 USB 作为数据链路的应用程序。 virtual COM port是 VSPE来自 Eterlogic
我一直在尝试监视何时插入或移除 USB 设备,它似乎工作得很好。现在唯一困扰我的是,每次我插入或移除设备时,都会多次触发该事件。 我可以毫无问题地将事件分组,但我很好奇为什么它首先发生。 这是我正在使
关闭。这个问题需要更多 focused .它目前不接受答案。 想改进这个问题?更新问题,使其仅关注一个问题 editing this post . 6年前关闭。 Improve this questi
我正在为 USB 设备编写代码。假设 USB 主机开始控制读取传输以从设备读取一些数据,并且请求的数据量(设置数据包中的 wLength)是端点 0 最大数据包大小的倍数。那么在主机接收到所有数据后(
我们正在开发一个带有 arm7(current: LPC2368) 的发送器设备。 本设备采样一个 mv 信号,A/D,并需要将此信号数据发送到 PC。(连续) 同时,PC 需要向 arm7 发送命令
我希望能够使用通过 USB 连接到 PC 的 IR 远程传感器打开和关闭我的 PC。该传感器是使用 AVR 微处理器和 V-USB 软件 USB 实现实现的定制 PCB。 现在,用软件关掉电脑是没有问
我正在使用 STM32L151 与使用 USB CDC 的 PC 进行通信。我使用 STM32 HAL 库来创建我的项目。 我发现 USB 以 1 ms 的间隔发送数据,每次发送 64 个字节。那么,
我们有一个设备要求我们在插入之前安装驱动程序,否则我们需要删除 Windows 8 和 10 自动下载的驱动程序。 我们如何制作一个无论先插还是不插都能正确安装的USB驱动安装器? 最佳答案 在 Wi
我需要填充 USB 存储器,我希望其他人能够以简单的方式重复此操作。所以我不想写“找到一个填满内存的文件”,所以他们必须四处寻找这样的文件。 我想生成 X MB 的数据并将其写入一个文件,然后可以将其
我有一个 Android 平板电脑,它有一个迷你 USB 端口和一个 USB 端口,我想编写一个与 USB key 通信的应用程序。我写了一个demo来找出U盘,但是没有任何反应。 令我不安的是,如果
我正在尝试使用 Android USB Host API 读取我的 USB 游戏 Controller 数据,一旦我让它工作,我将连接其他设备进行测试。我的游戏 Controller 使用 OTG 线
我是一名优秀的程序员,十分优秀!