Skip to content

Instantly share code, notes, and snippets.

@tai
Created October 20, 2022 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tai/408053a0955bf1712a5809240aa5544f to your computer and use it in GitHub Desktop.
Save tai/408053a0955bf1712a5809240aa5544f to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import time
import usbtmc
def capture(fmt='png'):
tmc = usbtmc.Instrument(0x1ab1, 0x04ce)
# magic initialization for DS1000Z
#
# - usbtmc.write_raw() does not work for now
# - DS1000Z dies with INITIATE_CLEAR sent by clear() call in open()
#tmc.write_raw(b'*IDN?')
open("/dev/usbtmc2", "w").write('*IDN?') # /dev/usbtmc<N> hardcoded for testing
tmc.write(':run')
time.sleep(1) # run for a while to get a trace on screen
tmc.write(':stop')
time.sleep(0.1)
tmc.write(':disp:data? on,off,%s' % fmt)
time.sleep(1) # needs to wait long enough
buf = tmc.read_raw(1024 * 1024)
img = buf[11:-4]
return img
if __name__ == '__main__':
img = capture('png')
open('rigol.png', 'wb').write(img)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment