简体   繁体   English

更新USB设备列表

[英]Update list of usb devices

I want create module which update list of usb devices automatically (not only mass storage). 我想创建模块自动更新USB设备列表(不仅是大容量存储)。 Now it works very rude - it has additional thread, which after 1 second update list of devices. 现在它非常粗鲁 - 它有额外的线程,在1秒后更新设备列表。 But maybe you know how to handle some plug event, which generate OS (for example windows XP and above) or another way how to simplify this process. 但也许您知道如何处理一些生成操作系统的插件事件(例如Windows XP及更高版本)或其他如何简化此过程的方法。 Thank you for your time! 感谢您的时间!

This question appears to be half design, half implementation. 这个问题似乎是半设计,半实现。 It seems you're most concerned about finding some way for Java USB services like jUSB to service hotplug events from the system, allowing you to have an event called via inversion of control instead of running a thread that passionately and iteratively polls the system in the background. 看起来你最关心的是为jUSB等Java USB服务找到一些方法来为系统提供热插拔事件,允许你通过控制反转调用一个事件而不是运行一个热情地迭代地轮询系统的线程。背景。

The support you seek was implemented back in 2005 as JSR-80, and appears to live on, in the matter of all great projects that overstepped their commercial support, as javax-usb on SourceForge . 你寻求的支持在2005年作为JSR-80实现,并且在所有超越其商业支持的伟大项目的问题上似乎继续存在,就像SourceForge上的javax-usb Note that in their toy example (in javax-usb-example/src/ShowTopology.java ), their preferred model is still polling based. 请注意,在他们的玩具示例中(在javax-usb-example/src/ShowTopology.java ),他们的首选模型仍然是基于轮询的。

Not all is lost, however! 然而,并非所有人都失去了! In the properties file for javax.usb , we find this: javax.usb的属性文件中 ,我们发现:

# If polling should be used instead of waiting for a hotplug notification. #如果应该使用轮询而不是等待热插拔通知。

# Some kernel versions have a bug, and don't update the device node(s) until many seconds after waking up threads waiting on the devices file. #某些内核版本有一个错误,并且在唤醒等待设备文件的线程后几秒钟才更新设备节点。 If you are not getting hotplug events on a moderately to heavily loaded system, use polling. 如果您没有在中等负载系统上获得热插拔事件,请使用轮询。

# Note that since the new (buggy?) kernel behavior breaks javax.usb, this defaults to true! #注意,由于新的(buggy?)内核行为破坏了javax.usb,因此默认为true!

# If you know your kernel isn't broken you can set this to false. #如果您知道内核没有损坏,可以将其设置为false。

#com.ibm.jusb.os.linux.LinuxUsbServices.topologyUpdateUsePolling = true #com.ibm.jusb.os.linux.LinuxUsbServices.topologyUpdateUsePolling = true

And in javax-usb/src/javax/usb/event/UsbServicesListener.java , we see a model for setting up a USB event listener that you can proceed to use when a device is attached or detached from the system. javax-usb/src/javax/usb/event/UsbServicesListener.java ,我们看到了一个用于设置USB事件监听器的模型,您可以在设备连接或从系统分离时继续使用该模型。 No documentation is externally given on whether this works, however, and the docs themselves appear to be mostly 8 years old. 但是,外部没有提供关于这是否有效的文档,并且文档本身似乎大部分都是8年。

Therefore, it's reasonable assume that while the support theoretically exists, it's lagged, stale, and in desperate need of an update by the community. 因此,合理的假设虽然支持理论上存在,但它是滞后的,陈旧的,并且迫切需要社区更新。 This is the kind of thing that this fine community on SO could help fix, so I'll begin to close by pointing directly to the project itself. 这是SO上这个优秀社区可以帮助修复的事情,所以我将通过直接指向项目本身来开始关闭

For now, until enhanced hardware or hotplug support exists, polling is still the best solution. 目前,在存在增强的硬件或热插拔支持之前,轮询仍然是最佳解决方案。

( Additional reference implementation of javax-usb ) javax-usb附加参考实现

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM