Python Rapid Block Adquisition Error

Post general discussions on using our drivers to write your own software here
Post Reply
diegocowes
Newbie
Posts: 0
Joined: Tue May 28, 2019 9:03 pm

Python Rapid Block Adquisition Error

Post by diegocowes »

Hello, i am trying to write a rapid block adquisition script in python 3.7 64 bit, using picoscope ps4227 and the 64 bit sdk. I encounter an error when calling the ps4000GetValuesBulk function. If i set fromSegmentIndex = 0 and toSegmentIndex = 8191 (all aquired segments) the script exits with the following code: -1073741819 (0xC0000005). However, if i set fromSegmentIndex = 50 and toSegmentIndex = 8191 the script runs normally. What could be the problem? I attached the code
PicoForum.py
(5.51 KiB) Downloaded 402 times

Code: Select all

import ctypes
from picosdk.ps4000 import ps4000 as ps
import matplotlib.pyplot as plt
from picosdk.functions import adc2mV, assert_pico_ok
import numpy as np
import time


# Create chandle and status ready for use
chandle = ctypes.c_int16()
status = {}

# 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"])

# Set up channel A
# handle = chandle
# channel = PS4000_CHANNEL_A = 0
# enabled = 1
# coupling type = PS4000_DC = 1
# range = PS4000_2V = 7
chARange = 7
status["setChA"] = ps.ps4000SetChannel(chandle, 0, 1, 1, chARange)
assert_pico_ok(status["setChA"])

# Set up channel B
# handle = chandle
# channel = PS4000_CHANNEL_B = 1
# enabled = 0
# coupling type = PS4000_DC = 1
# range = PS4000_2V = 7
chBRange = 7
status["setChB"] = ps.ps4000SetChannel(chandle, 1, 0, 1, chBRange)
assert_pico_ok(status["setChB"])

# 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 = 2500
# postTriggerSamples = 2500
# maxSamples = preTriggerSamples + postTriggerSamples
maxSamples = 3890

# Get timebase information
# handle = chandle
# timebase = 0 = timebase
# 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(0)
status["getTimebase2"] = ps.ps4000GetTimebase2(chandle, timebase, maxSamples, ctypes.byref(timeIntervalns), oversample, ctypes.byref(returnedMaxSamples), 0)
assert_pico_ok(status["getTimebase2"])

#sets the number of memory segments that the scope device will use
nSegments = 8192 # the number of segments to be used, from 1 to 8192
nMaxSamples=ctypes.c_int32()# returns the number of samples that are available in each segment.
status["memorySegments"] = ps.ps4000MemorySegments(chandle, nSegments, ctypes.byref(nMaxSamples))

# sets the number of captures to be collected in one run
nCaptures = nSegments #the number of waveforms to be captured in one run
status["noOfCaptures"] = ps.ps4000SetNoOfCaptures(chandle, nCaptures)

# Create buffers ready for assigning pointers for data collection
#Array de locaciones para guardar los buffers
#bufferLocations = np.zeros((nCaptures, maxSamples), dtype=np.int16)
bufferLocations=[0] * nCaptures
for r in range(0,nCaptures):
    bufferLocations[r] = (ctypes.c_int16 * maxSamples)()

time.sleep(4) #este delay hace que la transferencia sea mas rápida

# Run block capture
# handle = chandle
# number of pre-trigger samples = preTriggerSamples
# number of post-trigger samples = PostTriggerSamples
# timebase = 8 = 80 ns = timebase (see Programmer's guide for mre information on timebases)
# time indisposed ms = None (not needed in the example)
# segment index = 0
# lpReady = None (using ps4000IsReady rather than ps4000BlockReady)
# pParameter = None
status["runBlock"] = ps.ps4000RunBlock(chandle, 0, maxSamples, timebase, oversample, None, 0, None, None)
assert_pico_ok(status["runBlock"])

# Check for data collection to finish using ps4000IsReady
ready = ctypes.c_int16(0)
check = ctypes.c_int16(0)
while ready.value == check.value:
    status["isReady"] = ps.ps4000IsReady(chandle, ctypes.byref(ready))

for n in range(0, nCaptures):
    # allows the buffers to be set for each waveform
    # handle = chandle
    # source = PS4000_CHANNEL_A = 0
    # pointer to buffer max = ctypes.byref(bufferAMax)
    # buffer length = maxSamples
    #waveform = n qué captura le corresponde a qué locacion
    status["setDataBufferBulk"] = ps.ps4000SetDataBufferBulk(chandle, 0, ctypes.byref(bufferLocations[n]), maxSamples, n)
    assert_pico_ok(status["setDataBufferBulk"])

# create overflow loaction
overflow = ctypes.c_int16()
# create converted type maxSamples
cmaxSamples = ctypes.c_int32(maxSamples)

#allows more than one waveform to be retrieved at a time
# handle = chandle
# start index = 0
# pointer to number of samples = ctypes.byref(cmaxSamples)
# downsample ratio = 0
# downsample ratio mode = PS4000_RATIO_MODE_NONE
fromSegmentIndex = 1000
toSegmentIndex = maxSamples-1
# pointer to overflow = ctypes.byref(overflow))
status["getValuesBulk"] = ps.ps4000GetValuesBulk(chandle, ctypes.byref(cmaxSamples), fromSegmentIndex, toSegmentIndex, ctypes.byref(overflow))
assert_pico_ok(status["getValuesBulk"])

#find maximum ADC count value
#handle = chandle
#pointer to value = ctypes.byref(maxADC)
maxADC = ctypes.c_int16(32767)

# # convert ADC counts data to mV
adc2mVChAMax0 = adc2mV(bufferLocations[1000 ], chARange, maxADC)

# # Create time data
times = np.linspace(0, (cmaxSamples.value) * timeIntervalns.value, cmaxSamples.value)
plt.plot(times,adc2mVChAMax0)
plt.xlabel('Time (ns)')
plt.ylabel('Voltage (mV)')
plt.pause(0.001)
plt.show()

# Stop the scope
# handle = chandle
status["stop"] = ps.ps4000Stop(chandle)
assert_pico_ok(status["stop"])

# Close unit Disconnect the scope
# handle = chandle
status["close"] = ps.ps4000CloseUnit(chandle)
assert_pico_ok(status["close"])

# display status returns
print(status)

Post Reply