Page 1 of 1

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

Posted: January 21st, 2016, 1:26 am
by Syl
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.

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

Posted: February 9th, 2016, 12:14 am
by Syl
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!

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

Posted: July 2nd, 2016, 7:03 am
by omkar ugale
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!

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

Posted: July 12th, 2016, 2:56 pm
by Dave W
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