Examples?

1,177 views
Skip to first unread message

Christopher Johnson

unread,
Feb 11, 2014, 8:46:44 PM2/11/14
to pytho...@googlegroups.com
Any expanded uses or examples you can share for using Python-IVI?

I've forked the Github repo and I'm working on adding some instrument support for Chroma DC power supplies and LeCroy scopes. To debug my additions and for my own use it would be helpful to have a more comprehensive example instead of the short "identity" example on your site that shows the machine name.

Perhaps any examples you have for triggering the scope, taking a screenshot (print scope screen) and transferring the image back to the computer where you are running your Python-IVI program from?

Alex Forencich

unread,
Feb 11, 2014, 10:27:00 PM2/11/14
to pytho...@googlegroups.com
Christopher-

I noticed your branch a few days ago.  Looks like you've been putting in a lot of work.  Thanks!

The identify example is basically just a sanity check to make sure that the communication to the instrument is working correctly and that the new driver can be correctly instantiated.  Actually, if there are any major issues, the 'import ivi' call or the initialize call will most likely fail.  There are a few additional examples way down at the bottom of the readme, but these are by no means comprehensive and are mainly just an indication of how you can use Python IVI to control instruments. 

You mentioned an example for screenshots; there is one in the readme, but it really isn't much to look at:

png = mso.display.fetch_screenshot()
with open('screenshot.png', 'wb') as f:
    f.write(png)

I have a couple of scripts that use Python IVI to control a couple of instruments that I can pass along to you if you are interested, but there really isn't much to how they use Python IVI that you can't glean from the examples in the readme. 

In terms of individual parameters, I don't think there is one good simple example.  The way I develop drivers is I just go through the parameters one at a time and I make sure changes to each parameter are reflected correctly on the instrument. 

Implementing the trigger type?  If you set the trigger.type parameter to 'edge', the scope should switch to edge trigger mode.  However, for trigger modes, things may be a little bit complicated.  I would suggest taking a look at the IVI spec.  The documentation in the code is probably sufficient, but the spec is a little better formatted.  Basically, in most of the scopes that I have looked at, the mapping between IVI trigger types and the scope's supported trigger types is not quite 1:1.  For example, IVI has an 'edge' trigger and an 'ac_line' trigger.  However, to get AC line triggering on my MSO7104, you need to set it to edge trigger and then set the source to 'line'.  And on the same scope the 'glitch' and 'width' types both correspond to what the scope calls 'glitch' triggering, just with different qualifiers.  So implementing trigger types in accordance with the IVI spec requires a little bit of extra bookkeeping as the IVI trigger type has to be determined from looking at the scope's trigger type, trigger source, and glitch qualifier settings. 

The bottom line is that you need to check that every parameter works correctly with your instrument.  The easiest way to do this is check them one at a time by setting them to a sensible value and making sure the instrument responds appropriately. 

Also, if your instrument supports parameters and modes that are not in the base classes, go ahead and implement them.  If there are already similar instruments included in Python IVI, it would be a good idea to take a look at those and see if any of them might have added a similar function, perhaps with a slightly different name.  For example, most instruments support *SAV and *RCL commands to save and restore the setup to internal memories.  For all of the drivers currently in the repo for instruments that support this, this functionality is accessed through memory.save and memory.recall.  This isn't an IVI standard, but it is essentially a Python IVI de facto standard. 

The way the IVI spec defines the scope's horizontal timebase is actually a little bit wonky and I am still mulling over the right way to implement it.  Basically, the idea is that you set the start time (relative to the trigger) and the range.  A setting of 0 for the start time means that the first point out of fetch_waveform corresponds to the trigger event.  However, on most scopes, you set the trigger position on the display relative to the center.  On my MSO7104, the start of the trace just ends up on the left-hand edge of the display, and the offset between the left-hand edge and the center changes with the horizontal scale, necessitating calculating and subtracting off that offset.  However, on the DSA91304, the scope seems to like taking 1k points even if it can't display all 1k points on the screen, so the start of the acquisition actually ends up quite a ways off the left hand side of the display for sweep times around 2ns per division or less.  I have not thought of a good, reliable solution for dealing with this yet, so I went ahead and exposed the timebase.position, timebase.range, and timebase.scale properties.  Yes, they aren't in the IVI spec, but they correspond nicely with the available commands for most scopes.  (This is a very recent addition and was not present in the version of the agilentBaseScope file that you copied for the lecroy scopes). 

