Skip to content

Instantly share code, notes, and snippets.

@bodokaiser
Created July 13, 2018 11:52
Show Gist options
  • Save bodokaiser/73d4f0893263dd9b4808cfa41bc14001 to your computer and use it in GitHub Desktop.
Save bodokaiser/73d4f0893263dd9b4808cfa41bc14001 to your computer and use it in GitHub Desktop.
import visa
import numpy as np
from matplotlib import pyplot as plt
rm = visa.ResourceManager()
scope = rm.open_resource('TCPIP::172.22.22.30::inst0::INSTR')
scope.timeout = 5000
scope.clear()
print(scope.query("*IDN?"))
def capture(channel):
scope.write(f':DIGitize CHANnel{channel}')
scope.write(':WAVeform:FORMat WORD')
scope.write(f':WAVeform:SOURce CHANnel{channel}')
values = scope.query_binary_values(':WAVeform:DATA?',
datatype='H', container=np.array)
xorg = scope.query_ascii_values(':WAVeform:XORigin?')[0]
xinc = scope.query_ascii_values(':WAVeform:XINcrement?')[0]
yorg = scope.query_ascii_values(':WAVeform:YORigin?')[0]
yinc = scope.query_ascii_values(':WAVeform:YINcrement?')[0]
yref = scope.query_ascii_values(':WAVeform:YREference?')[0]
U = yorg + yinc*values
t = np.arange(xorg, xorg + len(U)*xinc, xinc)
return t, U
# configure the oscilloscope over the front panel to use external,
# rising edge trigger signal in normal mode
input("configure scope and press enter when ready")
# get values
t, U = capture(1)
# plot result
plt.plot(t, U)
plt.xlabel('Time [s]')
plt.ylabel('Voltage [V]')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment