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

rm = visa.ResourceManager()
rm.list_resources()
inst = rm.open_resource('GPIB0::1::INSTR',write_termination= '\n')

print(inst.query("*IDN?"))
print(rm)
print(inst)
values = np.array(inst.query_ascii_values('CURV?', converter='s'))
#values1=inst.write_ascii_values('WLISt:WAVeform:DATA somename,', values, converter='s')

len(值)打印(值)

大家好,我对 Python 和编程真的很陌生。我正在尝试从 Tektronix 示波器 (TDS 460 A) 获取波形。我正在使用 GPIB (GPIB USB-HS) 传输数据。使用上面编写的代码,我可以连接示波器。我有一些非常基本的问题。当我打印(值)时,它给了我一个字符串。我想知道那个字符串是什么?和仪器的地址一样吗?现在我已与仪器连接,我该如何进一步操作?我的最终目标是从示波器的多个通道中获取跟踪信息。

4

1 回答 1

0

你可以使用:

from struct import unpack
import pyvisa as visa
rm = visa.ResourceManager()
print(rm)

def acquire(channel, port):
    try:
        scope = rm.open_resource(port)
        scope.write("DATA:SOURCE " + channel)
        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?'))
        xdelay = float(scope.query('HORizontal:POSition?'))
        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)-((xincr * len(Volts))/2-xdelay)
        return Time,Volts
    except IndexError:
        return 0,0
于 2019-09-30T01:56:21.583 回答