QA401H, REST and Python

Release 0.94 of QA401H is up at Github. Release 0.94 moves a step closer to shipping the headless version of the QA401 control software, and measurements made with QA401H should now be agreeing very well with the QA401 GUI.

The goal of the QA401H application is to provide a cross-platform means for controlling the QA401 hardware from any language via a REST interface. And given the popularity of REST, you can bet your language supports it out of the box. 

The REST interface direction continues to prove its worth as we hear from more developers that are using it with great success in their test setups. Today, we'll look at a quick example in Python. The aim here is to show just how easy it is for any language that supports REST to make a measurement on the QA401H hardware.

To replicate this short example, you'll need to do the following:

1) Download and unzip the QA401H release. It is located here.

2) Unzip the release to your directory of choice.

3) Navigate to the 'publish' folder in the unzipped direrctory, and from a command prompt type 'dotnet qa401h.dll'

At that point, you should see the QA401H command line up startup (see the previous post here if you'd like more details on getting this setup on a Linux OS).

The following Python code will make a THD measurement on both the right and left channels

import requests

# Set max input level to +6 dBV (attenuator off)
resp = requests.put('http://localhost:9401/Settings/Input/Max/6')
# Enable audio generator 1 @ 1 KHz and -10 dBV
resp = requests.put('http://localhost:9401/Settings/AudioGen/1/1/1000/-10')
# Specify we want 32k FFT
resp = requests.put('http://localhost:9401/Settings/BufferSize/32768')
# Start acquisition. This will block until acquisition is finished
resp ='http://localhost:9401/Acquisition')
# Request the THD measurement
resp = requests.get('http://localhost:9401/ThdDb/1000/20000')
# Display results
print('THD Left:', resp.json()['Left'])
print('THD Right:', resp.json()['Right'])

And that's it!

The Python console shows the results:

And the QA401H console shows the various HTML REST requests the Python code made:

Note in the above how quickly the various REST commands completed. It is generally on the order of single digit milliseconds. 

Drop us a note if you need an API added to the interface. 


 If you liked the post you just read, please consider signing up for our mailing list at the bottom of the page. 

Leave a comment

Please note, comments must be approved before they are published