SCPI Programming: How to Send Commands


SCPI Programming: How to Send Commands

SCPI stands for Standard Commands for Programmable Instruments based on the IEEE 488.2 that introduced a standard digital interface, also called the SCPI standard.

It is a standard language used for controlling instruments such as an output voltage on power supplies, reading values on a digital multimeter, setting parameters on function generators, and more. SCPI commands are ASCII characters, making them easily readable and interpretable by humans.

This article will explain how you can program and send SCPI commands to control instruments. Going into which interfaces to use and what tools are available for you to download.

What kinds of Instruments use SCPI?

SCPI is widely used to control instruments, in both benchtop and portable formats. Oscilloscopes, digital multimeters, spectrum analyzers, power supplies, function generators, and many more can be controlled using SCPI commands.

This is great for automating manual button presses to for example query a current value or use a set command to change values in the instrument. All done with simple ASCII strings.

How does SCPI Work?

SCPI programming involves sending commands to a device through a physical layer such as GPIB, USB, or Ethernet.

These commands instruct the instrument to perform specific tasks such as taking measurements or changing settings. The SCPI syntax shows both generic commands and specific commands. The instrument then responds with a command response, confirming that the task has been completed.

There are two types of a SCPI command: queries and commands. Queries request information from the instrument, while commands instruct the instrument to perform an action. Both types follow a specific syntax which includes a header, command header, and termination character.

If you want to learn all about SCPI commands and their syntax then you can learn much more in our article: An Introduction to SCPI Commands where we have you covered.

Choosing an Interface

To program and send your first SCPI command, you'll need to connect your instrument to a computer or controller using an interface. This interface serves as the physical communication layer, enabling the interaction between the instrument and the computer.

In addition, exploring virtual instrument software architecture (VISA) can enhance your understanding of the underlying framework that enables seamless integration and control of instruments through software interfaces.

GPIB (General Purpose Interface Bus)

The general purpose interface bus also known as IEEE-488, this interface uses parallel communication to connect up to 15 instruments. GPIB has been used for decades and is still prevalent in many industries. It can achieve high data rates but requires expensive hardware.

USB (Universal Serial Bus)

The USB interfaces is commonly used for connecting a single instrument to a computer. USB interfaces is popular due to its plug-and-play capabilities and support for high-speed data transfers. Lastly USB interfaces It is also more affordable than GPIB and Ethernet interfaces.

Ethernet

Ethernet interfaces allow for remote control of instruments over a network connection. This option is used when the instrument needs to be controlled from a distance or in an automated testing environment.

The physical and electrical bus you choose will depend on the type of instrument from different manufacturers and your specific needs.

Tools for SCPI Programming

There are various tools and programming languages available for sending SCPI commands, depending on your specific needs and preferences. Some popular options include:

SAFE

We have developed a platform that is specifically designed to remote control SCPI devices and perform automatic testing.

It does not require any coding so it is very simple to get started, and it can be expanded to more advanced test sequences and data analysis if you are more experienced. You can start a trial and download it now here:

LabVIEW

A graphical programming environment from National Instruments is commonly used for controlling instruments.

LabVIEW with SCPI simplifies creating complex test and measurement applications. It offers extensive support for instrument drivers, but it has a steep learning curve, high license costs, and may lead to unnecessary complexity for simple tasks.

Python

Python is known for its vast library support and data processing capabilities, making it a good choice for programmers.

It has packages like PyVISA and PySerial that can manage communication with SCPI devices, simplifying the task of writing and deploying scripts. However, Python lacks the specialized development and debugging tools that come with dedicated SCPI environments like SAFE and LabVIEW.

MATLAB

MATLAB is a programming and data computing environment used in scientific research. It has powerful data computation capabilities, making it ideal for instrument data processing and data analysis.

It has a built-in toolbox for easy SCPI communication, but it's costly, especially for commercial use. The syntax is relatively straightforward, but it can be challenging for non-programmers.

Power Supply Example

Let's take a simple example of how to send common commands like how to to control the output voltage on a programmable power supply via a USB interface using our tool SAFE mentioned in the above examples. This could of course as easily been have a digital multimeter or different models.

We will make both set commands to change an output state, make query operations to get different values, and make multiple commands at the same time. Check out the video below.

