PicoScope 7 Software
Available on Windows, Mac and Linux
Code: Select all
#
# Copyright (C) 2018 Pico Technology Ltd. See LICENSE file for terms.
#
# PS4000 BLOCK MODE EXAMPLE
# This example opens a 4000 driver device, sets up two channels and a trigger then collects a block of data.
# This data is then plotted as mV against time in ns.
import ctypes
import numpy as np
from picosdk.ps4000 import ps4000 as ps
import matplotlib.pyplot as plt
from picosdk.functions import adc2mV, assert_pico_ok
import csv
import sys
# Create chandle and status ready for use
chandle = ctypes.c_int16()
status = {}
print('Opening picoscope 4000 series')
# Open 5000 series PicoScope
# Returns handle to chandle for use in future API functions
status["openunit"] = ps.ps4000OpenUnit(ctypes.byref(chandle))
assert_pico_ok(status["openunit"])
print('Configuring channel A')
# Set up channel A
# handle = chandle
# channel = PS4000_CHANNEL_A = 0
# enabled = 1
# coupling type = PS4000_DC = 1
# range = PS4000_2V = 7
chARange = ps.PS4000_RANGE['PS4000_100MV']
status["setChA"] = ps.ps4000SetChannel(chandle,
ps.PS4000_CHANNEL['PS4000_CHANNEL_A'],
1,
1,
chARange)
assert_pico_ok(status["setChA"])
print('Setting trigger')
# Set up single trigger
# handle = chandle
# enabled = 1
# source = PS4000_CHANNEL_A = 0
# threshold = 1024 ADC counts
# direction = PS4000_RISING = 2
# delay = 0 s
# auto Trigger = 1000 ms
status["trigger"] = ps.ps4000SetSimpleTrigger(chandle, 1, 0, 1024, 2, 0, 1000)
assert_pico_ok(status["trigger"])
# Set number of pre and post trigger samples to be collected
preTriggerSamples = 8000000
postTriggerSamples = 8000000
maxSamples = preTriggerSamples + postTriggerSamples
print('Setting sample interval')
# Get timebase information
# handle = chandle
# timebase = 8 = timebase (timebase of 0 = 100 ns sampling interval)
# noSamples = maxSamples
# pointer to timeIntervalNanoseconds = ctypes.byref(timeIntervalns)
# pointer to maxSamples = ctypes.byref(returnedMaxSamples)
# segment index = 0
timebase = 0
timeIntervalns = ctypes.c_float()
returnedMaxSamples = ctypes.c_int32()
oversample = ctypes.c_int16(1)
status["getTimebase2"] = ps.ps4000GetTimebase2(chandle, timebase, maxSamples, ctypes.byref(timeIntervalns), oversample, ctypes.byref(returnedMaxSamples), 0)
assert_pico_ok(status["getTimebase2"])
print('Capturing data')
Code: Select all
status["disableChB"] = ps.ps4000SetChannel(chandle,
ps.PS4000_CHANNEL['PS4000_CHANNEL_B'],
0,
1,
chBRange)
assert_pico_ok(status["disableChB"])