SWT: Getting notified of a system device change (USB device connection / disconnection)

泄露秘密 提交于 2019-12-03 15:23:29

EDIT: J-16 SDiZ reported that the API exists for Windows too

Here is a very good article about Access USB devices from Java applications

The described jUSB module contains a USBListener object.

Interface implemented by objects that want to monitor USB structure. The order in which these changes are reported is not necessarily going to be the order in which the changes were seen in the real world, and delays also occur.

Youre SWt object can implement this listener and do something, when the method

deviceAdded(Device dev) 

is fired

Java does not provide direct interaction with the devices and with USB. There are several third-party libraries for Java that provide USB-related features (read/write from USB port). For example: http://www.icaste.com/ (commercial)

Your comment for Zorglub suggests that you have some (presumably) JNI/JNA code to call the 3rd party DLL you mentioned. I assume you could also write a JNI wrapper to the Windows API where you can register to be notified for the _WM_DEVICECHANGE_ event you mentioned.

There is a jUSB port for windows at http://www.steelbrothers.ch/jusb/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!