Data Collection issue in / PicoScope 6403A / Python 2.7 / Windows 10

Forum for discussing PicoScope version 6 (non-automotive version)
Post Reply
ishoro13
Newbie
Posts: 0
Joined: Thu Feb 02, 2017 5:27 pm

Data Collection issue in / PicoScope 6403A / Python 2.7 / Windows 10

Post by ishoro13 » Thu May 02, 2019 11:29 am

Dear Support,

Genral info:
Hardware: PicoScope 6403A
Software: Spyder Python 2.7
OS: Windows 10
PicoSDK: 10.6.12 (64-bit) https://www.picotech.com/downloads/_li ... -kit-64bit
Picosd python wrappers: https://github.com/picotech/picosdk-python-wrappers



Inputs:
I wrote a very basic script to return the data as an array of voltage values for the channel 'A'.
The channel 'A' is self-triggered.

The input signal for channel 'A' is:
  • 1MHz sinewave
  • with 200mVpp amplitude
  • and burst period of 5us.
The output signal is attached.

The code to get the output is attached and shown below:

Code: Select all

from __future__ import division
from picoscope import ps6000
from pylab import *
import numpy as np;
import sys

picoscope = ps6000.PS6000(connect=True);
VRange = 500e-3;

sampleInterval = 1e-9;
pic_duration = 20e-6;

threshold_V = 0.1;

picoscope.setChannel('A', 'AC', VRange , 0.0, enabled=True, BWLimited=True); #?!
# Set the number of memory segments equal to or greater than the number of captures required.
(scopeSampleRate, scopeNumPoints, maxSamples) = picoscope.setSamplingInterval(sampleInterval, pic_duration)
# Self-trigger signal Channel A
picoscope.setSimpleTrigger('A', threshold_V, 'Rising',delay = 0);

pico_time = np.linspace(0,pic_duration*1e6,scopeNumPoints)

def dataV():
	#Run a single block.
	picoscope.runBlock();
	#Block until the scope is ready.
	picoscope.waitReady()
	#Return the data as an array of voltage values
	dataV = picoscope.getDataV('A', scopeNumPoints);
	#dataV = picoscope.getDataRaw('A', scopeNumPoints)[0];
	return dataV

for i in range (1000):

	data = dataV();
	sys.stdout.write('\r'+(str(i+1) +'/'+str(1000)+' '))
	plot(pico_time,data);xlabel('Time (us)');ylabel('Amplitude (V)');grid(True);title((str(i+1) +'/'+str(1000)));show()

del picoscope
The issue and need help with:
After several iterations (it varies between 15 up to 500), the PicoScope stops obtaining the data.

My attempts to solve the problem:
I have tried the different function "getDataV", "getDataRaw", and "segmented getDataRawBulk" it crushes all the time after several interactions.
I have checked the overflow flag and it is 'False'.
I have tried to increase the time delay to 1 second and didn't help either.

Could anyone please give me a pointer on what I need to do in order to prevent PicoScope from crashing?

Best Regards,
I.
Attachments
ToAsk.py
(1.27 KiB) Downloaded 53 times
Singal.png

ishoro13
Newbie
Posts: 0
Joined: Thu Feb 02, 2017 5:27 pm

Re: Data Collection issue in / PicoScope 6403A / Python 2.7 / Windows 10

Post by ishoro13 » Wed May 08, 2019 8:29 am

Dear @Martyn or @Pico Stuart,

It is been almost a week since I asked the question, moreover, I sent an e-mail to support@picotech.com but haven't received any feedback.

Would you mind to give any feedback regarding my issue?

Best Regards,
Ivan

NeilH
PICO STAFF
PICO STAFF
Posts: 145
Joined: Tue Jul 18, 2017 8:28 am

Re: Data Collection issue in / PicoScope 6403A / Python 2.7 / Windows 10

Post by NeilH » Wed May 08, 2019 9:02 am

Hi

I'm currently looking through your code and need some more information to understand it.
Where does your picoscope import come from?
Also you seem to be using functions on your picoscope object that don't exist within the picosdk-python-wrappers repository, where are these defined?

Neil
Neil
Technical Support Engineer

ishoro13
Newbie
Posts: 0
Joined: Thu Feb 02, 2017 5:27 pm

Re: Data Collection issue in / PicoScope 6403A / Python 2.7 / Windows 10

Post by ishoro13 » Wed May 08, 2019 9:11 am

Hi NeilH,

