【问题标题】:Hardware interrupt API for LinuxLinux 的硬件中断 API
【发布时间】:2012-11-07 04:17:15
【问题描述】:

当我要通过 USB 端口连接设备时,我想立即检测到它。 我正在寻找 Java API,我的主要目标是 Linux 操作系统。

有人知道这样的 API 吗?

【问题讨论】:

  • 我怀疑您需要轮询列出 USB 设备的命令。
  • @PeterLawrey 你能详细说明一下吗?有参考链接吗?

标签: java linux usb


【解决方案1】:

你可以这样做:

try {
    String command = "lsusb"; // you may add some param if you want
                              // or use adb for instance
    Process child = Runtime.getRuntime().exec(command);

    // Get output stream to write from it
    OutputStream out = child.getOutputStream();

    // TODO parsing lsusb output

    out.close();
} catch (IOException e) {
}

【讨论】:

  • 感谢您的回复。它检测到附加的鼠标。让我澄清一下我的情况,当我将 android 操作系统设备连接到我的机器时,我想触发一个事件,该事件将显示该设备已找到。
  • 尝试将lsusb 替换为adb devices | awk 'NR>1 {print $1}'。注意需要安装adb
【解决方案2】:

也会考虑通过 DBus 接口监控 USB 事件

有DBus-Java库here 和一个类似的线程,但在 python here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-28
    • 2016-02-09
    • 2011-06-12
    • 1970-01-01
    • 2014-11-28
    • 2011-06-22
    • 1970-01-01
    • 2014-08-01
    相关资源
    最近更新 更多