Created
February 26, 2014 21:23
-
-
Save theterg/9238877 to your computer and use it in GitHub Desktop.
Continually retrieve a single datapoint from any VISA device such as an oscilloscope or benchtop multimeter.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import visa | |
| import sys | |
| import pandas as pd | |
| import numpy as np | |
| import datetime | |
| import time | |
| import argparse | |
| parser = argparse.ArgumentParser(description='Continuously retrieve data from scope as quickly as possible') | |
| parser.add_argument('command', type=str, help='The command to execute. EG: MEAS:PWIDTH? CHANNEL3') | |
| parser.add_argument('--numruns', type=int, default=100, help='number of requests to make') | |
| parser.add_argument('--string', action='store_true', default=False, help='Return data as string instead of float') | |
| args = parser.parse_args() | |
| rm = visa.ResourceManager() | |
| devices = rm.list_resources() | |
| scopename = "" | |
| for dev in devices: | |
| if dev.startswith("USB0"): | |
| scopename = dev | |
| if scopename == "": | |
| print("Couldn't find scope") | |
| sys.exit(1) | |
| print("Using device "+scopename) | |
| scope = rm.get_instrument(scopename) | |
| datapts = [] | |
| idxs = [] | |
| start = time.time() | |
| try: | |
| for i in range(0,args.numruns): | |
| datapts.append(scope.ask(args.command)) | |
| idxs.append(time.time() - start) | |
| print("%d / %d" % (i, args.numruns)) | |
| except Exception as e: | |
| print(sys.exc_info()[0]) | |
| data = pd.Series(data=datapts, index=idxs) | |
| filename = datetime.datetime.now().strftime("scope_data_%m%d%y_%H%M%S.csv") | |
| if args.string: | |
| data.to_csv(filename) | |
| else: | |
| data.astype(np.float64).to_csv(filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment