PicoScope 7 Software
Available on Windows, Mac and Linux
Code: Select all
//Set up channel A
int channelA = PS2000ACLibrary.PS2000A_CHANNEL.PS2000A_CHANNEL_A.ordinal();
short enabledA = 1;
int typeA = PS2000ACLibrary.PS2000A_COUPLING.PS2000A_DC.ordinal();
int rangeA = PS2000ACLibrary.PS2000A_RANGE.PS2000A_2V.ordinal();
float analogOffsetA = 0.0f;
int setChannelReturnA = PS2000ACLibrary.INSTANCE.ps2000aSetChannel(handle, channelA, enabledA, typeA, rangeA, analogOffsetA);
//Set channel B
int channelB = PS2000ACLibrary.PS2000A_CHANNEL.PS2000A_CHANNEL_B.ordinal();
short enabledB = 1;
int typeB = PS2000ACLibrary.PS2000A_COUPLING.PS2000A_DC.ordinal();
int rangeB = PS2000ACLibrary.PS2000A_RANGE.PS2000A_2V.ordinal();
float analogOffsetB = 0.0f;
int setChannelReturnB = PS2000ACLibrary.INSTANCE.ps2000aSetChannel(handle, channelB, enabledB, typeB, rangeB, analogOffsetB);
Code: Select all
// Get timebase
// If we want 40 Hz => 1/40KHz = 25000 ns
// 2500 ns * 62500000 + 2 = 1564.5 ns
int timebase = 760;
int noOfPreTriggerSamples = 5000;
int noOfPostTriggerSamples = 5000;
int noSamples = noOfPreTriggerSamples + noOfPostTriggerSamples;
FloatByReference timeIntervalNsRef = new FloatByReference();
timeIntervalNsRef.setValue((float) 0.0);
short oversample = 0;
IntByReference maxSamplesRef = new IntByReference();
maxSamplesRef.setValue(0);
int segmentIndex = 0;
int getTimebase2Status = PicoStatus.PICO_INVALID_TIMEBASE;
// Loop until a valid timebase has been found
while (getTimebase2Status != PicoStatus.PICO_OK) {
getTimebase2Status = PS2000ACLibrary.INSTANCE.ps2000aGetTimebase2(handle, timebase, noSamples, timeIntervalNsRef, oversample, maxSamplesRef, segmentIndex);
if (getTimebase2Status == PicoStatus.PICO_OK) {
break;
} else {
timebase = timebase + 1;
}
}
Code: Select all
// Running block
IntByReference timeIndisposedMs = new IntByReference();
int runBlockStatus = PS2000ACLibrary.INSTANCE.ps2000aRunBlock(handle, noOfPreTriggerSamples, noOfPostTriggerSamples, timebase, oversample, timeIndisposedMs, segmentIndex, null, null);
// Wait until the oscilloscope is ready
System.out.println("Collecting data...");
ShortByReference ready = new ShortByReference();
while (ready.getValue() == 0) // 1 for data collection done
{
int isReadyStatus = PS2000ACLibrary.INSTANCE.ps2000aIsReady(handle, ready);
}
Code: Select all
// Set bufferA
Pointer bufferAMax = new Memory(noSamples * Native.getNativeSize(Short.TYPE));
Pointer bufferAMin = new Memory(noSamples * Native.getNativeSize(Short.TYPE));
for (int n = 0; n < noSamples; n++) {
bufferAMax.setShort(n * Native.getNativeSize(Short.TYPE), (short) 0);
bufferAMin.setShort(n * Native.getNativeSize(Short.TYPE), (short) 0);
}
int ratioModeA = PS2000ACLibrary.PS2000A_MODE.PS2000A_RATIO_MODE_NONE.ordinal();
int setDataBuffersStatusA = PS2000ACLibrary.INSTANCE.ps2000aSetDataBuffers(handle, channelA, bufferAMax, bufferAMin, noSamples, segmentIndex, ratioModeA);
// Set bufferB
Pointer bufferBMax = new Memory(noSamples * Native.getNativeSize(Short.TYPE));
Pointer bufferBMin = new Memory(noSamples * Native.getNativeSize(Short.TYPE));
for (int n = 0; n < noSamples; n++) {
bufferBMax.setShort(n * Native.getNativeSize(Short.TYPE), (short) 0);
}
int ratioModeB = PS2000ACLibrary.PS2000A_MODE.PS2000A_RATIO_MODE_NONE.ordinal();
int setDataBuffersStatusB = PS2000ACLibrary.INSTANCE.ps2000aSetDataBuffers(handle, channelB, bufferBMax, bufferBMin, noSamples, segmentIndex, ratioModeB);
Code: Select all
// Get values
int startIndex = 0;
IntByReference noOfSamples = new IntByReference(noSamples);
int downSampleRatio = 0;
int downSampleRatioMode = PS2000ACLibrary.PS2000A_MODE.PS2000A_RATIO_MODE_NONE.ordinal();
ShortByReference overflow = new ShortByReference();
int getValueReturn = PS2000ACLibrary.INSTANCE.ps2000aGetValues(handle, startIndex, noOfSamples, downSampleRatio, downSampleRatioMode, segmentIndex, overflow);
Code: Select all
public enum PS2000A_MODE
{
PS2000A_RATIO_MODE_NONE,
PS2000A_MODE_AGGREGATE,
PS2000A_RATIO_MODE_AVERAGE,
PS2000A_RATIO_MODE_DECIMATE
}
Code: Select all
///
/// Various methods of data reduction.
/// Note that a single call to setting the buffers (ie. ps2000aSetDataBuffer) can only
/// associate one buffer with one downsampling mode. If you intend to retrieve more than one
/// downsampling mode from the get values functions, you must call set data buffer several
/// times to associate a separate buffer with each channel and downsampling mode.
///
typedef enum enPS2000ARatioMode
{
///
/// No downsampling. Returns the raw data values.
///
PS2000A_RATIO_MODE_NONE,
///
/// Reduces every block of n values to just two values: a minimum and a maximum.
/// The minimum and maximum values are returned in two separate buffers.
///
PS2000A_RATIO_MODE_AGGREGATE = 1,
///
/// Reduces every block of n values to a single value representing the
/// average (arithmetic mean) of all the values.
///
PS2000A_RATIO_MODE_DECIMATE = 2,
///
/// Reduces every block of n values to just the first value in the block,
/// discarding all the other values.
///
PS2000A_RATIO_MODE_AVERAGE = 4,
} PS2000A_RATIO_MODE;