Tutorial: An Open Source Solution with PSLab, Python, and OpenTAP

Tutorial: An Open Source Solution with PSLab, Python, and OpenTAP

Introduction to Opentap and PSLab

In this video, Ivan explains what Opentap and PSLab are and how to get started with them.

Opentap

  • Opentap is an open-source test sequencer primarily used for test automation.
  • To install Opentap, go to opentap.io, click the download button, and choose your preferred operating system.
  • After installing Opentap, you will have access to the editor package manager and results viewer.

PSLab

  • PSLab is a small USB-powered hardware measurement device developed by FOSS Asia and Opentac.
  • It has many digital instruments built into it such as an oscilloscope multimeter wave generator power source.
  • You can also plug in any compatible I2C standard sensors to the PSLab pin slots.
  • To create a PSLop plugin for Opentab we will need to install the python plugin.

Installing Python Plugin for OpenTap

  • To install the Python plugin through the package manager, open the community edition editor of OpenTap, go to tools and click on the package manager.
  • Click install on the Python plugin that appears after searching for "Python" in the search bar.
  • The Python plugin allows new plugins to be developed entirely in Python language instead of C sharp.
  • The Python plugin also provides additional CLI actions besides the ones provided by OpenTap itself.

Creating a Python OpenTap Plugin using PSLab

  • Alex explains how to create an instrument plug-in in Python, write a test up in Python, and build both of those into a plug-in that we can then use in OpenTab.

Creating a Plugin for OpenTAP

In this section, the speaker explains how to create a plugin for OpenTAP and introduces the waveform generator instrument class.

Creating an Instrument Class

  • The waveform generator instrument class is extended with the instrument type from OpenTAP.
  • The open and close default methods are added to the instrument class. These methods can be used to add functionality to the instrument and help it register with connection handlers.

Adding Connection Handler Class

  • A connection handler class is added to handle connections between the program and the PSLab hardware board.
  • The connection handler creates a single connection that is used for two different instruments in this demo - waveform generator and oscilloscope.

Functionality for Instruments

  • The open method of waveform generator creates an instance of a waveform generator from the PSLab board. This will be used in conjunction with test steps to make calls to the waveform generator.
  • The generate method exposes PSLab APIs generate method to other plugins in the repository. It will be used by test steps again to call into Python API of PSLab board and generate a waveform.
  • Same steps are followed for creating an oscilloscope instrument which has a capture method instead of generate method.

Creating Test Steps

In this section, we learn how to create test steps that use instruments created earlier.

Generate Sine Wave Test Step

  • A generate sine wave test step is created to generate a sine waveform.
  • The run method is added to the test step class which is called when the test step is executed. This is where we add the bulk of functionality for the test step.

Conclusion

This transcript explains how to create a plugin for OpenTAP and introduces the waveform generator instrument class. It also covers adding connection handler class, creating functionality for instruments, and creating test steps that use these instruments.

Creating Test Steps for Instruments

In this section, the speaker explains how to create test steps for instruments in OpenTAP.

Adding Parameters to Test Steps

  • The run step contains a line that calls into the waveform generator and generates the sine waveform.
  • These lines add parameters to the test step that can be changed inside the editor. For example, we add a frequency, phase, and pin.
  • The test steps have an instance of the instrument that they will call into by calling in this case the generate method.

Measure RMS Voltage Test Step

  • The measure rms voltage test step calculates a sample count and time gap using a helper function and captures actual data from the oscilloscope.
  • It then does some calculations to get the rms voltage from the captured data and publishes results to be used in result listeners such as graphing or csv pipelines.

Building a Plugin

In this section, we learn how to build a plugin after creating instruments and test steps.

Creating Two Instruments

  • We created two instruments - waveform generator and oscilloscope.
  • We modified an initial init file by removing old plugins or parts of plugins from it and adding our individual test steps as well as two instruments that we added.

Building a Plugin

  • Once we've added all four different parts of our plugin into the init file, we can now build it using a shell command.
  • To build the plugin, we run the tap python build command followed by the name of the plugin which in our case is pslab.
  • We successfully built two instruments, made two test steps, and then built all of those into a plugin.

Using OpenTAP Community Edition Editor

In this section, Ashton Humphrey explains how to use the OpenTAP community edition editor.

Test Steps

  • The community edition of the editor should come set up with test steps on the left and test sub-settings on the right with a test plan in the middle.
  • Under ps lab, we have generate sine wave and rms voltage as our test steps.

Test Plan

  • The test plan is used to add these test steps that will be available here in our test plan.

Log Panel

  • The log panel is used to view what is happening during execution and information being printed here after running the program.

Testing the PSLab Sine Wave Generator

In this section, we learn how to test the PSLab sine wave generator using OpenTAP.

Adding Instruments

  • Click on "Add New" to add instruments.
  • Add waveform generator and oscilloscope by clicking on the plus sign.
  • Click "OK" to close.

Generating a Sine Wave

  • Go to the left side and click on "Test Steps".
  • Remove parameter range by clicking and dragging it to the top.
  • Make sine wave and RMS voltage children of sweep range by clicking on both of them.
  • Drag them inside sweep range.
  • Click on sweep range to edit the output of our graph. Set start frequency at 100 Hz and stop frequency at 10,000 Hz.

Running Test Plan

  • Run test plan by clicking on the green arrow.
  • When completed, go up to tools results here.
  • From here you see our x-axis as frequency or y as voltage around 5000 hertz you see it start to drop
  • You can change x and y axis or chart type to histogram.

Conclusion

We have successfully tested the spec of the board using OpenTAP. We learned how to create a test step, run it, and use OpenTAP to create Python plugins for our PSLab board.