The above example demonstrates the ease and simplicity of using USB interfaces and SCPI to read values using a query operation, and setting values, like output voltage or similar commands, with a set operation.

Tips and Tricks for Efficient SCPI Programming

SCPI programming is a powerful tool used to automate and streamline procedures in instrument control. However, learning to use it efficiently is key to maximizing its benefits. Here are some tips and tricks to get the most out of your SCPI programming experience:

Understand the instrument manual

Each instrument manual has common commands and a unique set of command syntax, and understanding the manual will make it easier to navigate and use these commands.

Use Query Commands

A Query operation allows you to query or request a programmed value from the instrument. Use queries for example to verify an output state or query a numeric parameter to use for example in your test.

Use Standard Commands

Standard commands are general and widely supported across instrument manufacturers. They offer a consistent approach to programming different types of instruments, making it easier to switch between devices.

Utilize Error Checking

SCPI instruments have built-in error queues. Consider incorporating error checking in your code to track and resolve issues efficiently.

Short form syntax

Many SCPI instruments support short form syntax, which allows you to omit unnecessary parts of the command. For example, instead of writing the long form "SET:VOLTage 5", you can write "VOLT 5". Check your instrument manual for supported shortcuts

Use Command Sequences

Instead of sending commands one by one, you can send a sequence of commands all at once. This can significantly reduce the communication latency between your program and the instrument.

Remember, efficient SCPI programming comes with practice and experience. So, keep experimenting and honing your skills to become proficient.

Avoiding Common Mistakes in SCPI Programming

While SCPI programming can be a powerful tool for controlling remotely controllable instruments, it also comes with its share of pitfalls. Here are some common mistakes and how you can avoid them.

Ignoring the Instrument's Manual

While SCPI is a standard language, different manufacturers and models may implement it differently. Always refer to your instrument's manual for specific SCPI command sets and implementation details. Avoid assuming universal command applicability.

Neglecting Error Checking

SCPI commands may not always execute as expected, leading to inaccurate results or errors. Regularly check the instrument's error queue to identify and resolve issues promptly.

Overlooking Command Ordering

SCPI commands follow a specific order of execution. Not adhering to this order may result in incorrect operations. Ensure to structure your code in a way that reflects the correct command sequence.

Not Utilizing Query Commands

A Query command is designed to confirm the execution of SCPI commands. Neglecting to use them might lead to an assumption that all commands are executed correctly, which may not always be the case.

Remember upper and lower case

SCPI standard is case-insensitive when it comes to valid commands, but always ensure to use the correct upper and lower case for values like units or options.

Remember the question mark

Many instruments use the question mark symbol "?" to indicate a query command. It is important to include this symbol in your code for proper execution.

By being aware of these common mistakes and taking steps to avoid them, you can significantly enhance your SCPI programming efficiency and effectiveness.

Examples of Commands in Different Applications

Command syntax shows that many of the following commands have the same type of syntax, meaning one or more keywords repeats the same class of words. Some examples of different types of test equipment can be seen below:

  • Multimeter: MEASure:VOLTage:DC? - used to measure DC voltage
  • Oscilloscope: MEASure:VOLTage:AC? - used to measure AC voltage
  • Spectrum Analyzer: CALibration:FREQuency:SPAN? - used to query the frequency span of the instrument's calibration.
  • Arbitrary Waveform Generator: SOURce1:IAMPLitude? - used to query the amplitude of a signal from source 1.
  • Signal Generator: SWEep:COUNt 10

These are just a few examples of the commands used in different applications. Each instrument has its own set of commands, and the syntax may vary depending on the manufacturer and model. It is crucial to refer to your instrument manual for specific command sets when programming with SCPI

Conclusion

In conclusion, SCPI programming serves as a versatile tool in the realm of instrument control, capable of significantly increasing efficiency when used correctly.

We've discussed various platforms that facilitate SCPI communication, such as SAFE, LabVIEW, Python, and MATLAB, each with its distinct strengths and limitations.

We've also delved into some handy tips and tricks for effective SCPI programming and common pitfalls to avoid for enhanced efficiency and effectiveness.

Moving forward, with the increasing complexity of instruments and the demand for automation, SCPI programming is likely to evolve and grow in importance.

The potential for more powerful and diverse SCPI commands, coupled with enhanced programming environments, makes it crucial for professionals in scientific research and industry to stay updated and continually hone their skills in SCPI programming.