Read an Agilent 34401A Multimeter in Python

Read an Agilent 34401A Multimeter in Python

View the app user interface

Multimeters are a common lab instrument – now you can write a user-friendly GUI to control and read one, using just Python! Dash DAQ makes it possible.

Check out the demo app, and keep reading to see how we made it.

The setup

We created a serial communication line by using the PySerial API and a Prologix GPIB-USB controller to connect the HP Agilent 34401A Multimeter to the computer. It is also important to set the programming language of the multimeter to your preference – in our case, we chose SCPI.

The Dash DAQ app

For starters, we import the dash_daq, dash, pyserial, numpy, and random:

 

Using PySerial, we open and set up the serial communication line.

The app layout

Similar to other Dash apps, we create the app’s layout by describing what Dash DAQ components we want, and where.

In this block of code, we used a Dash DAQ LEDDisplay component to create a visually appealing and responsive interface that is easily integrated with HTML components:

Interactivity with callbacks

Now, to make our app responsive using Dash callbacks.

For this first callback, we use a NumPy array to determine the desired function of the multimeter. n_clicks_timestamp returns the timestamp of the most recent button the user clicks. This value will be the largest number in the array, so using np.argmax() will give us the index of the most recently clicked button. We return this value as ID button-press, which is used throughout the program.

In this callback, we use SCPI and PySerial to send and receive commands from the multimeter. Values sent over serial communication need to be encoded into ASCII, and decoded again on the PC.

In the code below, “MEAS:VOLT:DC? {},DEF\n” is a SCPI command telling the device to measure DC voltage. The multimeter responds with a string, which we split into half_one and half_two. We make the appropriate calculations to format the response to eleven characters, which are returned to the eleven LED display components at the top of our app.

When the multimeter is asked to display more data than it can handle, it enters into overload or “OVLD”. In this app, when the data is to the power of a value greater than six, overload occurs. A response of 999999999 is returned to the LED displays with ID meter-display and parameter value.

With Dash, callbacks can be made to disable Dash components unless certain conditions are met. This code is used to disable commands when one is already selected:

Dash DAQ makes it simple and easy to create an interactive GUI for complex laboratory devices. Play with this demo app, and purchase a Dash DAQ license to access the full source code for this app and the others!