view example.py @ 6:85dfc0babc36

Add basic RSIB parser and example program. There are still a few questions about this stuff..
author Daniel O'Connor <darius@dons.net.au>
date Sat, 16 May 2009 23:30:59 +0930
parents 51d1fc44a753
children 813e183cfd49
line wrap: on
line source

#!/usr/bin/env python

import usb488
import matplotlib.pylab as pylab
import numpy
import time

def main():
    u = usb488.USB488Device()
    print "Found device"

    u.write("*IDN?")
    print "IDN reports " + u.read()
    
    u.write("DATA:ENC RIB")	# Big endian signed
    u.write("DATA:WIDTH 2")	# 2 bytes wide
    u.write("SELECT:CH1 ON")	# Turn channel 1 on
    u.write("DATA:SOURCE CH1")	# Set the curve source to channel 1
    u.write("CURVE?")		# Ask for the curve data
    then = time.time()                            
    result = u.read(1.0)	# Takes the CRO a while for this
    now = time.time()
    print "CURVE read took %f milliseconds" % ((now - then) * 1000.0)
    data = result[13:]		# Chop off the header
    dattype = numpy.dtype('>h')	# Big endian 16 bit quantity
    ary = numpy.fromstring(data, dtype = dattype)
    pylab.plot(ary)
    pylab.show()
    
if __name__ == "__main__":
    main()