Alex Forencich
--
You received this message because you are subscribed to the Google Groups "python-ivi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-ivi+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Christopher Johnson

unread,
Feb 11, 2014, 11:25:17 PM2/11/14
to pytho...@googlegroups.com
Thank you very much for the detailed reply Alex.

I'm very appreciative of the IVI and VXI11 libraries you have put together. My first attempt at using Python to control lab instrumentation is by using the PyVISA module and writing the commands by myself. This is proving to be pretty frustrating experience but hopefully a worthwhile learning experience for myself.

The LeCroy Waverunner Xi-A / MXi-A scope series I'm using seems to be a little bit difficult. I'm definitely able to control settings and take some pictures using the PyVISA library and sending the HCSU and SCDP commands to the scope but it is not easy to retrieve the images off the HDD on my scope using python and this approach.

I originally copied the agilent files for my LeCroy implementation. I just tried the simple screenshot example you gave but it seems I need to dive into the documentation and do a lot more debugging, there is likely some differences in the commands I need to send or they just aren't supported; my scope is receiving "HARDCOPY:INKSAVER" and "DISPLAY:DATA?" commands form Python-IVI with the fetch_screenshot() commands (because I copied the agilent directory) but the scope only returns an error for these commands.

I think the problem is that my scope will work best when using some VBS commands (visual basic) that I have to implement. Once it is fixed and working I will look to submit a pull request.

Here is a visual basic example from LeCroy:
' Visual Basic Script
Set app = CreateObject("LeCroy.XStreamDSO")
' Set the grid lines to be over the trace lines.
app.Display.GridOnTop = True

The scope can preface visual basic code with the "VBS" command. By using the previous example from LeCroy I think my Python-IVI implementation can then send a command like:
“VBS 'app.Display.GridOnTop = True'"

I also think I may need to use the CreateObject command to create 'app' first and then I can send these VBS commands but I still need to test this. I'm not very familiar with visual basic.

LeCroy manuals for reference:

Regards,
Chris

Alex Forencich

unread,
Feb 12, 2014, 1:03:33 AM2/12/14
to pytho...@googlegroups.com
Christopher-

Unfortunately, you're still going to have to figure out what commands you need to send to the instrument.  I might be able to give you some help deciphering manuals here and there.  

The screenshot function was written for Agilent InfiniiVision series oscilloscopes (2000, 3000, 6000, 7000) so it will need to be rewritten to work with LeCroy scopes. 

The screenshot command for the Agilent scopes is very straightforward, just send "DISPLAY:DATA?" with the proper arguments and it spits out a binary block with the image data, all ready to be written to a file. 

From looking at the LeCroy manual for the X-Stream scopes, it looks like the waveform readout can use a binary block format.  What I would suggest doing is changing the default names in the _init_channels command to match the channel names used in the control language (so change channel%d to c%d so the channels are c1, c2, c3, etc.).  Then read out a waveform with the 'c[#]:waveform?' command, similar to how the Agilent waveform readout command works.  Then process it according to the format listed in the manual.  Looks like you can pull out all of the needed information from the binary block directly without needing to do an equivalent of Agilent's waveform:preamble command.  Take a look at Python's struct library to help out with the decoding. 

For a screenshot, it looks like you can use HCSU to set the image type and the destination to 'remote'.  Then I'm not sure exactly how it works after that.  You probably need to send the screen dump command SCDP.  Then I'm not sure if you need to query something or if you just need to issue a read call to get the data. 

Looks like this post has some confirming information:

http://forums.ni.com/t5/Instrument-Control-GPIB-Serial/How-do-you-use-the-SCREEN-DUMP-command-for-the-waverunner-scopes/td-p/402376