Just realized I was using the wrapper made by: "Colin O'Flynn and Mark Harfouche".
Link to the wrapper is: https://github.com/colinoflynn/pico-python

NeilH
PICO STAFF
PICO STAFF
Posts: 145
Joined: Tue Jul 18, 2017 8:28 am

Re: Data Collection issue in / PicoScope 6403A / Python 2.7 / Windows 10

Post by NeilH » Wed May 08, 2019 9:15 am

Hi

We don't support that wrapper as it wasn't created by us.

Have you tried using our wrapper for controlling the scope, if you're using this wrapper then we can assist you. https://github.com/picotech/picosdk-python-wrappers

If you're wanting to continue using the wrapper by Colin O'Flynn and Mark Harfouche then for support resolving this you'll need to contact them. https://github.com/colinoflynn/pico-python/issues

Neil
Neil
Technical Support Engineer

ishoro13
Newbie
Posts: 0
Joined: Thu Feb 02, 2017 5:27 pm

Re: Data Collection issue in / PicoScope 6403A / Python 2.7 / Windows 10

Post by ishoro13 » Wed May 08, 2019 9:22 am

Hi NeilH,

Thank you.
I'll be using the suggested wrapper.

ishoro13
Newbie
Posts: 0
Joined: Thu Feb 02, 2017 5:27 pm

Re: Data Collection issue in / PicoScope 6403A / Python 2.7 / Windows 10

Post by ishoro13 » Wed May 08, 2019 11:11 am

@NeilH,

The issue still remains the same even when using the suggested wrapper:

Code: Select all

#
# Copyright (C) 2018 Pico Technology Ltd. See LICENSE file for terms.
#
# PS6000 BLOCK MODE EXAMPLE
# This example opens a 6000 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.ps6000 import ps6000 as ps
import matplotlib.pyplot as plt
from picosdk.functions import adc2mV, assert_pico_ok
import sys


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

# Open 6000 series PicoScope
# Returns handle to chandle for use in future API functions
status["openunit"] = ps.ps6000OpenUnit(ctypes.byref(chandle), None)
assert_pico_ok(status["openunit"])

# Set up channel A
# handle = chandle
# channel = PS6000_CHANNEL_A = 0
# enabled = 1
# coupling type = PS6000_DC = 1
# range = PS6000_2V = 7
# analogue offset = 0 V
# bandwidth limiter = PS6000_BW_FULL = 0
chARange = 7
status["setChA"] = ps.ps6000SetChannel(chandle, 0, 1, 1, chARange, 0, 0)
assert_pico_ok(status["setChA"])

# Set up channel B
# handle = chandle
# channel = PS6000_CHANNEL_B = 1
# enabled = 1
# coupling type = PS6000_DC = 1
# range = PS6000_2V = 7
# analogue offset = 0 V
# bandwidth limiter = PS6000_BW_FULL = 0
chBRange = 10
status["setChB"] = ps.ps6000SetChannel(chandle, 1, 1, 1, chBRange, 0, 0)
assert_pico_ok(status["setChB"])

# Set up single trigger
# handle = chandle
# enabled = 1
# source = PS6000_CHANNEL_B = 1
# threshold = 64 ADC counts
# direction = PS6000_RISING = 2
# delay = 0 s
# auto Trigger = 100 ms
status["trigger"] = ps.ps6000SetSimpleTrigger(chandle, 1, 1, 2560, 2, 0, 100)
assert_pico_ok(status["trigger"])

# Set number of pre and post trigger samples to be collected
preTriggerSamples = 0
postTriggerSamples = 2500
maxSamples = preTriggerSamples + postTriggerSamples

# Get timebase information
# handle = chandle
# timebase = 8 = timebase
# noSamples = maxSamples
# pointer to timeIntervalNanoseconds = ctypes.byref(timeIntervalns)
# oversample = 1
# pointer to maxSamples = ctypes.byref(returnedMaxSamples)
# segment index = 0
timebase = 2
timeIntervalns = ctypes.c_float()
returnedMaxSamples = ctypes.c_int32()
status["getTimebase2"] = ps.ps6000GetTimebase2(chandle, timebase, maxSamples, ctypes.byref(timeIntervalns), 1, ctypes.byref(returnedMaxSamples), 0)
assert_pico_ok(status["getTimebase2"])

