Python SCPI Acquire

Tell us how your experiment is running with Red Pitaya
Post Reply
kooper
Posts: 3
Joined: Mon Jan 04, 2016 6:02 pm

Python SCPI Acquire

Post by kooper » Thu Mar 16, 2017 6:30 pm

Hi!

I try to acquire some signal data over the network with python.
For signal generation (1 kHz, 1 V) I use the example from the wiki. For aquisition I use the following code:

Code: Select all

#!/usr/bin/python

import sys
from time import sleep
import redpitaya_scpi as scpi
import matplotlib.pyplot as plot

ip = 'insert ip here'

rp_s = scpi.scpi(ip)

rp_s.tx_txt('ACQ:RST')
rp_s.tx_txt('ACQ:SOUR1:GAIN LV')
rp_s.tx_txt('ACQ:TRIG:LEV 0')
rp_s.tx_txt('ACQ:TRIG:DLY 0')
rp_s.tx_txt('ACQ:DEC 8')
rp_s.tx_txt('ACQ:START')

sleep(0.1)

rp_s.tx_txt('ACQ:TRIG CH1_PE')

while 1:
    rp_s.tx_txt('ACQ:TRIG:STAT?')
    if rp_s.rx_txt() == 'TD':
        break

rp_s.tx_txt('ACQ:SOUR1:DATA?')

buff_string = rp_s.rx_txt()
buff_string = buff_string.strip('{}\n\r').replace("  ", "").split(',')
buff = list(map(float, buff_string))

plot.plot(buff)
plot.ylabel('Voltage')
plot.grid()
plot.show()
First of all I got some result which looks good. But if I take a deeper look, I wonder why the signal is not starting at 0V. There is no delay and the trigger level is set to 0V.

Another confusing thing is that setting the trigger event comes after 'ACQ:START'. Am I right that with 'ACQ:START' the (ring?) buffer get filled? But where comes the trigger in?

THX!

Nils Roos
Posts: 1441
Joined: Sat Jun 07, 2014 12:49 pm
Location: Königswinter

Re: Python SCPI Acquire

Post by Nils Roos » Fri Mar 17, 2017 1:46 pm

I wonder why the signal is not starting at 0V. There is no delay and the trigger level is set to 0V.
Setting a trigger delay of 0 does not mean "no delay". The trigger delay is increased by 8192 samples internally, in order to have the trigger be in the middle of the buffer by default. If you want the trigger event to be at the beginning of the recorded data, you need to set a delay of 8192.
Another confusing thing is that setting the trigger event comes after 'ACQ:START'. Am I right that with 'ACQ:START' the (ring?) buffer get filled? But where comes the trigger in?
ACQ:START starts filling the ringbuffer, but recording does not stop when the end of the buffer is reached. The buffer will be filled over and over so that at any point in time it contains the latest 16384 samples. The trigger (plus the trigger delay) marks the point when recording into the ringbuffer is stopped. When the trigger happened and the trigger delay is over, the buffer will no longer be updated so that you can read out the contents.

kooper
Posts: 3
Joined: Mon Jan 04, 2016 6:02 pm

Re: Python SCPI Acquire

Post by kooper » Fri Mar 17, 2017 10:54 pm

Thanks Nils to bring some light into the darkness!

First, is it possible to extend the buffer by simple change the size at the malloc or is this somewhat of hardwired in the FPGA?

Second, just to get this right, trigger in this scope is not the same as in the old analog days, where the beam starts at the left side of the CRT?!

By getting the buffer with ACQ:SOUR1:DATA? I lost the trigger information?

Thx

kooper
Posts: 3
Joined: Mon Jan 04, 2016 6:02 pm

Re: Python SCPI Acquire

Post by kooper » Sat Mar 18, 2017 10:02 am

Ok by using ACQ:TPOS? I get the position in the data array and by using the delay I can control how many samples I get after the trigger occurs!?

Nils Roos
Posts: 1441
Joined: Sat Jun 07, 2014 12:49 pm
Location: Königswinter

Re: Python SCPI Acquire

Post by Nils Roos » Sun Mar 19, 2017 11:26 pm

