4. VISA in Programming Languages

There are many programming languages offering the possibility to remotely control Test & Measurement instruments.
In this guide, we focus on:

  • Python in R&S Forum
  • Python in PyCharm
  • MATLAB®
  • C# in Visual Studio Development Environment
  • LabVIEW™
  • ANSI-C in LabWindows/CVI™

In the following sub-chapters, we discuss advantages and disadvantages of each language. Included ready-to-use example for each of these languages should help you getting started. The screenshots emphasize simple code change in case you change physical connection to your instrument. They also show used layers between the application and VISA.

An installation of VISA is the common precondition for all the examples below.

Python in R&S Forum

Advantages: Easy to use, specially developed for instrument remote control, multi-platform, also offers interactive console.
Disadvantages: Difficult to develop GUIs, the environment is not suitable for bigger projects.

In R&S Forum, you change the instrument resource string in menu item Settings -> Instruments. The session to the instrument is opened with the first communication attempt. See more in the dedicated application note 1MA196

This example script is available for download here

Python in PyCharm

Advantages: Intelligent code editor, safe refactoring, allows for tracking code changes, excellent debugger, also available for Linux
Disadvantages: Missing compiler means you code is only tested for errors during execution.

Generally, in Python you use PyVISA component - a wrapper of the ANSI-C visa32.dll library. First, you have to create a ResourceManager object. The resource string you change in the method open_resource()

This example script is available for download here

MATLAB

Advantages: Simple scripting language, including easy GUI designs.
Disadvantages: No multi-threading, bulky executables.

In MATLAB you change the resource string in the VISA Open() method. The rest of your script is unchanged. See more in the dedicated application note 1MA171

This example script is available for download here

C# in Visual Studio

Advantages: State-of-the-art programming environment, optimized for high performance.
Disadvantages: Requires advanced programming knowledge.

In Visual Studio C#, you use the Ivi.Visa assembly installed together with your VISA installation. You only have to change the resource string in the VISA Open() method.

This example project is available for download here

LabVIEW

Advantages: Ideal for engineers without the need for advanced programming skills, specially developed for instrument remote control applications.
Disadvantages: Lower performance by graphical tasks, difficult to compare versions due to graphical source code.

In LabVIEW, you change the instrument resource string for the LabVIEW function VISA Open. The session stays valid even if your program stops. If you are using instrument drivers, refer to the dedicated application note 1MA228

This example VI for LV2010 is available for download here

ANSI-C in LabWindows/CVI

Advantages: ANSI-C environment targeted for instrument remote control.
Disadvantages: Requires advanced programming knowledge.

In C/C++, you change the resource string in the viOpen() function. First, you need to open a resource manager with the function viOpenDefaultRM().

This example project is available for download here

International Website