使用Java HID API打开HID设备时出现NullPointerException(管理来自多个键盘的输入) [英] NullPointerException when opening HID Device using Java HID API (Managing Inputs from Multiple Keyboards)

查看:242
本文介绍了使用Java HID API打开HID设备时出现NullPointerException(管理来自多个键盘的输入)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题可能与重复这个这个主题。但由于他们都没有为我的问题提供明确的解决方案,我再次问它。

This question is a possible duplicate of this and this thread. But since none of them have provided a clear solution for my problem, I'm asking it again.

我需要的任务是通过USB连接2个键盘,然后管理通过Java应用程序分别输入每个键盘。此要求已在中取得了一些进展。我在上面提到的第一个帖子是@nan,但是他的解决方案并没有准确地为我工作。你可以在他的解决方案上找到他的博客文章这里。他使用 java-hid-api 完成了解决方案,看起来准确且有效。

My required task is to connect 2 Keyboards via USB and then manage the inputs of each Keyboard separately through a Java Application. This requirement has been answered into some progress in the first thread I have mentioned above by @nan but his solution did not work accurately for me. You can find his blog post on his solution for this here. He has done the solution using the java-hid-api and it seems accurate and working.

然而我所困的是打开HID设备。当我尝试使用 openByPath()使用 HIDManager 打开设备时openById()方法只返回n​​ull,因此抛出 NullPointerException 。当我使用 HIDDeviceInfo open()方法尝试时,它是一样的。在java-hid-api页面中此问题已列出,但到目前为止似乎没有人看到已经提供了一个可行的解决方案。

However the point I am stuck in it is at opening the HID Device. When I try to open the Device using the HIDManager using either the openByPath() or the openById() methods it returns only null and therefore it throws the NullPointerException. it is the same when I try it using the open() method of HIDDeviceInfo. this issue is listed in the java-hid-api page too but so far no one seems to have provided a working solution.

我正在开发的操作系统是Windows 7 32位

The OS I'm working on is Windows 7 32-bit

以下是我打开HID设备的所有3次尝试

Here are all the 3 attempts I've made to open the HID Device


  1. HIDDevice hidDevice = HIDManager .getInstance()。openByPath(hidDeviceInfo.getPath());

HIDDevice hidDevice = HIDManager。 getInstance()。openById(hidDeviceInfo.getVendor_id(),hidDeviceInfo.getProduct_id(),hidDeviceInfo.getSerial_number());

HIDDevice hidDevice = hidDeviceInfo.open();

有有人能够解决这个问题吗?如果是这样,我们非常感谢您的帮助。

Has anyone been able to get through this problem? If so your help is highly appreciated.

谢谢!

更新1:我刚刚发现,根据@paul提供的答案,可以使用 JInput 完成此任务此主题中的-whelan。我现在要尝试,但我在这里首先寻求任何确认或指导,如果有人已经知道并完成了它。

Update 1: I just found out that this task could be accomplished with JInput, according to the answer provided by @paul-whelan in this thread. I am going to try it now but I'm stating here first seeking for any confirmation or a guide on how to do it if anyone already knows and have accomplished it.

推荐答案

这是初始化库的方法:

ClassPathLibraryLoader.loadNativeHIDLibrary();
HIDManager hm=HIDManager.getInstance();

然后你可以阅读设备等:

Then you can read the devices etc:

HIDDeviceInfo[] dvl = hm.listDevices();
for (HIDDeviceInfo dv:dvl){
    System.out.println(dv.getManufacturer_string());        
}

这篇关于使用Java HID API打开HID设备时出现NullPointerException(管理来自多个键盘的输入)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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