// Class to access the wrapper dll functions
public class PS2000JNIWrapAccessor
{
//Native methods
public native short ps2000OpenUnit();
public native short ps2000CloseUnit(short handle);
//Load our wrapper dll containing native code implementation
static
{
System.loadLibrary("PS2000JNIWrap");
}
public PS2000JNIWrapAccessor()
{
// Empty Constuctor
}
}
// Main class
public class PS2000
{
private PS2000JNIWrapAccessor ps2000JniWrapAccessor;
short ps2000Handle;
public PS2000()
{
// New instance of class with native methods
ps2000JniWrapAccessor = new PS2000JNIWrapAccessor();
// Call method to open unit
ps2000handle = ps2000JniWrapAccessor.ps2000OpenUnit();
System.out.println(“Handle: ” + handle);
}
public short getPs2000Handle()
{
return ps2000Handle;
}
public PS2000JNIWrapAccessor getPs2000JniWrapAccessor()
{
return ps2000JniWrapAccessor;
}
public static void main(String[] args)
{
PS2000 ps2000 = new PS2000();
// Perform some operations with the PicoScope...
// When finished, close the unit
short close_status = ps2000.getPs2000JniWrapAccessor().ps2000CloseUnit(ps2000.getPs2000Handle());
System.out.println("Exit status: " + close_status);
System.exit(0);
}
}
Build the dll and place it together with the ps2000.dll in a directory (add the location to your PATH environment variable) or alternatively add the dlls to the directory where your main class resides – you’re now ready to run the program!
I've successfully written and tested my first basic JNI wrapper for a basic C Library I wrote and compiled with MS Visual Studio 2012.
I've also successfully compiled and run the USBPT104con.c example program.
I have a few basic questions that will help me out with creating the java class and C implementation for my PT104 Usb logger after studying your example.
1. -The USB Pt 104 documentation lists the return type for the 9 listed methods as Pico_Status which is an "unsigned long".
- "Unsigned Longs" apparently are not supported in java.
- In your Picoscope C implementation (Part 5) you call the method "ps2000_open_unit()" is in a different naming
format, it has a "short" return type and contains no arguments as compared to the PT104 function documentation is
listed as the following "Pico_Status" return type (unsigned long) for method "UsbPt104OpenUnit( short * handle,
char * serial)".
* Due to the incompatibility of Java with the "unsigned long" type, did you define methods in another C file that isn't shown where you call the native Picoscope methods and return a simplified type "short" output that can be then passed through JNI into Java?
I'm hoping that from my attempts at getting some of this other stuff figured out I'm developing at least some understanding of what I need to do to implement the PT-104 libraries correctly.
The driver for the older PicoScope 2000 series devices does not use the PICO_STATUS data type but uses the short data type for return values.
If you are only dealing with 32-bit numbers, you can use the int data type - I used this for some initial work I did on Java code for the PicoScope 3000 series (A/B variants). I've attached my code below for reference - there is a jar file containing some reusable classes as well.
Thanks for the quick response.
I was hoping the solution wasn't going to be overly involved.
I'll be happy to share the code when I get done with it and I'm intending on doing a little write-up to go along with it.
I received your message a while ago asking if I had made progress in getting the JNI Wrapper working with respect to these posts. Unfortunately, i don't have the ability to reply to your message as the functionality appears to be disabled for my profile. I used the example libraries you posted and tried my best at converting them to work with the PT-104, unfortunately I've been swamped and haven't had the chance to write a basic C wrapper to try to test out my implementation of your libraries.
I'm hoping to be able to give it a try in the next month or so. I still have a few gray areas in my understanding of how to do this but i'm still hoping to get it figured out. I got a basic JNI wrapper to work previously but this is moderately more complicated so I expect it will take some more effort.
I would post my problem with SDK and JNI on a x64 PC.
I did the described steps in this post on a windows 32-bit machine in order to build my dll for the DrDaq and they work.
The problem came out when i did the same on a 64-bit machine.
Of course, in the 64-bit i have used the UsbDrDAQ.lib library placed in the x64 folder but in this case i have got the error
" Error 2 error LNK2019: unresolved external symbol _UsbDrDaqGetUnitInfo@20 referenced in function _Java_DrDaqDriver_DrDaqWrapper_init@8 C:\Users\Giovanni\documents\visual studio 2010\Projects\DrDaqDriverDll\DrDaqDriverDll\DrDaqDriverDll.obj DrDaqDriverDll"
I quite sure all the configuration are corrects (linker, builder, etc).