更新USB设备列表 [英] Update list of usb devices

查看:178
本文介绍了更新USB设备列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建自动更新usb设备列表的模块(不仅是大容量存储)。现在它非常粗鲁 - 它有额外的线程,在1秒后更新设备列表。但也许您知道如何处理一些生成操作系统的插件事件(例如Windows XP及更高版本)或其他如何简化此过程的方法。谢谢你的时间!

解决方案

这个问题似乎是半设计,半实现。您似乎最关心的是为Java USB服务找到一些方法,例如 jUSB 从系统服务热插拔事件,允许您通过反转进行调用控制而不是运行一个线程,在后台热情地和迭代地轮询系统。



你寻求的支持早在2005年作为JSR-80实施,并且似乎继续存在,就所有超越的超级项目而言它们的商业支持, 的javax-USB 在SourceForge 。注意,在他们的玩具实例(在 javax-usb-example / src / ShowTopology.java ),他们的首选模型仍然是基于轮询的。



然而,并非所有都丢失了!在 javax.usb的属性文件中 ,我们发现:


#如果应该使用轮询而不是等待热插拔
通知。



#某些内核版本有一个错误,并且在唤醒后很多秒才更新设备节点,直到
等待设备文件的线程。
如果你没有在适度负载系统上获得热插拔事件,
使用轮询。



#请注意,因为新的(错误? )内核行为破坏javax.usb,这默认
为true!



#如果你知道你的内核没有损坏你可以将其设置为false。 / p>

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




和在 javax-usb / src / javax / usb / event / UsbServicesListener.java ,我们看到一个用于设置USB事件的模型您可以在设备连接或从系统分离时继续使用的侦听器。外部没有关于此是否有效的文档,然而,文档本身似乎大部分都是8年。



因此,这是合理的假设虽然支持理论上存在,但它是滞后的,陈旧的,并且迫切需要社区更新。这是SO上这个优秀社区可以帮助修复的事情,所以我将开始关闭指向直接到项目本身。



目前,在存在增强的硬件或热插拔支持之前,轮询仍然是最好的解决方案。



'p>(附加参考实现的的javax-USB


I want create module which update list of usb devices automatically (not only mass storage). Now it works very rude - it has additional thread, which after 1 second update list of devices. 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. 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.

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. Note that in their toy example (in javax-usb-example/src/ShowTopology.java), their preferred model is still polling based.

Not all is lost, however! In the properties file for javax.usb, we find this:

# 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!

# If you know your kernel isn't broken you can set this to false.

#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. No documentation is externally given on whether this works, however, and the docs themselves appear to be mostly 8 years old.

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.

For now, until enhanced hardware or hotplug support exists, polling is still the best solution.

(Additional reference implementation of javax-usb)

这篇关于更新USB设备列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