What you need
Controlling an instrument from a program requires two things: a physical channel and a common language. The channel can be LAN, USB, GPIB or a serial port. The most widespread language in instrumentation is SCPI, a set of text commands with a hierarchical structure, so that instruments from different manufacturers share names for similar functions. A software layer such as VISA hides the differences between interfaces and lets you open a session with an address and send or read strings.
Commands and queries
Commands configure or execute something; queries end with a question mark and return a response. There are common commands defined by the IEEE 488.2 standard, such as the instrument identification query, reset and the operation complete query. All other commands depend on the instrument, so the model’s programming manual is the essential reference: SCPI does not guarantee that two models accept exactly the same commands.
Synchronization
Many commands take time to complete, such as a sweep or a measurement with long integration. If the program sends the next instruction or reads the result too early, it gets stale data or errors. This is solved by querying the operation complete status, waiting for a service request, or sizing wait times with ample margin. Fixed waits work, but they are fragile.
Error control
- Check the instrument’s error queue after configuration sequences, because a mistyped command does not always interrupt the program.
- Set read timeouts so that an instrument that does not respond does not leave the program hanging.
- Pay attention to line termination characters, which the instrument and the software layer must agree on.
Good practice
- Verify the instrument’s identity when connecting.
- Put the instrument in a known state at the start.
- Isolate each model’s specific commands in a layer of their own, so that changing instruments does not force you to rewrite the test logic.
- Log the commands sent while debugging.
How to interpret a failure
If a command has no effect, first check the syntax and the error queue; if the instrument stops responding, check the connection and whether it is in remote or local mode.