is it possible to extend the buffer by simple change the size at the malloc or is this somewhat of hardwired in the FPGA?
The buffer size of 16384 samples per channel is hardwired.
trigger in this scope is not the same as in the old analog days, where the beam starts at the left side of the CRT?!
Ok by using ACQ:TPOS? I get the position in the data array and by using the delay I can control how many samples I get after the trigger occurs!?
A trigger condition is recognized instantaneously, like in the old days, but at that moment, you already have the last 16k samples buffered. So by stopping the recording 0-16383 samples after the trigger happened, you can shift the trigger position over the whole width of your 'screen' (or even further to the left if you use larger values).
Like you said, with "ACQ:TPOS?" you read the trigger position inside the buffer. But "ACQ:SOUR#:DATA?" does not read the buffer from absolute 0-16383. Instead, it reads relative to the point when recording stopped. For example if the trigger happened at (TPOS=) 1000 and you had an effective trigger delay of 2000, you will get 3000-16383 concatenated with 0-2999.

bhc
Posts: 4
Joined: Mon Nov 16, 2020 2:20 am

Re: Python SCPI Acquire

Post by bhc » Tue Nov 17, 2020 6:35 am

After spending some time on the forum and with the examples, I'm still stuck. Using an external trigger I cannot synchronize the trigger with the data. To be clear, the oscilloscope app works fine as does the result from another usb scope. I'm struggling with how to align the trigger with the acquired data. Can someone please enlighten me?

I'm running OS 1.03-701.

Below is my test code (intended for an ipynb) along with a few capture images to illustrate the issue. As you can see the signal is quite noisy and I need to implement some signal averaging and peak picking. However, without a syncrhonized trigger, signal averaging is a pipe dream.

Apparently, I cannot upload a png for some reason. Here's a summary of the issue:

https://docs.google.com/document/d/1X-t ... sp=sharing

Code: Select all

import sys
import time
import numpy as np
import matplotlib.pyplot as plt

%matplotlib inline

import redpitaya_scpi as scpi

#create the instance of the scipy server
#TODO put in your correct Red Pitayas IP-Adress here
rp_s = scpi.scpi('192.168.4.68')###INSERT YOUR ADDRESS

rp_s.rst()#reset

rp_s.tx_txt('ACQ:DEC 1024')
rp_s.tx_txt('ACQ:TRIG:LEV 2000 mV')
rp_s.tx_txt('ACQ:START')
rp_s.tx_txt('ACQ:TRIG EXT_PE')

while 1:
    rp_s.tx_txt('ACQ:TRIG:STAT?')
    if rp_s.rx_txt() == 'TD':
        break
        
##IS THERE A DELAY HERE? Shouldn't be, because the data is already acquired.  We are just grabbing what is in the past and applying a trigger mark to it.
## At least so I think...
rp_s.tx_txt('ACQ:SOUR1:DATA?')
buff_string = rp_s.rx_txt()
buff_string = buff_string.strip('{}\n\r').replace("  ", "").split(',')
buff = list(map(float, buff_string))

rp_s.tx_txt('ACQ:TPOS?')
trigLoc = int(rp_s.rx_txt())
rp_s.tx_txt('ACQ:WPOS?')
writePos = int(rp_s.rx_txt())
print("Trigger Loc: %s"%trigLoc)
print("Write Pos: %s"%writePos)
print("%d"%(trigLoc+writePos))


fig, ax = plt.subplots(figsize=(12, 4))
plt.plot(buff)
plt.vlines(8192, 0, 0.8, 'r', label = "8192")
plt.vlines(trigLoc, 0, 0.8, 'm', label = "Trigger Location")
plt.vlines(writePos, 0, 0.8, 'y', label = "Write Location")
plt.legend()
plt.title("Why isn't the trigger aligned?", fontsize = 16)


User avatar
redpitaya
Site Admin
Posts: 876
Joined: Wed Mar 26, 2014 7:04 pm

Re: Python SCPI Acquire

Post by redpitaya » Thu Nov 19, 2020 2:51 pm

Sorry to interrupt. Black Friday 2020 is here!

bhc
Posts: 4
Joined: Mon Nov 16, 2020 2:20 am

Re: Python SCPI Acquire

Post by bhc » Thu Nov 19, 2020 10:39 pm

It's hard to consider buying another one without some clarity on the operation of the existing unit.

earlforeal
Posts: 33
Joined: Thu Aug 20, 2020 9:00 pm

Re: Python SCPI Acquire

Post by earlforeal » Tue May 03, 2022 7:56 pm

I laughed at that reply from red pitaya

Post Reply
jadalnie klasyczne ekskluzywne meble wypoczynkowe do salonu ekskluzywne meble tapicerowane ekskluzywne meble do sypialni ekskluzywne meble włoskie

Who is online

Users browsing this forum: No registered users and 2 guests