This post uses the API functions for the PicoScope 3000 series devices provided by the ps3000a.dll driver to provide some example code.
Requirements:
From the Software Development Kit for your device:
- Dynamic link library files for the device (e.g. ps3000a.dll and PicoIpp.dll)
- Header file ((in this case, ps3000aApi.h, for reference)
- Programmer’s Guide
- This example also uses the PicoScope.jar file from the following thread http://www.picotech.com/support/topic12887.html
- Latest Java Development Kit (JDK) -http://www.oracle.com/technetwork/java/ ... index.html
- Latest JNA jar file available from https://github.com/twall/jna
The first step is to define an interface which maps methods to the functions defined in the header file. Note the mapping of the data types.
Don’t forget the relevant import statements.
Code: Select all
import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.ptr.ShortByReference;
public interface PS3000aCLibrary extends Library
{
PS3000aCLibrary INSTANCE = (PS3000aCLibrary) Native.loadLibrary
("ps3000a", PS3000aCLibrary.class);
// API function definition :
// PICO_STATUS ps3000aEnumerateUnits(int16_t * count, int8_t * serials, int16_t serialLth)
int ps3000aEnumerateUnits(ShortByReference count, byte[] serials, ShortByReference serialLth);
// API function definition :
// PICO_STATUS ps3000aOpenUnit (int16_t * handle, int8_t * serial)
int ps3000aOpenUnit(ShortByReference handle, String serial);
// API function definition:
// PICO_STATUS ps3000aCloseUnit(int16_t handle);
int ps3000aCloseUnit(short handle);
// API function definition:
// PICO_STATUS ps3000aGetUnitInfo(int16_t handle, int8_t *string, int16_t stringLength,
// int16_t *requiredSize, PICO_INFO info)
int ps3000aGetUnitInfo(short handle, byte[] string, short stringLength, ShortByReference requiredSize, int info);
// API function definition:
//unit32_t ps3000aChangePowerSource(int16_t handle, PICO_STATUS powerstate)
int ps3000aChangePowerSource(short handle, int powerstate);
}
Below are some examples of calling code from within the main method of a class. The import statements are given below:
Import statements:
Code: Select all
import com.sun.jna.ptr.ShortByReference;
import com.picotech.picoscope.*;
import com.sun.jna.Native;
import java.io.UnsupportedEncodingException;
Code: Select all
System.out.println("Searching for PicoScope 3000 Series devices...");
ShortByReference countRef = new ShortByReference();
byte[] serials = new byte[100];
ShortByReference serialsLthRef = new ShortByReference();
serialsLthRef.setValue((short) 0);
int enumerateStatus = PS3000aCLibrary.INSTANCE.ps3000aEnumerateUnits(countRef, serials, serialsLthRef);
System.out.println("Enumerate status: " + enumerateStatus);
System.out.println("Count: " + countRef.getValue());
String deviceSerials = "";
try
{
deviceSerials = new String(serials, "UTF-8");
}
catch(UnsupportedEncodingException uee)
{
deviceSerials = "";
}
System.out.println("Serial number(s): " + deviceSerials);
System.out.println("Serials Lth: " + serialsLthRef.getValue());
Code: Select all
System.out.println("Opening PicoScope 3000 Series device ...");
ShortByReference handleRef = new ShortByReference();
handleRef.setValue((short) 0);
//String deviceSerial = "TEST/007"; // Serial number can be specified
String deviceSerial = null;
int openStatus = PicoStatus.PICO_OK;
try
{
openStatus = PS3000aCLibrary.INSTANCE.ps3000aOpenUnit(handleRef, deviceSerial);
}
catch(Exception e)
{
e.printStackTrace();
}
short handle = handleRef.getValue();
// Handle the power change for PicoScope 340XA/B, 340XDMSO and 3207A/B devices
if(openStatus == PicoStatus.PICO_POWER_SUPPLY_NOT_CONNECTED ||
openStatus == PicoStatus.PICO_USB3_0_DEVICE_NON_USB3_0_PORT)
{
int powerChangeStatus = PS3000aCLibrary.INSTANCE.ps3000aChangePowerSource(handle, openStatus);
}
System.out.println("Handle: " + handle);
Code: Select all
byte[] infoBytes = new byte[40];
ShortByReference reqSizeRef = new ShortByReference();
int driverInfoStatus = PS3000aCLibrary.INSTANCE.ps3000aGetUnitInfo(handle, infoBytes, (short) infoBytes.length, reqSizeRef, PicoInfo.PICO_DRIVER_VERSION);
String driverInfo = new String();
try
{
driverInfo = new String(infoBytes, "UTF-8");
}
catch(UnsupportedEncodingException uee)
{
driverInfo = "";
}
System.out.println("Driver: " + driverInfo);
reqSizeRef.setValue((short) infoBytes.length);
int variantInfoStatus = PS3000aCLibrary.INSTANCE.ps3000aGetUnitInfo(handle, infoBytes, (short) infoBytes.length, reqSizeRef, PicoInfo.PICO_VARIANT_INFO);
System.out.println("Variant: " + Native.toString(infoBytes));
Close the connection to the device:
Code: Select all
PS3000aCLibrary.INSTANCE.ps3000aCloseUnit(handle);
You may need to set the following JVM command at runtime:
Code: Select all
-Djna.nosys=true
Feel free to try this code and post code snippets in this forum area

Regards,