Python SCPI: binary acquisition

Applications, development tools, FPGA, C, WEB
Post Reply
tttt
Posts: 1
Joined: Wed Apr 25, 2018 4:16 pm

Python SCPI: binary acquisition

Post by tttt » Wed Apr 25, 2018 4:43 pm

I'm trying to acquire data from a fast analog output as continuously as possible using Python and the redpitaya_scpi.py module.
If I acquire ascii data, the delay time between successive acquisitions (with decimation = 1) is 250 ms.
What I do is:

Code: Select all

rp_s.tx_txt('ACQ:RST')
rp_s.tx_txt('ACQ:START')
rp_s.tx_txt('ACQ:TRIG NOW')
rp_s.tx_txt('ACQ:SOUR2:DATA?')
buff_string = rp_s.rx_txt()
buff_string = buff_string.strip('{}\n\r').replace("  ", "").split(',')
buff = list(map(float, buff_string))
I red around that it would be much faster if I could acquire in binary format, but if I read the buffer, the result is a boolean False.

Code: Select all

rp_s.tx_txt('ACQ:RST')
rp_s.tx_txt('ACQ:DATA:UNITS VOLTS')
rp_s.tx_txt('ACQ:DATA:FORMAT BIN')
rp_s.tx_txt('ACQ:START')
rp_s.tx_txt('ACQ:TRIG NOW')
rp_s.tx_txt('ACQ:SOUR2:DATA?')
databin = rp_s.rx_arb()
In fact, if we look inside the function rp_s.rx_arb(), this is returning False if the first bit that the socket return is:

Code: Select all

b'#'
This is indeed the only thing that the socket read in the buffer.

The two sequences are identical, except for the requested data format. Why can I read ascii data and not binary? What am I doing wrong?
Thanks in advance

gsteele13
Posts: 3
Joined: Thu Mar 12, 2020 3:11 pm

Re: Python SCPI: binary acquisition

Post by gsteele13 » Sun Mar 15, 2020 1:19 pm

Does anyone know if there is some working example code of a binary read in python?

Thanks,
Gary

gsteele13
Posts: 3
Joined: Thu Mar 12, 2020 3:11 pm

Re: Python SCPI: binary acquisition

Post by gsteele13 » Sun Mar 15, 2020 11:18 pm

Hi all,

I found a source of a problem: the SCPI code on github is still python2.7 oriented, and needed some upgrades for python3 (socket.recv now returns byte strings)

This is some code that will allow you to read the socket properly:

Code: Select all

rp_s.tx_txt('ACQ:DATA:UNITS VOLTS')
rp_s.tx_txt('ACQ:DATA:FORMAT BIN')
rp_s.tx_txt('ACQ:SOUR2:DATA?')

# The first thing it sends is always a #
#
# One thing I don't understand here is that even if I do a recv(10), 
# I always get only one answer back. Like somehow we are getting a
# terimination signal in the socket? I don't know enough about sockets. 
# This doesn't work though for the the number of digits. 
# Maybe I need to look in the SCPI server code. 
#
buf = rp_s._socket.recv(1)
print(buf.decode('utf-8'))

# The second thing it sends is the number of digits in the byte count. 
buf = rp_s._socket.recv(1)
digits_in_byte_count = int(buf)

# The third thing it sends is the byte count
buf = rp_s._socket.recv(digits_in_byte_count)
print(buf.decode('utf-8'))
byte_count = int(buf)

# Now we're ready read! You might thing we would just to a recv(byte_count), but somehow this often 
# results in an incomplete transfer? Maybe related to first point above? 
# The RP code just reads one byte at a time until it's gets all
# it wants? I tried that and it seems to work. But it is not mega-fast? 317 ms, whereas we should be 
# able to get data off much faster than that! It is 65536 bytes = 5 ms at 100 MBit / second. 
# But 317 ms is still at least a lot better than the ASCII read which takes 1.3 seconds!

buf = []
while len(buf) != byte_count:
    buf.append(rp_s._socket.recv(1))
print(len(buf))

inv-wh
Posts: 1
Joined: Mon Mar 16, 2020 4:57 pm

Re: Python SCPI: binary acquisition

Post by inv-wh » Tue Mar 24, 2020 8:55 pm

Hello,

Does anyone know how to then convert the collected bytes back into the float VOLTS form?

Thank you!

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