Streaming with Python

Post general discussions on using our drivers to write your own software here
Post Reply
Reynaulu
User
User
Posts: 4
Joined: Tue Nov 20, 2018 12:37 pm

Streaming with Python

Post by Reynaulu »

Hello all,

I am not familiar with Python and programming with Picoscope. I would like to write a python program in order to record long sets of data (~1hour). I have a Picoscope2206BMSO for starting but I will soon move to a Picoscope 4262 if everything goes well.

Therefore I would like to use a streaming function, and somehow save all the data (time and volt) in a convenient format if possible (.txt or .csv ?). Does that sound possible ?


I started to download PicoSDK and the wrapper from the official picotech github (https://github.com/picotech/picosdk-python-wrappers) but there is no streaming example.
I found the deprecated github https://github.com/picotech/picosdk-python-examples and tried the stream_capture.py but it doesn't work (ModuleNotFoundError: No module named 'exceptions').
I found another Github from a member of this community, Mr Bentham https://github.com/jbentham/picostream where there was a streaming function. I tried it a couple of time and it works but I don't know how to save the data recorded from that software.

Did anyone tried to do streaming and record the data in a format that can be used later ?

Bests !

zipcode
Newbie
Posts: 0
Joined: Wed Dec 05, 2018 8:54 am

Re: Streaming with Python

Post by zipcode »

I am also having problems with streaming in Python. I'm stuck with the callback function.
First I defined the callback function as:

Code: Select all

@CFUNCTYPE(None, c_int16,c_int32,c_uint32,c_int16,c_uint32,c_int16,c_int16,c_int32) 
def callBackStreaming(handle,noOfSamples,startIndex,overflow,triggerAt,triggered,autoStop,pParameter):
	pass
Than I make the call from the GetStreamingLatestValues as:

Code: Select all

m = ps.ps4000aGetStreamingLatestValues(self.handle, callBackStreaming, byref(pCallBack))
I get the following error:

m = ps.ps4000aGetStreamingLatestValues(self.handle, callback, c_void_p())
ctypes.ArgumentError: argument 2: : wrong type

Does someone have any idea what I am doing wrong?

zipcode
Newbie
Posts: 0
Joined: Wed Dec 05, 2018 8:54 am

Re: Streaming with Python

Post by zipcode »

Where do you problems with https://github.com/jbentham/picostream ?

vincenthuh
Newbie
Posts: 0
Joined: Fri Feb 08, 2019 11:07 am

Re: Streaming with Python

Post by vincenthuh »

hello I have the same request with you.
I read the same github project too.
I need to save the data from pico-6 software to .csv file. The data is not big, maybe 10M.
I want to find a save function when encounter with a trigger .
I am not sure that if the block function or the streaming function would have a conflict with the software.

zipcode
Newbie
Posts: 0
Joined: Wed Dec 05, 2018 8:54 am

Re: Streaming with Python

Post by zipcode »

Streaming mode with python looks like is not available for now.

calaset
Newbie
Posts: 0
Joined: Mon Mar 25, 2019 7:41 pm

Re: Streaming with Python

Post by calaset »

Hi all,

I'm hopping on this thread because I've been trying to set up python streaming with a digital trigger in python. I'm using a 5443D, and my code is in python 2.7, and my machine is running Ubuntu 16.

I've successfully set up the digital trigger, and it works with block mode.

I've modified the code from https://github.com/jbentham/picostream/ ... ostream.py
for my application and I've successfully gotten it to stream data in my setup.

I'm attempting to use the triggered and triggeredAt flags in my callback function, but the triggered flag never becomes nonzero.

For reference my callback function is:

Code: Select all

@ctypes.CFUNCTYPE(None, ctypes.c_int16, ctypes.c_int32, ctypes.c_uint32, ctypes.c_int16, ctypes.c_uint32, ctypes.c_int16, ctypes.c_int16, ctypes.c_int32)
def callback_py2(handle, nSamples, startIdx, overflow, triggerAt, triggered, autoStop, param):
    # Update global variables
    global block_offset, block_samples, sample_count, called_back, trigger_flag, overflow_flag

    if overflow != 0:
        
        overflow_flag = True
    
    
    if triggered != 0:
        
        trigger_flag = True
        
        block_offset, block_samples, trig_offset = startIdx, nSamples, triggerAt

        srce_addr = ctypes.addressof(bufferA) + block_offset*2 + trig_offset*2
        dest_addr = ctypes.addressof(data_buffer) + sample_count*2
        ctypes.memmove(dest_addr, srce_addr, block_samples*2)
        sample_count += block_samples
        called_back = True
If you have any input on how to use the trigger with streaming, please let me know.

Thank you,
Mark

Anders_Eriksson
Newbie
Posts: 0
Joined: Fri Nov 15, 2019 10:09 am

Re: Streaming with Python

Post by Anders_Eriksson »

Hi!
I have a 3204D MSO scope.
I have been experimenting with ps3000aStreamingExample.py
and added digital trig on bit D5 negativ edge
chA has a triangle waveform with 1Hz, +- 200mv pk-pk, blue signal
chB is connect with a 10times probe to the same digital waveform that is connected to D5 (3.3V => approx 330mV), red (or perhaps orange)
D5 * 100 + 100 is the green signal

Sampling at 1Mhz for 1sec, trigger position 40%

Hope this can be helpful, I would like more examples of this kind of more "advanced features" .

Thanks,
Anders




I have attached the complete code, but below are some "key parts" where I have also removed "the diagnostic logging".
Note especially how the "triggerAt" param is used :
nextSample -= triggerAt

Thanks to this (in my test; the triggeAt had the value of 2091) the trigger position is correct within a sample, that can be seen in the attached "zoomin_at_trigger_pos_40_percent.png"

from collections import deque
bufferCompleteA = deque(np.zeros(shape=totalSamples, dtype=np.int16), maxlen=totalSamples)
bufferCompleteB = deque(np.zeros(shape=totalSamples, dtype=np.int16), maxlen=totalSamples)
bufferCompleteDPort0 = deque(np.zeros(shape=totalSamples, dtype=np.int16), maxlen=totalSamples)


def streaming_callback(handle, noOfSamples, startIndex, overflow, triggerAt, triggered, autoStop, param):
global nextSample, autoStopOuter, wasCalledBack, post_trig
wasCalledBack = True
if triggered:
post_trig = True
nextSample -= triggerAt

sourceEnd = startIndex + noOfSamples
bufferCompleteA.extend(bufferAMax[startIndex:sourceEnd])
bufferCompleteB.extend(bufferBMax[startIndex:sourceEnd])
bufferCompleteDPort0.extend(bufferDPort0Max[startIndex:sourceEnd])
if autoStop:
autoStopOuter = True

if post_trig or nextSample < maxPreTriggerSamples:
nextSample += noOfSamples


streaming_with_digital_trig.PNG
Attachments
zoomin_at_trigger_pos_40_percent.PNG
ps3000aStreamingExample.py
(14.78 KiB) Downloaded 551 times

MuffinKing1337
Newbie
Posts: 0
Joined: Sun Apr 19, 2020 6:58 pm

Re: Streaming with Python

Post by MuffinKing1337 »

Anders_Eriksson wrote:
Wed Apr 15, 2020 12:49 pm
Hi!
I have a 3204D MSO scope.
I have been experimenting with ps3000aStreamingExample.py
and added digital trig on bit D5 negativ edge
chA has a triangle waveform with 1Hz, +- 200mv pk-pk, blue signal
chB is connect with a 10times probe to the same digital waveform that is connected to D5 (3.3V => approx 330mV), red (or perhaps orange)
D5 * 100 + 100 is the green signal

Sampling at 1Mhz for 1sec, trigger position 40%

Hope this can be helpful, I would like more examples of this kind of more "advanced features" .

Thanks,
Anders




I have attached the complete code, but below are some "key parts" where I have also removed "the diagnostic logging".
Note especially how the "triggerAt" param is used :
nextSample -= triggerAt

Thanks to this (in my test; the triggeAt had the value of 2091) the trigger position is correct within a sample, that can be seen in the attached "zoomin_at_trigger_pos_40_percent.png"

from collections import deque
bufferCompleteA = deque(np.zeros(shape=totalSamples, dtype=np.int16), maxlen=totalSamples)
bufferCompleteB = deque(np.zeros(shape=totalSamples, dtype=np.int16), maxlen=totalSamples)
bufferCompleteDPort0 = deque(np.zeros(shape=totalSamples, dtype=np.int16), maxlen=totalSamples)


def streaming_callback(handle, noOfSamples, startIndex, overflow, triggerAt, triggered, autoStop, param):
global nextSample, autoStopOuter, wasCalledBack, post_trig
wasCalledBack = True
if triggered:
post_trig = True
nextSample -= triggerAt

sourceEnd = startIndex + noOfSamples
bufferCompleteA.extend(bufferAMax[startIndex:sourceEnd])
bufferCompleteB.extend(bufferBMax[startIndex:sourceEnd])
bufferCompleteDPort0.extend(bufferDPort0Max[startIndex:sourceEnd])
if autoStop:
autoStopOuter = True

if post_trig or nextSample < maxPreTriggerSamples:
nextSample += noOfSamples



streaming_with_digital_trig.PNG
I've been trying to set up python streaming with a digital trigger in python. I'm using a 5443D, and my code is in python 2.7, and my machine is running Ubuntu 16.

Post Reply