# Run block capture
# handle = chandle
# number of pre-trigger samples = preTriggerSamples
# number of post-trigger samples = PostTriggerSamples
# timebase = 8 = 80 ns (see Programmer's guide for mre information on timebases)
# oversample = 0
# time indisposed ms = None (not needed in the example)
# segment index = 0
# lpReady = None (using ps6000IsReady rather than ps6000BlockReady)
# pParameter = None
l = 2000;
for i in range(l):

	status["runBlock"] = ps.ps6000RunBlock(chandle, preTriggerSamples, postTriggerSamples, timebase, 0, None, 0, None, None)
	assert_pico_ok(status["runBlock"])

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

	# Create buffers ready for assigning pointers for data collection
	bufferAMax = (ctypes.c_int16 * maxSamples)()
	bufferAMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example
	bufferBMax = (ctypes.c_int16 * maxSamples)()
	bufferBMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example

	# Set data buffer location for data collection from channel A
	# handle = chandle
	# source = PS6000_CHANNEL_A = 0
	# pointer to buffer max = ctypes.byref(bufferAMax)
	# pointer to buffer min = ctypes.byref(bufferAMin)
	# buffer length = maxSamples
	# ratio mode = PS6000_RATIO_MODE_NONE = 0
	status["setDataBuffersA"] = ps.ps6000SetDataBuffers(chandle, 0, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), maxSamples, 0)
	assert_pico_ok(status["setDataBuffersA"])

	# Set data buffer location for data collection from channel B
	# handle = chandle
	# source = PS6000_CHANNEL_B = 1
	# pointer to buffer max = ctypes.byref(bufferBMax)
	# pointer to buffer min = ctypes.byref(bufferBMin)
	# buffer length = maxSamples
	# ratio mode = PS6000_RATIO_MODE_NONE = 0
	status["setDataBuffersB"] = ps.ps6000SetDataBuffers(chandle, 1, ctypes.byref(bufferBMax), ctypes.byref(bufferBMin), maxSamples, 0)
	assert_pico_ok(status["setDataBuffersB"])

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

	# Retried data from scope to buffers assigned above
	# handle = chandle
	# start index = 0
	# pointer to number of samples = ctypes.byref(cmaxSamples)
	# downsample ratio = 1
	# downsample ratio mode = PS6000_RATIO_MODE_NONE
	# pointer to overflow = ctypes.byref(overflow))

	status["getValues"] = ps.ps6000GetValues(chandle, 0, ctypes.byref(cmaxSamples), 1, 0, 0, ctypes.byref(overflow))
	assert_pico_ok(status["getValues"])


	# find maximum ADC count value
	maxADC = ctypes.c_int16(32512)

	# convert ADC counts data to mV
	adc2mVChAMax =  adc2mV(bufferAMax, chARange, maxADC)
	adc2mVChBMax =  adc2mV(bufferBMax, chBRange, maxADC)

	sys.stdout.write('\r'+(str(i+1) +'/'+str(l)))

	# Create time data
	time = np.linspace(0, (cmaxSamples.value) * timeIntervalns.value, cmaxSamples.value)

	# plot data from channel A and B
	plt.plot(time, adc2mVChAMax[:])
	plt.plot(time, adc2mVChBMax[:])
	plt.xlabel('Time (ns)')
	plt.ylabel('Voltage (mV)')
	plt.show()

status["stop"] = ps.ps6000Stop(chandle)
assert_pico_ok(status["stop"])

# Close unitDisconnect the scope
# handle = chandle
ps.ps6000CloseUnit(chandle)

# display status returns
print(status) 
The input signal is:
  • 1MHz sinewave,
  • 1Vpp amplitude,
  • Burst period: 1.5us
  • Trigger level: 900mV
The screenshot from the Inout signla parramters is attached.

Output signal is attahced
Attachments
Output Signal.png

NeilH
PICO STAFF
PICO STAFF
Posts: 145
Joined: Tue Jul 18, 2017 8:28 am

Re: Data Collection issue in / PicoScope 6403A / Python 2.7 / Windows 10

Post by NeilH » Wed May 08, 2019 12:28 pm

Where exactly in the script does it fail? Do you get any error codes?
Neil
Technical Support Engineer

ishoro13
Newbie
Posts: 0
Joined: Thu Feb 02, 2017 5:27 pm

Re: Data Collection issue in / PicoScope 6403A / Python 2.7 / Windows 10

Post by ishoro13 » Wed May 08, 2019 12:38 pm

The code stuck in the ps6000IsReady loop.

It ordered to see the error I have to interrupt the code