I think you should probably ignore all of the VBS stuff as that looks like it leverages a LeCroy VBS library of some sort.  Calling a VBS library from Python seems rather redundant to me, not to mention it's not going to be very portable. 

Alex Forencich

Christopher Johnson

unread,
Feb 12, 2014, 1:25:25 AM2/12/14
to pytho...@googlegroups.com
Got it, thanks so much for the help.

The VBS stuff was really confusing me and I thought it was going to contain some extra access or enhancements but it seems to just mirror much of what I can access with the SCPI commands.

I'll keep working at it and see what I can do. Once I get some more features integrated I can start doing more testing. I'm writing a lab control program that I would like to finish this week so the work of writing the SCPI commands for the scope and figuring out the implementation can help me with the python-ivi support that I am working on.

Alex Forencich

unread,
Feb 12, 2014, 2:01:35 AM2/12/14
to pytho...@googlegroups.com
Yeah, the VBS stuff is strange.  The first time I looked at the manual I was trying to figure out how many different communication protocols it supported and what the difference was.  Then I realized that they had their own VBS script that basically does (as far as I can tell) what Python IVI does, but only for their scopes. 

Let me know if you run in to any major roadblocks.  I have been working with the remote interfaces on a lot of different instruments so I might have a few insights. 

Alex Forencich

Christopher Johnson

unread,
Feb 15, 2014, 12:09:51 AM2/15/14
to pytho...@googlegroups.com
This scope, LeCroy WaveRunner Xi-A series, is pretty fickle. For an example I was really hoping to use the scope print screen function and transfer the images back to my computer and into a directory. They mentioned to use the "DEST,REMOTE" and "PORT,NET" as commands in HARDCOPY_SETUP to get the data out over the ethernet port but right now I don't have the know-how to implement this yet. It seems that I can receive the data but Python just spews out something about the data format that it receives (by the way I'm on Mac OS X). There are also some undocumented things I found like the proper coupling settings for the LeCroy AP015 current probes I use with the scope, I figured them out but they don't seem to be documented.

I will probably start to add IVI support for some of the more simple instruments I use such as a Chroma programmable DC power supply, a random Taiwanese brand (Prodigit) programmable DC load, Chroma DC loads, and some Agilent source meters. I do have access to quite a lot of different instruments. The scopes have so many features that it is a daunting task to tackle as my first implementation.

Alex Forencich

unread,
Feb 15, 2014, 2:27:48 AM2/15/14
to pytho...@googlegroups.com
When you read out binary data, don't use _ask.  Use _write and then _read_raw.  If the data is coming out as an IEEE block (e.g. #800000123.... or #9000000123....) then use _read_ieee_block.  Otherwise, if it's not textual data, you're going to get an encoding error when the driver tries to run it through the utf-8 decoder. 

I would suggest trying something like this:

self._write('setup command 1')
self._write('setup command 2')
etc.
self._write('output screenshot command')
img = self._read_raw()
or
img = self._read_ieee_block()

Then do something like

with open('screen.png', 'wb') as f:
    f.write(img)

to save your picture. 

Simple instruments are definitely the way to start out.  There are a few drivers you can look at that implement very simple instruments - check out the Colby Instruments delay line driver and the Tektronix AM5030 and OA5000 series drivers for a few examples of very simple drivers that don't use the IVI base classes at all. 

Also, the included drivers for all of the Agilent scopes definitely don't cover all of the functions.  The Infiniivision drivers are missing all of the serial decoding features, and the infiniium drivers are missing that and much of the complicated triggering features that they support (dual triggering, etc.), among other things.  However, the basics are covered, as well as storing and loading configurations, so that's generally enough for a decent test setup.  I would imagine most types of test setups mainly involve synchronizing DUT and routing configurations with only minimal changes to measurement equipment settings, aside from possibly loading up saved configurations. 

Alex Forencich

Christopher Johnson

unread,
Mar 19, 2014, 6:46:28 AM3/19/14
to pytho...@googlegroups.com
Hi Alex,

I can report that I have finally started implementing and testing for the LeCroy scope that I am using. So far I have worked through some of the basic and a few more advanced features of the scope. I will try to follow your coding conventions and style as much as I can.

