Read a Kurt J. Lesker Pressure Gauge Controller in Python

Read a Kurt J. Lesker Pressure Gauge Controller in Python

View the app user interface

This Dash DAQ application written in Python lets you make clean, modern UI components to facilitate the readout of a Kurt J. Lesker pressure gauge controller.

Integration is simple: we used PySerial and an RS232-to-USB cable to allow Dash DAQ to interface with the MGC4000 controller. But modules like PyVisa can be used as well!

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

The Dash DAQ app

Firstly, we’ll import the necessary libraries from Plotly’s Dash libraries, and some general Python packages:

Note the import of the class MGC4000 from the module kurtjlesker_instruments. This Python module was coded separately to wrap around the instrument’s manufacturer-provided communication protocol. We keep our code modular this way – if a user wants to interface with a two-gauge controller, they can simply create two instances of this class, instead of copying and pasting the code.

Creating the layout

Like with any Dash app, we’ll establish the layout of our app first. This app will have two sections: the top will resemble a control panel for the gauges, and the bottom will display the instrument’s readout.

For the top section, we unpack some information about the instrument’s layout from the class MGC4000 in the module kurtjlesker_instruments. We’ll learn more about the instrument’s layout below. Right now, the only thing we need to do is to create an instance of this class:

Note that the mock argument is set to True, allowing users to test the app without a live connection to the instrument. By default, it will create a gauge controller with four gauges in millibar, named P1 through P4 . For custom gauge numbers, names, and units, the argument gauge_dict can be passed to the instance of the class:

Now, the instrument is virtually placed inside an instrument rack, as would happen in an actual lab. Here, the instrument_rack is simply a list of instrument classes:

Next, each instrument in the rack iteratively calls its method setup_layout. This will automatically set up the layout from the code in the kurtjlesker_instruments module by returning an HTML layout with that instrument’s specific Dash DAQ components.

Components are defined as an attribute of the instrument, to allow more than one layout of the same instrument in future versions.

A list of Dash DAQ Gauge components is created with self.gauge_list. The Dash DAQ components, PowerButton, StopButton, and Indicator, are defined upon initialization of the instrument class, as self.power_btn, self.connexion_button, and self.mock_indicator:

The components are then arranged into the HTML layout of the gauge controller, which is returned by the method setup_layout:

The first line of the instrument layout contains the power button and the custom name of the gauge controller:

The second line of the app layout allows you to textually enter the instrument port with which to connect. There is also a drop-down combo box where the user can choose which gauges to read from. The last item on this list is an indicator component indicating if the instrument is in mock mode:

The third line in the layout contains the list of gauges. They have many options for settings, including maximum and minimum ranges, display units, log or linear, etc.:

That’s it for the top gauge controller aspect of the layout!

The bottom aspect of the layout is defined in the main app file. We’ll use a Dash DAQ StopButton component to start and stop the measurement. This will trigger the method measure of each instrument for each of their gauges in the drop-down menu. A second Dash DAQ Indicator component will turn on, to show that the measurements are running:

Beneath, an interactive graph from Dash’s core components displays measurement readouts:

Creating the callbacks

Callbacks for the user’s click on the “Start” button are defined to set the indicator component’s value is_measuring to True:

A Dash core component graph is updated via a callback triggered by another Dash core component, Interval:

The callback is only effective when the value of Indicator is_measuring is set to True.

The gauges are set to the correct value via callbacks which are defined in the class MGC4000.

The callbacks are generated automatically by calling the generate_callbacks method of the class MGC4000.

This way, each gauge will have a unique identifier generated automatically, and a callback is assigned to each gauge in the layout, without having to copy and paste.

Finally, we load the callbacks into the main app by calling the instrument’s method:

See it all come together in our demo app.

With the power of Dash and Dash DAQ, you can reproduce hardware changes and create clean UI components in your lab, all in Python. The full source code for this app and the other example apps comes with the purchase of a Dash DAQ license!