Code: Select all

  File "C:/Users/..../Windows/PicoScope/picosdk-python-wrappers-master/picosdk-python-wrappers-master/ps6000Examples/ps6000Block2.py", line 99, in 
    status["isReady"] = ps.ps6000IsReady(chandle, ctypes.byref(ready))

KeyboardInterrupt

NeilH
PICO STAFF
PICO STAFF
Posts: 145
Joined: Tue Jul 18, 2017 8:28 am

Re: Data Collection issue in / PicoScope 6403A / Python 2.7 / Windows 10

Post by NeilH » Thu May 09, 2019 6:39 am

What is producing the signal that you're trying to collect?
Are you able to get the capture to work in PicoScope 6 using the same settings as you're using in python?

Also what happens if you move this line
ready = ctypes.c_int16(0)
before calling runBlock?
Neil
Technical Support Engineer

ishoro13
Newbie
Posts: 0
Joined: Thu Feb 02, 2017 5:27 pm

Re: Data Collection issue in / PicoScope 6403A / Python 2.7 / Windows 10

Post by ishoro13 » Thu May 09, 2019 9:01 am

Good morning @NeilH,

I have tried to move the "ready = ctypes.c_int16(0)" as following, the problem still remains the same:

Code: Select all

ready = ctypes.c_int16(0)
	status["runBlock"] = ps.ps6000RunBlock(chandle, preTriggerSamples, postTriggerSamples, timebase, 0, None, 0, None, None)
The input signal is produced by the Keysight Waveform Generator (33600A series), photo of the generator's settings is attached.
Attachments
Input_Singal2.png
Input_Singal2.png (137.48 KiB) Viewed 1003 times

NeilH
PICO STAFF
PICO STAFF
Posts: 145
Joined: Tue Jul 18, 2017 8:28 am

Re: Data Collection issue in / PicoScope 6403A / Python 2.7 / Windows 10

Post by NeilH » Thu May 09, 2019 10:42 am

I've tried to reproduce what you've been seeing and have been unable to do so.

Are there any other applications running when you're doing this?
Are any other devices using the USB bus while this is running?
What are you doing with the graph each time its plotted?
Neil
Technical Support Engineer

ishoro13
Newbie
Posts: 0
Joined: Thu Feb 02, 2017 5:27 pm

Re: Data Collection issue in / PicoScope 6403A / Python 2.7 / Windows 10

Post by ishoro13 » Thu May 09, 2019 11:07 am

Applications running: spyder (python 2.7).
Devices using the USB bus: PicoScope (6000) only.
Currently, I plotting it to see the real-time output from the waveform generator.
Even if I would disable the graph plotting (as in the script below) the scope still freezes:

Code: Select all

#
# Copyright (C) 2018 Pico Technology Ltd. See LICENSE file for terms.
#
# PS6000 BLOCK MODE EXAMPLE
# This example opens a 6000 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.ps6000 import ps6000 as ps
import matplotlib.pyplot as plt
from picosdk.functions import adc2mV, assert_pico_ok
import sys


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

# Open 6000 series PicoScope
# Returns handle to chandle for use in future API functions
status["openunit"] = ps.ps6000OpenUnit(ctypes.byref(chandle), None)
assert_pico_ok(status["openunit"])

# Set up channel A
# handle = chandle
# channel = PS6000_CHANNEL_A = 0
# enabled = 1
# coupling type = PS6000_DC = 1
# range = PS6000_2V = 7
# analogue offset = 0 V
# bandwidth limiter = PS6000_BW_FULL = 0
chARange = 7
status["setChA"] = ps.ps6000SetChannel(chandle, 0, 1, 1, chARange, 0, 0)
assert_pico_ok(status["setChA"])

# Set up channel B
# handle = chandle
# channel = PS6000_CHANNEL_B = 1
# enabled = 1
# coupling type = PS6000_DC = 1
# range = PS6000_2V = 7
# analogue offset = 0 V
# bandwidth limiter = PS6000_BW_FULL = 0
chBRange = 10
status["setChB"] = ps.ps6000SetChannel(chandle, 1, 1, 1, chBRange, 0, 0)
assert_pico_ok(status["setChB"])

# Set up single trigger
# handle = chandle
# enabled = 1
# source = PS6000_CHANNEL_B = 1
# threshold = 64 ADC counts
# direction = PS6000_RISING = 2
# delay = 0 s
# auto Trigger = 100 ms
status["trigger"] = ps.ps6000SetSimpleTrigger(chandle, 1, 1, 2560, 2, 0, 100)
assert_pico_ok(status["trigger"])