I did end up using that rather strange 'VBS' command for some of the more advanced features of the LeCroy WaveRunner 104Xi-A that aren't covered by the SCPI commands. I put these commands inside my "WaveRunner XI-A" class so the lecroyBaseScope will still be able to support lower level SCPI commands if supported by the scope. I found that this VBS wrapper can work fine with python-ivi as long as I am sending the properly formatted commands.

You should start to see my contributions to my GitHub repo but it is not ready for a PR yet.

Regards,
Chris
...

Alex Forencich

unread,
Mar 19, 2014, 11:39:34 AM3/19/14
to pytho...@googlegroups.com
Wait, so it actually works if you send the VBS commands to the scope? That is really whacky. Well, if it works, i guess that's fine then. It really doesn't matter how Python IVI communicates with the scope so long as the result is correct.

Good luck with getting all of that operational, and just submit a pull request when it is all working.

Alex Forencich

Mark Nornberg

unread,
Aug 15, 2014, 11:42:21 AM8/15/14
to pytho...@googlegroups.com
Hello Chris,

I am a research physicist working with Tektronix and LeCroy oscilloscopes for data acquisition needs. I have been recently using using pyVISA to communicate with a Tektronix 3054b successfully and wanted to create a similar setup for a LeCroy WaveRunner 204MXi. I stumbled upon the python-ivi project and this thread. Would you send me the link to your GitHub repo with what you've developed for the WaveRunner so far? I would be happy to help in the development if there are still needs for basic commands for retrieving data from the scope.

Regards,

Mark

Christopher Johnson

unread,
Aug 15, 2014, 12:08:03 PM8/15/14
to Mark Nornberg, pytho...@googlegroups.com
Hi Mark,

I will definitely share my driver. I shelved it for a bit while I was working out some kinks and started back up this past week. I'll add it to my master branch on GitHub and maybe submit a PR to Alex this week. 

It has a bunch of features that I use often already implemented and tested such as setting triggers, horizontal and vertical scaling, labeling traces, taking screenshots, auto setup, and other functions. I will let you know when it is available.

I believe I have added all MXi / Xi scopes including the 204MXi so you should be able to get going once I put it up and just implement features into the main file for all of the WaveRunner Xi-A scopes. 

A side note for anyone - I have all instrument drivers in development together as a single "develop" branch and just manually copy the files over to master when I want to submit a PR to Alex for a single instrument. I do this so I can run 'python setup.py develop' for my dev branch and not have to worry about constantly reinstalling to test, the develop option takes care of it for me. However, if I do a bunch of mixed commits on one branch it makes a for very messy PR if I only want to submit files for one instrument which is why I copy over the files to master instead of pushing from my dev branch. Any suggestions? I think I can use a git submodule or subtree here which I need to investigate. 

- Chris 

Sent from my phone
--
You received this message because you are subscribed to a topic in the Google Groups "python-ivi" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python-ivi/trEOVAguEpw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python-ivi+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Christopher Johnson

unread,
Aug 18, 2014, 10:53:07 AM8/18/14
to Mark Nornberg, pytho...@googlegroups.com
Hi Mark,

I just pushed up my latest implementation for the LeCroy scope on my 'develop' branch after I took in Alex's latest master. You can poke around it here: https://github.com/ceeeeej/python-ivi/tree/develop/ivi/lecroy

I've been working on the triggering implementation and hoping that I also squashed a few errors I had in some parts - I will thoroughly test on Tuesday. What I just put up is not fully tested yet and I just messed with it (probably too much at once) since I rebased my changes over the latest master.

Some of the LeCroy implementations are different than what Agilent uses (I originally copied agilentBaseScope.py as my starting point for lecroyBaseScope.py). This is making me rewrite a lot for the LeCroy scope.

What type of commands are you interested in? Retrieving waveform data and points? I haven't touched that yet myself in the LeCroy driver - I have implemented the screenshot / print function to read out the display as an image though.

Regards,
Chris
Reply all
Reply to author
Forward
0 new messages