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.
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.
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).
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).
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).
I tried myself with the following:
static{ System.loadLibrary("hidapi"); }
.
.
.
public static void main(string[] Args) throws . . . {
ClassPathLibraryLoader.loadNativeHIDLibrary();
HIDDevice dev = HIDManager.getInstance().openById(VEND_ID, PROD_ID, null);
.
.
.
}
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.
What am I doing wrong here?
I'm a bit late to answer this question, but I've written a library called hid4java that might solve your problem.
It's based on Java Native Access (JNA) which is a lot simpler than faffing about with complex JNI incantations.
I had to write it because javahidapi is out of date and the underlying signal11/hidapi code has moved on considerably. The older versions of the hidapi library had problems on OS X with attach/detach events which have now been fixed so an upgrade is necessary.
Also I found it impossible to claim a USB HID device through usb4java on OS X so I ended up writing this library to solve that problem.
Hope it helps.
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();
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.
Related
Problem: 20% of users are receiving:
Fatal Exception: java.lang.UnsatisfiedLinkError
No implementation found for java.lang.String com.example.utils.API.getHashString(android.content.Context) (tried Java_com_example_utils_API_getHashString and Java_com_example_utils_API_getHashString__Landroid_content_Context_2)
For other 80% app working perfectly, no exception on my test devices as well.
Can't figure out what's the problem.
EDIT1:
Library loads perfectly on splash screen. No exception on that point.
static { System.loadLibrary("my-lib"); }
EDIT2:
Just reproduced the error. It is absolutely random. App function call works fine, and at some time it starts failing. The only fix is re-installing the app.
Following my comment and later comments from #stanislav-parkhomenko, I'm reposting it as an answer. Thanks!
My comment:
Where is the static {...} block located? A possible reason for this could be that the code is not executed before some calls.
And later confirmed by himself that this was the cause:
The problem was in library initialization. Splash screen run not always, because of sharing functionality, thats why some times library did not load.
Thanks to Xavier Rubio Jansana for advice, which cured my blindness.
Glad it helped!
This error is caused by method signature mismatch between Java and native library you are loading. It is likely that 20% of users have different version of library file with same name. If it is your own library try giving it relatively unique name and load it from absolute path to reduce chance of name conflict.
It looks like it's trying to load a native library, and there isn't support in Android Gradle for native code yet. You should double-check the docs for your library to confirm; I tried to look it up but it looks like it's a commercial library without publicly accessible docs.
You could just put the .so files into jniLibs folder in src/main. This was introduced in AS 0.7.2
As a sample, see this from #CommonsWare, or see this page for official samples (scroll to the bottom of page)
Yes Still no support for native library in Android gradle.Just I followed simple hack.It works great.Check this
My end goal is to get a JPG from a fingerprint scanner inside my Java application. I don't need to do any recognition or logins.
I have a Topaz IDGem LCD 1x5 signature pad / fingerprint scanner. The SDK they provide for the fingerprint scanner part of the device is called SigIDp1. The problem is that it is only available as an ActiveX control.
I know next to nothing about ActiveX. From my research, I seem to need a Java to COM bridge to interact with the ActiveX control through Java. The JACOB project seems to be the most well known. My problem is that I can't seem to make it work with this particular ActiveX control file.
My super advanced Java program looks like this:
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
public class JacobTest {
public static void main(String[] args) {
Dispatch test = new ActiveXComponent("SigIDp.SigIDp1");
Dispatch.call(test, "CreateJpg");
}
}
The problem is that when I try to create the new ActiveXComponent object, I get a com.jacob.com.ComFailException: Can’t co-create object error. According to this page, it looks like this has to do with the .ocx file not being properly registered. However, I can't use the referenced .NET tool (i.e. RegAsm.exe) to register the control because I get an error saying it's not a valid .NET assembly. And, when I use regsvr32.exe to register it, registration seems to succeed, but I still get the can't co-create error (I've tried the regsvr32.exe in System32 and in SysWOW64).
All that to say, I'm pretty stuck. I'm open to any suggestion that will help me achieve the end goal, even if it's start over with friendlier hardware (although I'm having trouble finding any fingerprint scanner with a free Java SDK).
For anyone else that stumbles upon this:
It turns out that it was an architecture issue after all. The ActiveX control in question seems to only be available in 32 bit form. So, it didn't matter which version of regsvr32.exe I used to try to register it because (as far as I understand) an app running in a 64 bit JRE can't interact with a 32 bit ActiveX control.
The "solution" for me was to use a 32 bit JRE for my project. It's not ideal, but at least I'm moving forward now.
I have no Java experience and prefer Visual Basic; I've found a very nice translation IDE called Basic4android (www.basic4android.com). It works by interpreting a scripting language that's similar to Visual Basic and then using it to generate and compile native Java code. Rather ingenious, if you ask me. In fact I believe I found it from a reference here on StackOverflow.
I'm having some trouble wrapping PayPal's Mobile Payments Library:
www.x.com/community/ppx/xspaces/mobile/mep (scroll down for the HTML Tutorial)
I need to do it in a way that promotes the library's functionality so that B4A can in turn expose it to the Android device (emulator in this case). I've made some halting progress so far, but now I'm stuck on NullPointerExceptions occurring deep within the MPL.
The saga is pretty well described in a thread at their forum:
http://www.basic4ppc.com/forum/additional-libraries-official-updates/8819-looking-download-link.html
Here's my wrapper and the generated code—download here—as only licensed users may access downloads in that particular forum section.
The latest NullPointerException occurs a few calls down from the initWithAppID function. The JD-GUI decompiler reports an internal error when it gets to the com.paypal.android.b.b class, so it doesn't appear to be possible to know exactly what's going on down there.
I'm certain this can be done; I just need to know how to open the proper communication channel between the device and the MPL.
I'm new at Java and I'm new at Android. Quite a combination, wouldn't you say?
It turns out the problem is in the way PayPal bundles their resource files; non-Eclipse projects can't get at them.
More info on the original B4A thread.
Thanks,
Jeff
I think if you ask here about something that generates code for you, you won't be provided with any answers because you can't give any useful source code or something. Also, if you use something like this tool, you never know what it's generating. Also, you can't fix any occurring errors with the generated code... I could go on and on and on...
If you want to use Android the way it's supposed to be used, you'll need to learn Java and Android. If you are good with VB, this shouldn't be that hard. And this is what anyone is going to tell you.
from time to time I am haunted by the "org.eclipse.swt.SWTError: No more handles". I already know tools like GDIView, to watch the number of handles allocated, but now I wonder if there is a better way to do this.
Is there a tool available? Maybe one that logs all stacktraces when handles are created? And which shows the new handles between two invocation points?
Regards,
Daniel
PS: Added the windows tag because dev occures mostly on windows and a windows only tool would be good enough.
I found out about Sleak, a great tool to debug SWT resources! Highly recommended for everyone with the same problems. Even shows the images for image resources!
For me the issue was simply that new Shell() has been called too often. Storing the shell as static member and reusing it helped. Therefore, before applying a tool like Sleak, others might want to do a full text search for "new Shell" and check that they don't have the same simple cause.
I'm trying to build a pipeline with gst-launch in Windows 7 that will view a stream from a VC500 Video Capture device (Captures composite video and inputs to computer via USB). I think my biggest issue here is the fact that it MUST be done in Windows. I'm finding a lot of the plugins for gstreamer-java are supported in Linux instead of Windows. So I'm having issues finding the element and syntax to get this working. Any help would be greatly appreciated. Another thing is I don't have to use the gstreamer framework for this, it just seems to be the easiest. If anyone knows another good media framework with good Java bindings that might be better let me know? Haha. (Tried DirectShow, VLCJ, neither are very stable for Java.)
Thanks a lot.
Brayden
EDIT:
From more reading I'm pretty sure the element I need here is ksvideosrc.
So I've been trying:
gst-launch -v ksvideosrc ! autovideosink
But I get:
ERROR: from element
/GSTPipeline:pipeline0/GstKsVideoSrc:ksvideosrc0:
could not start capture Additional
debug info:
..........\Source\gst-plugins-bad\sys\winks\gstvideosrc.c(970):
gst_ks_video_src_create ():
/GstPipeline:pipeline0/GstKsVideoSrc:ksvideosrc0:failed
to change pin state to KSSTATE_RUN
Execution ended after 1000000 ns.
Alright well.. I ended up using Direct Show Java (dsj) instead. It was able to play video from the capture device very easily.