Contact an Expert

Thread: Python Scripting


Permlink Replies: 3 - Pages: 1 - Last Post: Jan 29, 2013 10:25 PM Last Post By: alex.forencich
scottnla

Posts: 3
Registered: 02/02/12
Python Scripting
Posted: Feb 2, 2012 4:31 PM
Click to report abuse...   Click to reply to this thread Reply
Hey all,

I am an avid python scripter, and was wondering how I could connect/log data from an oscilloscope (I'm looking at the DSOX2004A) using Python. I'm open to using USB or Ethernet (I actually slightly prefer ethernet so I can talk to multiple devices simultaneously), but its unclear to me what the easiest way to get going is.

I've seen a few people post code, but I'd really like to have a more clear idea about what the general structure is of how to interface with the scope than simply the code to perform a specific task. I'm used to talking to arduinos over serial, but am not sure what I'm supposed to do with an oscilloscope to talk to it. Do I need PyVISA? Can it be done over a serial/usb connection?

any help would be greatly appreciated,

nathan lachenmyer
boogaloob

Posts: 7
Registered: 10/13/11
Re: Python Scripting
Posted: Feb 3, 2012 1:49 AM   in response to: scottnla in response to: scottnla
Click to report abuse...   Click to reply to this thread Reply
Hi,

I am currently using Python to remote control my DSO6104A either via USB or LAN.
Yes, you need PyVisa. You obviously need the Agilent connection expert also.

Example 01 (directly with PyVisa):
import visa
import pylab

# Get instrument VISAname
visaInstrList = visa.get_instruments_list()
myScope = visaInstrList[0]+'::INSTR'

scope = visa.instrument(myScope)

# CONFIGURATION ----------------------------------------------------------------
scope.write("*RST")
scope.write("*CLS")
IDN = scope.ask("*IDN?")
scope.write(":AUToscale")
scope.write(":CHANnel1:PROBe 10")
scope.write(":CHANnel1:RANGe 8")
scope.write(":CHANnel1:SCALe 250mV")
scope.write(":TIMebase:RANGe 5e-6")
scope.write(":ACQuire:MODE RTIMe")
scope.write(":TIMebase:REFerence CENTer")
scope.write(":TRIGger:TV:SOURCe CHANnel1")
scope.write(":TRIGger:MODE EDGE")


Because Visa is based on ambiguous strings (to my opinion...) writing a high level wrapper for the PyVisa module will help you getting rid of the strings. It makes life easier.
To do so, the GUIDE (6000_series_prog_guide.pdf) has been very helpfull. It lists all the functions you can use with Visa and how to use them. Of course, you will have to clean up things to make it work perfectly under Python but the wrapper is used in that purpose.

Hope this helps.
scottnla

Posts: 3
Registered: 02/02/12
Re: Python Scripting
Posted: Feb 5, 2012 4:58 PM   in response to: scottnla in response to: scottnla
Click to report abuse...   Click to reply to this thread Reply
So are the somewhat ambigous strings like 'CHAN', 'ACQ', and 'APPL' part of the VISA language?

It was a bit ambiguous to me how to connect to devices from reading around on the forums, so I wrote my own driver that should operate in python. It probably repeated a lot of the efforts of pyVISA, but I hope that perhaps it's easier to read for beginners like myself?

https://github.com/asymptoticdesign/pyInstrumentation
alex.forencich

Posts: 18
Registered: 01/29/13
Re: Python Scripting
Posted: Jan 29, 2013 10:25 PM   in response to: scottnla in response to: scottnla
Click to report abuse...   Click to reply to this thread Reply
VISA isn't a language, it's a framework. Those commands are part of the instruction set (SCPI, I believe) for the instrument in question. Quite a few instruments use the same (or very similar) commands.

It's possible to connect to instruments over LAN with pure python applications as well. I have been working on a pure Python interpretation of IVI myself that can connect to instruments with VXI-11 over LAN, among other things. It's not complete yet, but it may be of use to someone: https://github.com/alexforencich/python-ivi .

Point your RSS reader here for a feed of the latest messages in all forums