Collecting data from measurements devices using USBTMC, SCPI, Python and R

High end test gear allows two-way communication with PC to set measurement parameters and to send the measured data to PC for further analyze. On PC side there are applications for this (LabView, BenchVue), but they are expensive. One option is to make own program/script that will communicate with the device and parse/present measured data - this approach I will present it in this post. The tool I'm using it with is 34460A(digital multimeter).

Below is an example of the measurement graph made using this home-made software.

The module of communication with the device I made in Python, it stores data to .csv file, that is later parsed by a script in R and the output graph is stored as .png image. The R part could ass well do some numeric stuff and print it on STDOUT, but for me that was not the case.

Initially all was in Python, but I didn't like Python's graphs, they weren't visually nice.

Python part when started will save measurements to the .csv file constantly, at any time, user can run R script to create new graph.

Installation steps

Assuming device driver correctly enumerate in the Device Manager (if not one needs to install its drivers first).

  • Install Python and R, add them to Path (environment variable).
  • In R, install following packages: latticeExtra, gridExtra, grid.
  • In Python install following packages: usbtmc, pyusb.
  • On Windows, download libusb-win32 and follow README steps to bind it to the device. In addition it didn't work for me if I didn't run the tool as an Administrator. If everything went ok, device will be visible in Device Manager in branch named libusb-win32 devices.
  • Download Python/R scripts, they are available via my IonizationChamber repository.
  • In main.py, replace idDMM with id of the device.

For usbtmc, I got the same problem as described here, fortunately the fix presented in that thread fixed it, so please check it if you have some weird stacktrace errors in Python.

Usage

I made those scripts for my personal use, so they may be a bit awkward to work with, but once the setup is done, everything should work fine.

  • Set meassurement type and range on your device (this could be also done via python script)
  • Start python script
  • Run R script, it will create results.png file with graphs.

That's all.

0 commentaires:

Post a Comment