Python application for running test equipment

Hi

I did my first Python application today. A simple application that controls my test equipment to do characterization of a power supply, efficiently, line/load regulation etc

The app pulls in information on a setup box to define key constraints, outputs the results to a file and plots relevant curves

(next step is to have the app generate a word document from the results)

Anyway, I want to add the ability to load config files and define different types of measurements, but before doing that, and spending time, is there something out there that has been done already?

I have all this working in Labwindows, did it 10 years ago, but want to use newer tools and add Python to the list of skills. Also it seems Python does this with a lot more condensed code

In the old days one could buy Test stand (also Labwindows, but I guess that’s very expensive)

I am using SCPI commands by the way

Regards

Klaus

I’m no python expert, but from what I understand its biggest weakness is lack of good gui tools. I use Xojo for all my desktop apps - it’s super-easy to make decent GUIs with it, the IDE is available for Mac and Windows, and it can compile for Mac, Windows, and Linux targets. It’s very object-oriented, has simple, readable syntax, and has an extremely helpful user community.

Xojo doesn’t support python directly, but there’s a third-party developer offering a plugin that allows Xojo apps to easily communicate with python scripts.

I was actually looking at this recently because I need to write a controller for a specific piece of test equipment, but then I saw that the TE has a serial port, so I don’t need to bother with python VISA stuff at all, I can just talk SCPI with it over USB serial directly from Xojo.

I tend to avoid GUIs, but when people want them on Python my choices are (a) Remi, for browser-based GUI , (b) built-in HTTP server for JSON exchanges against an HTML5 and JavaScript UI in browser, © Qt, (d) GTK, and (e) Tcl/Tk. I whipped up a Remi GUI for a demonstration of a three axis robot yesterday at a telescope. Just a few buttons to push on a phone in browser. Went well.

Nothing springs to mind though on @kvk’s functional description.

So you typed this comment into the command line? :grinning:

A google search taught me that the Remi were a Belgic tribe dwelling in the Aisne, Vesle and Suippe river valleys during the Iron Age and the Roman period, but didn’t provide any leads for gui-building software - can you share a link?

Yes, there’s a command-line interface; just reply to mail notifications using a command-line mail client. :grin:

Here you go;

1 Like

I’ve seen Python used as a test runner in a couple instances, but haven’t come across a good framework that’s available. You would there would be an open source project/repo somewhere that helps with this.

I’d echo the Python = bad at Guis comments. I only have mild experience with Qt, and it seems fine? If you can avoid the GUI aspects (especially if you’re still learning Python), I’d recommend that.

The main thing I’d recommend when learning Python is to get PyCharm as the IDE. It’s rather heavy weight in terms of resources, but the benefits it provides are enormous. The main one being that it has a code checker that follows the PEP guidelines and helps you write better code. You could also use pylint, but this is built in to the IDE and runs continuously. It’s also better about not poisoning the instance of Python you’re using, unlike Spyder. (I’ve had to debug too many problems that are specifically related to some “feature” that Spyder decided to add.)

I did a Python-based project earlier this year which required a minimal GUI. I wanted something that was very light-weight and ended up using eel. For my purposes, it worked very well.

The Chrome browser acted as the CSS+HTML render engine, and eel’s Python <-> Javascript messaging mechanism allowed browser events to trigger actions in the Python code, and the resulting Python execution would send messages back to the javascript to dynamically modify the document to update the display.

It was a very light-weight solution that allowed me to quickly implement a basic UI which was easy to design because I could just quickly hand edit the CSS, HTML, and javascript to change things around, without having to learn a massive framework.

It looks very nice indeed

I tried tkinter (Python library), but each object needs to be made in code (although very simple code)

Maybe a coincidence, but I am infact using PyCharm. Very nice tool suite :slight_smile:

Yes, it has been done many times. I have my lab automated this way, including Joulescope tests. If you want something that you repeat, like a manufacturing test station, you can check out my pytation library. If you want to create and run a test suite, you can leverage any of the python unit test frameworks, including unittest.

However, desires vary so much and it’s very easy to make your own. For trusted internal apps, I will often just use a python “config.py” file with a data structure that defines the configuration. It’s very fast to parse and develop. You can also use YAML, TOML, INI, JSON5, JSON, or some other format. Be aware that some of the formats can take much longer to parse (YAML is particularly slow), which can make a difference as the app grows.

For UIs, I tend to use Qt since I know it. I avoid tkinter/TCL like the plague it is. I’ve never use the web-based tools mentioned above, but they look interesting.

I also use PyCharm and CLion as my go-to IDEs. Visual Studio Code is also quite nice these days.

If you have to distribute your application to others, be aware that python packaging is a mess. See setup.py, joulescope.spec, MANIFEST.in, appdmg.json, and joulescope.iss in the Joulescope UI for an example of what to expect.

Also worth mentioning: I like to use Jupyter notebooks for both collecting test data and analysis. Notebooks are nice because you can execute chunks of code and the kernel holds state without needing linear execution of code. You can also use basic gui widgets like sliders.

1 Like

Since nobody here has mentioned it - PySimpleGUI rules!

It’s not the tool for making something like a Spotify app or some beautiful consumer desktop application, but if you need a GUI for a command-line-phobic client, it’s a breeze to use.

I did some searching on different GUIs and PySimpleGUI seems vey nice

Then I found a guy that has done a frontend for it. So you can layout the GUI, and it converts it to PySimpleGUI:

@kvk I would base the setup on a config file. Python already has a library for it called config parser.

I wouldn’t waste too much time on a GUI until I had it working from command line. GUI adds a lot of complexity to the program, but if it runs great for command line, it shouldn’t take too much work to add a GUI latter.

I agree. I will be the only one using it, so just changing a config file is probably the same time consumption as in a GUI

I know I’m the odd man out on this, but I use tkinter a lot. It uses a lot less resources than most other GUI libraries, and ships with python. I have written software that controls instruments and It has a great way to load config files. It also works great with pyinstaller so you can package everything into a .exe file! Here is a photo of the latest design (uses ttk styling).

I have used use GTK for my test GUIs.
I reccomend using the python interface for GTK.

Matplotlib uses GTK, and it is quite simple to integrate plots into a GTK GUI.

When it comes to GUI VS CLI. In my experience most of my colleagues are radio guys whom aren’t that comfortable with the command line. Giving them a UI really helps them. It also simplify things when the consulting contract ends and other people have to take over, or when the SW is handed to a production/test team.