Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with a Java wrapper for NIDAQmxBase (using JNI and Linux)

Hello all! I need a little help 🙂

I'm trying to wrapp the C calls to NIDAQmxBase into Java calls, using JNI, but the thing seems doesn't work as expected.

The JNI C code compiles great but the NIDAQmxBase functions calls seems to behave different when called from the JVM as when they are called from a native executable.

For example, the function DAQmxBaseCreateTask (as in the following example)

    uInt32 status = -1;
    TaskHandle taskHandle = 0;

    printf("before: status=%d, taskHandle=%d \n", status, taskHandle);
    status = DAQmxBaseCreateTask ("", &taskHandle);
    printf("aftet:  status=%d, taskHandle=%d \n", status, taskHandle);


works great in native (compiled C) apps, printing
    
before: status=-1, taskHandle=0
after:  status=0, taskHandle=##########


i.e. the status is 0 (Ok) and the taskHandle has changed for a number (the address or something similar, I guess),
 but when executed from JNI I get

before: status=-1, taskHandle=0
after:  status=0, taskHandle=0


so the taskHandle doesn't change despite of the status is 0 (Ok? I don't think so)

I don't have any idea of why this could occur, because is suppoused that the method can't know if is called from a JVM or from a native app.

Maybe the java.policy or the JNI wrapper library generation (some kind of linking problem)?

The program doesn't give any error ... it simply the DAQmxBaseCreateTask that behaves incorrectly (really strange!!)

Well, sure I'm doing something bad because some people seems to manage to get JNI working with NIDAQ.

If more information is needed I'll be pleased to give 🙂

Thanks in advance!
0 Kudos
Message 1 of 20
(9,100 Views)
I answer to myself to add a set of files to replicate the problem, that also checked in Windows, where seems to work without problem, so maybe it only affects to Linux version of DAQmx Base 2.0 ... I don't know.

Please, anyone that work with Java+Linux+NIDAQmxBase please try the example and tell my your results. The attached zip file includes a Makefile so I think that it doesn't take much of your time.

Thanks in advance! 🙂

Miguel Ángel
0 Kudos
Message 2 of 20
(9,082 Views)
I forget to note that the physical device is a USB NI-6009 Multifunction DAQ

That is the reason, the USB interface, to use the NIDAQmx Base library instead of the NIDAQmx library, as it is explained at this article in NI Knowledge Base:

http://digital.ni.com/public.nsf/allkb/B799ECFA57266A2986256974005482C6
0 Kudos
Message 3 of 20
(9,075 Views)

You might try looking at www.jniwrapper.com for a head start.  At some point I'll be needing to get/make JNI wrappers for DAQmx and could use some clues.  Did you make all yours by hand?

Also, here's a clipping that might help you:

-Stosh

 

Hi Francesco,

I am doing something similar. In my case I am wrapping nidaqmxbase.dll in another dll for access from Java (JNI). After doing everything outlined in dplamp's reply (#14), this is gcc command line that is working fine for me:

gcc -mno-cygwin -Wl,--add-stdcall-alias -I"C:\Program Files\Java\jdk1.5.0_06\jreinclude" -I"C:\Program Files\Java\jdk1.5.0_06\include\win32" -I"C:\Program Files\National Instruments\NI-DAQmx Base\Include" -L"C:\Program Files\National Instruments\NI-DAQmx Base\Lib" somefile.c -lnidaqmxbase -shared -o mydaqmxbase.dll


The -mno-cygwin is just so that I don't depend on cygwin1.dll. The -lnidaqmxbase (or libdaqmxibase.a) is the library prepared using instructions and scripts from dmplam's earlier reply. The -add-stdcall-alias is the trick that makes it work (see stadel's earlier reply #5 and also good overview from David Caldwell). Naturally, if you are not building JNI code you should remove related -I"..Java.." arguments.

I hope that this will help...

Regards,
Vladimir

 

0 Kudos
Message 4 of 20
(9,047 Views)
Actually, I managed successfully on Windows (using Mingw32, I think ...), so the post you references (which is a  hint on Windows compilation using Cygwin) is not valid for Linux.

If you are interested in the Windows JNI wrapper, tell me and I'll post my code. I'll did it with the JDK tools and DevC++.

The www.jniwrapper.com is a propietary tool, so I'm not sure to use it, although I perhaps try it ...

See you!

Miguel Ángel

0 Kudos
Message 5 of 20
(9,028 Views)
Hi Maht,
 
I would greatly appreaciate any JNI code, regarding NIDAQ posted.
 
With kind regards
 
Arnoud
0 Kudos
Message 6 of 20
(8,977 Views)
Hi ,
I am also hoping to use the NI-DAQmx drivers from java on windows. Does not seem like a straightforward task. Would it be possible for you to post your code?

Thanks for your help,
Satriani
0 Kudos
Message 7 of 20
(8,812 Views)
Hi,

I developped a JNI interface with Daqmx on windows that works great.
I try to adapt that on linux with DAQmx base and it doesn't work anymore.

I began to think that it's impossible to use daqmx base with JNI on linux ... Is everyone as ever achieve to do that ?
Should I begin to look for an alternative ?
0 Kudos
Message 8 of 20
(8,205 Views)
I change the code given above to make another exemple.

I use the same C code compiled 2 times, to have exe and .so version.

If I run exe, it prints reel values, if I call the .so from JNI its prints 0

To use the zip :
dezipp, make, ./JniDAQmxBase && java JniDAQmxBase
Download All
0 Kudos
Message 9 of 20
(8,201 Views)
Hello Franxois,
Did you find a solution to the issue of the jni 0 DAQmxBaseCreateTask issue?
I'm in a similiar situation, and am hoping not to create a DIO service from C since I already have one in java.
Regards,
Ranoxerox.
0 Kudos
Message 10 of 20
(8,031 Views)