Python demonstration script – how to understand our script and adapt it to control your instruments

Introduction

Razorbill Instruments sells equipment that forms part of a scientific experiment.  Most users want to combine our products with other components from other vendors. This would include cryostat components such as temperature and magnet controllers, and measurement instruments such as lock-in amplifiers.

It’s not practical to provide universal software for every possible combination, so most labs end up writing some degree of bespoke code.  There are several popular languages for doing this (e.g. LabView, Matlab, Python), and there are projects in those languages (e.g Qcodes or Pymeasure) that offer toolkits and many advanced functions for lab automation. Razorbill Instrument’s technical director Jack has written a couple of blogs on the topic of lab automation and instrument communication which you can find here.

This example script is for people who have chosen Python as there preferred language, but are looking for something simpler than Qcodes or Pymeasure.  This script demonstrates how to send instructions to our RP100 power supply; measure the feedback sensor with a Keysight E4980AL LCR meter (the most popular option for our customers); convert capacitance to displacement; and record the results to a csv file that you can open in Microsoft Excel, python, or any other data analysis system.

The script isn’t the simplest is could possibly be, it includes some extra components that we consider good practice, but it still fits in a single file of some 190 lines. An even simpler example of controlling an RP100 is given in the RP100 manual, but that doesn’t include the LCR meter or saving data to a file.

The simple example in the manual uses Python’s serial module. This is nice and simple, but only works for serial or virtual serial instruments.  The LCR meter is a TMC device (Test and Measurement Class). Python’s direct support for TMC is weak, so I’m using VISA to bridge the gap.  This has the added advantage that visa makes all connections look the same, so they can be written to or read from using the same commands.  This does mean that you have to install a visa implementation in order to use this script.

Throughout this supporting documentation I refer to sections of code by comment numbers e.g ‘# 02’. These are in numerical order and you can search for them (include the # in the search box) to find the section of code I’m referring to. As long as you don’t delete the comments this will work even if you’ve substantially edited the file and line numbers have changed.