PicoScope 7 Software
Available on Windows, Mac and Linux
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);
}
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));
Code: Select all
PS3000aCLibrary.INSTANCE.ps3000aCloseUnit(handle);
Code: Select all
-Djna.nosys=true
Code: Select all
// uint32_t ps3000aSetChannel(int16_t handle, PS3000A_CHANNEL channel, short enabled, PS3000A_COUPLING type, PS3000A_RANGE range, float analogueOffset)
int ps3000aSetChannel(short handle, int channel, short enabled, int type, int range, float analogueOffset);
Code: Select all
public enum PS3000AChannel
{
PS3000A_CHANNEL_A,
PS3000A_CHANNEL_B,
PS3000A_CHANNEL_C,
PS3000A_CHANNEL_D,
PS3000A_EXTERNAL
}
public enum PS3000ACoupling
{
PS3000A_AC,
PS3000A_DC
}
public enum PS3000ARange
{
PS3000A_10MV,
PS3000A_20MV,
PS3000A_50MV,
PS3000A_100MV,
PS3000A_200MV,
PS3000A_500MV,
PS3000A_1V,
PS3000A_2V,
PS3000A_5V,
PS3000A_10V,
PS3000A_20V,
PS3000A_50V,
PS3000A_MAX_RANGES
}
Code: Select all
int channel = PS3000aCLibrary.PS3000AChannel.PS3000A_CHANNEL_A.ordinal();
short enabled = 1;
int coupling = PS3000aCLibrary.PS3000ACoupling.PS3000A_DC.ordinal();
int range = PS3000aCLibrary.PS3000ARange.PS3000A_5V.ordinal();
float offset = 0.0f;
// Set a channel
int setChannelStatus = PS3000aCLibrary.INSTANCE.ps3000aSetChannel(handle, channel, enabled, coupling, range, offset);
Code: Select all
// uint32_t ps3000aGetTimebase2(int16_t handle, uint32_t timebase, int32_t noSamples, float //*timeIntervalNanoseconds, int16_t oversample, int32_t *maxSamples, uint32_t segmentIndex)
int ps3000aGetTimebase2(short handle, int timebase, int noSamples, FloatByReference timeIntervalNanoseconds, short oversample, IntByReference maxSamples, int segmentIndex);
Code: Select all
int timebase = 0;
int numSamples = 1024; // Set to total number of samples required
FloatByReference timeIntervalNsRef = new FloatByReference();
timeIntervalNsRef.setValue((float) 0.0);
short oversample = 1; // Do not change this value
IntByReference maxSamplesRef = new IntByReference();
maxSamplesRef.setValue(0);
int segmentIndex = 0;
int getTimebase2Status = 14; // Initialise to PICO_INVALID_TIMEBASE
// Loop until a valid timebase has been found
while(getTimebase2Status != 0)
{
getTimebase2Status = PS3000aCLibrary.INSTANCE.ps3000aGetTimebase2(handle, timebase, numSamples, timeIntervalNsRef, oversample, maxSamplesRef, segmentIndex);
if(getTimebase2Status == 0)
{
break;
}
else
{
timebase = timebase + 1;
}
}
System.out.println("Timebase: " + timebase);
System.out.println("Time interval: " + timeIntervalNsRef.getValue());
System.out.println("Max Samples: " + maxSamplesRef.getValue());