PicoScope 7 Software
Available on Windows, Mac and Linux
Code: Select all
while(True):
# Fetch data from the driver in a loop, copying it out of the registered buffers and into our complete
# one.
while nextSample < totalSamples and not autoStopOuter:
wasCalledBack = False
status["getStreamingLastestValues"] = ps.ps5000aGetStreamingLatestValues(chandle, cFuncPtr, None)
if not wasCalledBack:
# If we weren't called back by the driver, this means no data is ready. Sleep for a short while
# before trying again.
time.sleep(0.01)
# Print time
now = datetime.now()
print(now.strftime("%Y_%m_%d-%H_%M_%S.%f"))
Code: Select all
# -*- coding: cp1250 -*-
# Copyright (C) 2018-2019 Pico Technology Ltd. See LICENSE file for terms.
# PS5000 Series (A API) STREAMING MODE EXAMPLE
# This example demonstrates how to call the ps5000a driver API functions in order to open a device, setup 2 channels and collects streamed data (1 buffer).
# This data is then plotted as mV against time in ns.
import ctypes
import numpy as np
from picosdk.ps5000a import ps5000a as ps
import matplotlib.pyplot as plt
from picosdk.functions import adc2mV, assert_pico_ok
import time
from datetime import datetime
if __name__ == '__main__':
# Create chandle and status ready for use
chandle = ctypes.c_int16()
status = {}
# Open PicoScope 5000 Series device
# Resolution set to 12 Bit
resolution = ps.PS5000A_DEVICE_RESOLUTION["PS5000A_DR_15BIT"]
# Returns handle to chandle for use in future API functions
status["openunit"] = ps.ps5000aOpenUnit(ctypes.byref(chandle), None, resolution)
try:
assert_pico_ok(status["openunit"])
except: # PicoNotOkError:
powerStatus = status["openunit"]
if powerStatus == 286:
status["changePowerSource"] = ps.ps5000aChangePowerSource(chandle, powerStatus)
elif powerStatus == 282:
status["changePowerSource"] = ps.ps5000aChangePowerSource(chandle, powerStatus)
else:
raise
assert_pico_ok(status["changePowerSource"])
enabled = 1
disabled = 0
analogue_offset = 0.0
# Set up channel A
# handle = chandle
# channel = PS5000A_CHANNEL_A = 0
# enabled = 1
# coupling type = PS5000A_DC = 1
# range = PS5000A_2V = 7
# analogue offset = 0 V
channel_range = ps.PS5000A_RANGE['PS5000A_10V']
status["setChA"] = ps.ps5000aSetChannel(chandle,
ps.PS5000A_CHANNEL['PS5000A_CHANNEL_A'],
enabled,
ps.PS5000A_COUPLING['PS5000A_DC'],
channel_range,
analogue_offset)
assert_pico_ok(status["setChA"])
# Set up channel B
# handle = chandle
# channel = PS5000A_CHANNEL_B = 1
# enabled = 1
# coupling type = PS5000A_DC = 1
# range = PS5000A_2V = 7
# analogue offset = 0 V
channel_range = ps.PS5000A_RANGE['PS5000A_50MV']
status["setChB"] = ps.ps5000aSetChannel(chandle,
ps.PS5000A_CHANNEL['PS5000A_CHANNEL_B'],
enabled,
ps.PS5000A_COUPLING['PS5000A_DC'],
channel_range,
analogue_offset)
assert_pico_ok(status["setChB"])
# Size of capture
sizeOfOneBuffer = 500
numBuffersToCapture = 20
totalSamples = sizeOfOneBuffer * numBuffersToCapture
# Create buffers ready for assigning pointers for data collection
bufferAMax = np.zeros(shape=sizeOfOneBuffer, dtype=np.int16)
bufferBMax = np.zeros(shape=sizeOfOneBuffer, dtype=np.int16)
memory_segment = 0
# Set data buffer location for data collection from channel A
# handle = chandle
# source = PS5000A_CHANNEL_A = 0
# pointer to buffer max = ctypes.byref(bufferAMax)
# pointer to buffer min = ctypes.byref(bufferAMin)
# buffer length = maxSamples
# segment index = 0
# ratio mode = PS5000A_RATIO_MODE_NONE = 0
status["setDataBuffersA"] = ps.ps5000aSetDataBuffers(chandle,
ps.PS5000A_CHANNEL['PS5000A_CHANNEL_A'],
bufferAMax.ctypes.data_as(ctypes.POINTER(ctypes.c_int16)),
None,
sizeOfOneBuffer,
memory_segment,
ps.PS5000A_RATIO_MODE['PS5000A_RATIO_MODE_NONE'])
assert_pico_ok(status["setDataBuffersA"])
# Set data buffer location for data collection from channel B
# handle = chandle
# source = PS5000A_CHANNEL_B = 1
# pointer to buffer max = ctypes.byref(bufferBMax)
# pointer to buffer min = ctypes.byref(bufferBMin)
# buffer length = maxSamples
# segment index = 0
# ratio mode = PS5000A_RATIO_MODE_NONE = 0
status["setDataBuffersB"] = ps.ps5000aSetDataBuffers(chandle,
ps.PS5000A_CHANNEL['PS5000A_CHANNEL_B'],
bufferBMax.ctypes.data_as(ctypes.POINTER(ctypes.c_int16)),
None,
sizeOfOneBuffer,
memory_segment,
ps.PS5000A_RATIO_MODE['PS5000A_RATIO_MODE_NONE'])
assert_pico_ok(status["setDataBuffersB"])
# Begin streaming mode:
sampleInterval = ctypes.c_int32(20) # do budoucna 20
sampleUnits = ps.PS5000A_TIME_UNITS['PS5000A_US']
# We are not triggering:
maxPreTriggerSamples = 0
autoStopOn = 1
autoStopOff = 0
# No downsampling:
downsampleRatio = 1
status["runStreaming"] = ps.ps5000aRunStreaming(chandle,
ctypes.byref(sampleInterval),
sampleUnits,
maxPreTriggerSamples,
totalSamples,
autoStopOff,
downsampleRatio,
ps.PS5000A_RATIO_MODE['PS5000A_RATIO_MODE_NONE'],
sizeOfOneBuffer)
assert_pico_ok(status["runStreaming"])
actualSampleInterval = sampleInterval.value
actualSampleIntervalNs = actualSampleInterval * 1000
print("Capturing at sample interval %s ns" % actualSampleIntervalNs)
# We need a big buffer, not registered with the driver, to keep our complete capture in.
bufferCompleteA = np.zeros(shape=totalSamples, dtype=np.int16)
bufferCompleteB = np.zeros(shape=totalSamples, dtype=np.int16)
nextSample = 0
autoStopOuter = False
wasCalledBack = False
def streaming_callback(handle, noOfSamples, startIndex, overflow, triggerAt, triggered, autoStop, param):
global nextSample, autoStopOuter, wasCalledBack
wasCalledBack = True
destEnd = nextSample + noOfSamples
sourceEnd = startIndex + noOfSamples
# print(nextSample)
bufferCompleteA[nextSample:destEnd] = bufferAMax[startIndex:sourceEnd]
bufferCompleteB[nextSample:destEnd] = bufferBMax[startIndex:sourceEnd]
nextSample = nextSample + noOfSamples
if autoStop:
autoStopOuter = True
# Convert the python function into a C function pointer.
cFuncPtr = ps.StreamingReadyType(streaming_callback)
bufferCompleteA_total = []
bufferCompleteB_total = []
i = 0 # detekce prvniho prubehu
while(True): # neni potreba uzavirat, jenom pohlidat odsazeni
nextSample = 0
# Fetch data from the driver in a loop, copying it out of the registered buffers and into our complete one.
while nextSample < totalSamples and not autoStopOuter:
wasCalledBack = False
status["getStreamingLastestValues"] = ps.ps5000aGetStreamingLatestValues(chandle, cFuncPtr, None)
if not wasCalledBack:
# If we weren't called back by the driver, this means no data is ready. Sleep for a short while before trying
# again.
time.sleep(0.01)
# Find maximum ADC count value
# handle = chandle
# pointer to value = ctypes.byref(maxADC)
maxADC = ctypes.c_int16()
status["maximumValue"] = ps.ps5000aMaximumValue(chandle, ctypes.byref(maxADC))
assert_pico_ok(status["maximumValue"])
# Print time
now = datetime.now()
print(now.strftime("%Y_%m_%d-%H_%M_%S.%f"))
# Stop the scope
# handle = chandle
status["stop"] = ps.ps5000aStop(chandle)
assert_pico_ok(status["stop"])
# Disconnect the scope
# handle = chandle
status["close"] = ps.ps5000aCloseUnit(chandle)
assert_pico_ok(status["close"])
# Display status returns
# print(status)
print("Done.")