Introduction

When using a text based language, such as Visual Basic, Visual C++, Visual Java, MATLAB, or Python, it is a quick and easy way to start remotely controlling your oscilloscope. This document is intended as a getting started guide for using the Python language with ActiveDSO to remotely control a Teledyne LeCroy oscilloscope.

At the time this document was written there were two production versions of Python, 2.7.6 and 3.3.3. Some existing third-party software was not yet compatible with version 3.3.3. As a result, Python 2.7.6 was used.

System Requirements

  1. ActiveDSO on controlling PC: http://teledynelecroy.com/support/softwaredownload/activedso.aspx?capid=106
  2. Python: http://www.python.org/
  3. Python for Windows Extensions: http://sourceforge.net/projects/pywin32/files/pywin32/Build%20218/

Note: Please install the software in the order listed. It is important that the version of Python for Windows Extensions and the base Python installation versions match. For example, if the Python version is 2.7.x, then the version of Python for Windows Extensions should also be 2.7.

Step 1: Create new Python script

Open the PythonWin application and create a new Python script by selecting File > New.

Step 2: Configuring the oscilloscope for TCPIP communication

Select Utilities > Utilities Setup from the drop down menu at the top of the oscilloscope’s display. Then select the Remote tab and press the TCPIP (VICP) button. Take note of the IP address of the scope.

Note: You may use any connection type that your oscilloscope supports with ActiveDSO. This tutorial uses TCPIP since it is the most common. See the ActiveDSO help file for more information on using the MakeConnection method with other connection types.

Step 3: Connect and interact with the instrument using Remote Control commands

In the newly created Python script enter the following code to connect to the device, change the volt/div setting on Channel 1 to 20mV, and then disconnect from the device.

import win32com.client #imports the pywin32 library
scope=win32com.client.Dispatch("LeCroy.ActiveDSOCtrl.1") #creates instance of the ActiveDSO control
scope.MakeConnection("IP:127.0.0.1") #Connects to the oscilloscope. Substitute your IP address
scope.WriteString("C1:VDIV .02",1) #Remote Command to set C1 volt/div setting to 20 mV.
scope.Disconnect() #Disconnects from the oscilloscope

Save the new script and then select File > Run from the PythonWin drop down menu. After running the script you should see your volt/div setting on Channel 1 change to 20mV.

Step 4: Connect and interact with the instrument using Automation commands

Create a new python script and enter the following code. This code will display the parameter table and change the P1 parameter to a mean measurement.

import win32com.client #import the pywin32 library
scope=win32com.client.Dispatch("LeCroy.ActiveDSOCtrl.1") #creates instance of the ActiveDSO control
scope.MakeConnection("IP:127.0.0.1") #Connects to the oscilloscope. Substitute your IP address
scope.WriteString("VBS app.Measure.ShowMeasure = true",1) #Automation command to show measurement table
scope.WriteString("""VBS 'app.Measure.P1.ParamEngine="Mean" ' """,1) #Automation command to change P1 to Mean
scope.Disconnect() #Disconnects from the oscilloscope

This script can then be run by saving it and then selecting File > Run from the PythonWin drop down menu.

Note: Triple quotes around the command to change P1 to Mean are required because the double quotes around the word Mean are part of the command string. Without the triple quotes Python would think that the first quote in front of the word Mean is the end of the command string. This is a common method used in Python for including quotation marks inside of a string.

Step 5: Return oscilloscope value using Automation commands

The final step in this tutorial involves using Automation commands to return a value. In this example we will again set the P1 parameter for a mean measurement and then return the value the oscilloscope reports. A new script can be created or the script created in Step 4 can be modified with the code below.

import win32com.client #import the pywin32 library
scope=win32com.client.Dispatch("LeCroy.ActiveDSOCtrl.1") #creates instance of the ActiveDSO control
scope.MakeConnection("IP:127.0.0.1") #Connects to the oscilloscope. Substitute your IP address
scope.WriteString("VBS app.Measure.ShowMeasure = true",1) #Automation command to show measurement table
scope.WriteString("""VBS 'app.Measure.P1.ParamEngine="Mean" ' """,1) #Automation command to change P1 to Mean
scope.WriteString("VBS? 'return=app.Measure.P1.Out.Result.Value' ",1) #Queries the P1 parameter
value = scope.ReadString(80)#reads a maximum of 80 bytes
print (value) #Print value to Interactive Window
scope.Disconnect() #Disconnects from the oscilloscope

Again, save the script and then select File > Run from the PythonWin drop down menu. After running the script you should see the mean value returned to the PythonWin Interactive Window.