# Set number of pre and post trigger samples to be collected
preTriggerSamples = 0
postTriggerSamples = 2500
maxSamples = preTriggerSamples + postTriggerSamples

# Get timebase information
# handle = chandle
# timebase = 8 = timebase
# noSamples = maxSamples
# pointer to timeIntervalNanoseconds = ctypes.byref(timeIntervalns)
# oversample = 1
# pointer to maxSamples = ctypes.byref(returnedMaxSamples)
# segment index = 0
timebase = 2
timeIntervalns = ctypes.c_float()
returnedMaxSamples = ctypes.c_int32()
status["getTimebase2"] = ps.ps6000GetTimebase2(chandle, timebase, maxSamples, ctypes.byref(timeIntervalns), 1, ctypes.byref(returnedMaxSamples), 0)
assert_pico_ok(status["getTimebase2"])

# Run block capture
# handle = chandle
# number of pre-trigger samples = preTriggerSamples
# number of post-trigger samples = PostTriggerSamples
# timebase = 8 = 80 ns (see Programmer's guide for mre information on timebases)
# oversample = 0
# time indisposed ms = None (not needed in the example)
# segment index = 0
# lpReady = None (using ps6000IsReady rather than ps6000BlockReady)
# pParameter = None
l = 2500;
for i in range(l):

	status["runBlock"] = ps.ps6000RunBlock(chandle, preTriggerSamples, postTriggerSamples, timebase, 0, None, 0, None, None)
	assert_pico_ok(status["runBlock"])

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

	# Create buffers ready for assigning pointers for data collection
	bufferAMax = (ctypes.c_int16 * maxSamples)()
	bufferAMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example
	bufferBMax = (ctypes.c_int16 * maxSamples)()
	bufferBMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example

	# Set data buffer location for data collection from channel A
	# handle = chandle
	# source = PS6000_CHANNEL_A = 0
	# pointer to buffer max = ctypes.byref(bufferAMax)
	# pointer to buffer min = ctypes.byref(bufferAMin)
	# buffer length = maxSamples
	# ratio mode = PS6000_RATIO_MODE_NONE = 0
	status["setDataBuffersA"] = ps.ps6000SetDataBuffers(chandle, 0, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), maxSamples, 0)
	assert_pico_ok(status["setDataBuffersA"])

	# Set data buffer location for data collection from channel B
	# handle = chandle
	# source = PS6000_CHANNEL_B = 1
	# pointer to buffer max = ctypes.byref(bufferBMax)
	# pointer to buffer min = ctypes.byref(bufferBMin)
	# buffer length = maxSamples
	# ratio mode = PS6000_RATIO_MODE_NONE = 0
	status["setDataBuffersB"] = ps.ps6000SetDataBuffers(chandle, 1, ctypes.byref(bufferBMax), ctypes.byref(bufferBMin), maxSamples, 0)
	assert_pico_ok(status["setDataBuffersB"])

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

	# Retried data from scope to buffers assigned above
	# handle = chandle
	# start index = 0
	# pointer to number of samples = ctypes.byref(cmaxSamples)
	# downsample ratio = 1
	# downsample ratio mode = PS6000_RATIO_MODE_NONE
	# pointer to overflow = ctypes.byref(overflow))

	status["getValues"] = ps.ps6000GetValues(chandle, 0, ctypes.byref(cmaxSamples), 1, 0, 0, ctypes.byref(overflow))
	assert_pico_ok(status["getValues"])


	# find maximum ADC count value
	maxADC = ctypes.c_int16(32512)

	# convert ADC counts data to mV
	adc2mVChAMax =  adc2mV(bufferAMax, chARange, maxADC)
	adc2mVChBMax =  adc2mV(bufferBMax, chBRange, maxADC)

	sys.stdout.write('\r'+(str(i+1) +'/'+str(l)))
'''
	# Create time data
time = np.linspace(0, (cmaxSamples.value) * timeIntervalns.value, cmaxSamples.value)

	# plot data from channel A and B
plt.plot(time, adc2mVChAMax[:])
plt.plot(time, adc2mVChBMax[:])
plt.xlabel('Time (ns)')
plt.ylabel('Voltage (mV)')
plt.show()
'''
status["stop"] = ps.ps6000Stop(chandle)
assert_pico_ok(status["stop"])

# Close unitDisconnect the scope
# handle = chandle
ps.ps6000CloseUnit(chandle)

# display status returns
print(status)

Post Reply