Tektronix Technical Forums are maintained by community involvement. Feel free to post questions or respond to questions by other members. Should you require a time-sensitive answer, please contact your local Tektronix support center here.

Python-Tek DPO 400 series: read binary wafeform with 2 bytes

Post Reply
Syl
Posts: 2
Joined: January 20th, 2016, 11:39 pm

Python-Tek DPO 400 series: read binary wafeform with 2 bytes

Post by Syl » January 21st, 2016, 1:26 am

Hello everyone,
I would like to address to the community a question that I don't succeed to solve.
I want to read a waveform from an oscilloscope Tek DPO 4000 series with a binary format of 2 bytes per data point. The reason is that a 1 byte per data point produces values ranged in 255 levels while 2 bytes per data point allows 65,535 discretization levels. (Actually I know that it is a 8 bits oscilloscope but when one averages, 8 bits are not enough to sample the signal, therefore I want to go for 16 bits).

Based on the code offered by Tektronix FAQ ID: 948850 (http://www.tek.com/support/faqs/program ... ope-python),

Code: Select all

import visa
import numpy as np
from struct import unpack
import pylab

scope = visa.instrument('USB0::0x0699::0x0401::No_Serial::INSTR')

scope.write('DATA:SOU CH1')
scope.write('DATA:WIDTH 1')
scope.write('DATA:ENC RPB')

ymult = float(scope.ask('WFMPRE:YMULT?'))
yzero = float(scope.ask('WFMPRE:YZERO?'))
yoff = float(scope.ask('WFMPRE:YOFF?'))
xincr = float(scope.ask('WFMPRE:XINCR?'))

scope.write('CURVE?')
data = scope.read_raw()
headerlen = 2 + int(data[1])
header = data[:headerlen]
ADC_wave = data[headerlen:-1]

ADC_wave = np.array(unpack('%sB' % len(ADC_wave),ADC_wave))

Volts = (ADC_wave - yoff) * ymult  + yzero

Time = np.arange(0, xincr * len(Volts), xincr)

pylab.plot(Time, Volts)
pylab.show()
I haven't succeed to read a 2 byte per data point binary waveform.
I changed:
  • scope.write('DATA:WIDTH 1') to scope.write('DATA:WIDTH 2')
  • ADC_wave = np.array(unpack('%sB' % len(ADC_wave),ADC_wave)) to ADC_wave = np.array(unpack('%sb' % len(ADC_wave),ADC_wave))
but it doesn't work.
I also tried many other possibilities but it doesn't work too. The best I got was to have a waveform with my values separated with "0".
I would be so thankful if someone could support me with that. In my opinion it is a python issue, but I didn't find any example dealing with this case.
Thank you in advance for your help.

Syl
Posts: 2
Joined: January 20th, 2016, 11:39 pm

Re: Python-Tek DPO 400 series: read binary wafeform with 2 bytes

Post by Syl » February 9th, 2016, 12:14 am

Hello everyone,
Here is the answer to the problem I posted recently.
Replace the code with the following command:

Code: Select all

-DATA:WIDTH 2
-DATA:ENC SRI
...
-ADC_wave = np.fromstring(ADC_wave, dtype=np.int16)
And it works ;)
Cheers!

omkar ugale
Posts: 2
Joined: June 29th, 2016, 11:15 pm
Country: United States

Re: Python-Tek DPO 400 series: read binary wafeform with 2 bytes

Post by omkar ugale » July 2nd, 2016, 7:03 am

Hello,
I want to collect the data from oscilloscope and process it on PC with Python script. Though I can process it using a python script first it is import for me to collect it from oscilloscope. Do you have any idea about how i can do the interfacing between dso and PC so as to collect and process the data. How I can collect the data that i can use to process using a Python on PC. Please let me know. Thank you!

Dave W
Tektronix Applications
Tektronix Applications
Posts: 266
Joined: April 26th, 2010, 12:01 pm
Country: United States

Re: Python-Tek DPO 400 series: read binary wafeform with 2 bytes

Post by Dave W » July 12th, 2016, 2:56 pm

omkar ugale wrote:Hello,
I want to collect the data from oscilloscope and process it on PC with Python script. Though I can process it using a python script first it is import for me to collect it from oscilloscope. Do you have any idea about how i can do the interfacing between dso and PC so as to collect and process the data. How I can collect the data that i can use to process using a Python on PC. Please let me know. Thank you!
The video at the following URL should help you get started.

Python Rapid Start

Post Reply

Return to “Programming Support”

Who is online

Users browsing this forum: No registered users and 5 guests