Java和HID通信 [英] Java and HID Communication

查看:653
本文介绍了Java和HID通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个简单的无线HID接口设备的Linux / Windows / Mac Java HID控制器。我对USB4Java LibUsb库进行了修改无济于事,而且我已经朝着JavaHIDAPI的方向转向。

I'm looking to write a Linux/Windows/Mac Java HID controller for a simple wireless HID interface device. I've tinkered around with the USB4Java LibUsb library to no avail, and I've been steered in the direction of the JavaHIDAPI.

不幸的是,我真的没有想法我正在做的事情超出了一个相当不错的高级编程技能集(C#/ VB.Net),切换到这就是杀了我。

Unfortunately for me, I really have no idea what I'm doing beyond a pretty decent higher level programming skill set (C#/VB.Net), and switching over to this is killing me.

方向,我发现我首先需要编译HIDAPI库找到此处。它说它会构建一个名为hidapi-jni.dll的东西(它没有)。

The directions that I found said that I would first need to compile the HIDAPI library found here. It said it would build something called hidapi-jni.dll (which it didn't).

无论如何,我认为这是我需要去的地方,因为HID确实如此只是简单地向无线控制器发送信号和从无线控制器接收信号(并响应收到的信号)。

Anyway, I think this is where I need to go since the HID does nothing but simply sends and receives signals to and from a wireless control (and responds to signals received).

是否有任何使用JavaHIDAPI的分步教程这个?还是有更好的图书馆? (我注意到这有点......过时了。)

Is there any step-by-step tutorial for using the JavaHIDAPI for this? Or is there a better library? (I noticed that this is a bit... dated).

我尝试了以下内容:

static{ System.loadLibrary("hidapi"); }
.
.
.
public static void main(string[] Args) throws . . . {    
    ClassPathLibraryLoader.loadNativeHIDLibrary();
    HIDDevice dev = HIDManager.getInstance().openById(VEND_ID, PROD_ID, null);
    .
    .
    .
}

我正在运行的问题是(除了HIDAPI之外)似乎没有构建到HIDAPI-jni.dll)是HIDManager.openById(...)总是返回null。另外,我移动了内置在C:... \ Java ... \ bin目录中的hidapi.dll ......或者其他什么,我确定它是正确的,因为没有任何不满意的链接错误。这真的很令人沮丧,因为似乎没有任何关于Java和HID的新手指南。

The issue into which I am running is that (besides the fact that the HIDAPI doesnt seem to be building into HIDAPI-jni.dll) is that the HIDManager.openById(. . .) always returns null. Also, I moved the hidapi.dll that was built into the C:...\Java...\bin directory... or something, I'm sure it's right because there wasn't any unsatisfied link error. It's really frustrating because there doesn't seem to be any newbies guide to Java and HID anywhere.

我在这里做错了什么?

推荐答案

所以我发现这个问题与本地库有关。
我能够通过从.jar文件复制.dll并引用它来使应用程序工作,但更重要的是,我将重建负责加载库的.java类文件并添加

So the issue, I discovered, was with native libraries. I was able to get the application to work by copying the .dll from the .jar file and referencing it, but more important, I'm going to rebuild the .java class file responsible for loading the library and add the

System.loadLibrary();

致电。当调用 JavaHidApi ClassPathLibraryLoader.loadNativeHIDLibrary(); 方法时,它不会在成功写入库时加载库临时文件有点烦人。这样做将消除从静态位置手动加载库的必要性......

call. When the JavaHidApi ClassPathLibraryLoader.loadNativeHIDLibrary(); method is called it doesn't load the library upon successfully writing it out to the temp file which is mildly annoying. Doing this will eliminate the necessity for manually loading the library from a static location...

感谢您指出我正确的方向。

Thank you for pointing me in the correct direction.

这篇关于Java和HID通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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