Data from device using SCPI and the usbtmc kernel driver
Connected up my Tektronix TDS 2012C to my Linux based computer and learned a bit I thought may be useful to others.
Topics include
Permissions for the usbtmc device
Hello world
5 Second Delay Reading usbtmc Device
Get a Screenshot
Getting and Plotting Data with gnuplot
Misc Commands I Sent to my Tektronix Scope
I have been experimenting with this scope on and off and have lost track of many references but here are a few:
Wikipedia about SCPI
Awesome c program
Permissions for the usbtmc0 device
The device when connected, in my case, created /dev/usbtmc1. Not sure why its 1 and not 0. One issue is a ‘normal user’ doesn’t have permissions to do anything with it. Two options here. One is to just ‘sudo chmod 666 /dev/usbtmc1’. The next is more permanent and recommended.
Create a file ‘/dev/udev/rules.d/86-tmc.rules’ with the following in it.
Then run: ‘udevadm control –reload-rules && udevadm trigger’
Hello World
First a simple test. If you ask the device to ID does it?
One point of note here is the ‘Connection timed out’ after about 5 seconds.
5 Second Delay Reading usbtmc Device
I spent more time on this then I will admit. From some reading of others posts the kernel driver usbtmc doesn’t set the EOF bit so it just times out. This sucks! It means all my simple techniques can still work but will have a 5 second delay on read.
I tried many things and the only one that worked for me was this. The code came from https://github.com/dpenkler/linux-usbtmc/blob/master/ttmc.c and I just reduced and slightly modified to work for what I wanted to do. It works without the 5 second hang time. It does NOT work for commands that may return more then 1024 bytes. For those commands I still use echo and cat at the command line.
I compile it with ‘gcc -o send_this thecode.c’
With it I can do things like this:
Get a Screenshot
This has been around a while so I don’t have my reference(s).
Use like this: ‘./thescript.sh bla.jpg’
Getting and Plotting Data with GNUPlot
I use this to get the raw data points. There is a lot of informatin missing such as formating the data, what data we’re taling about, etc. That information is in my TDS 2012C programmers manual. There are lots of options and you should be looking in your specific devices manuals.
Now I have a file with 2500 values all in one big line seperated by commas. It looks like this: 32,32,32,-21,-30,-31,-31,… For plotting it I use gnuplot. I use the following configuration file curv.gnuplot
I get the plot by running this: gnuplot -p -e “filename=’result’” curv.gnuplot
It looks like this:
Misc Commands I Sent to my Tektronix Scope
Just some random commands I experimented with. I didn’t notice any case sensitivity when sending them. These commands were found in the Tektronix Programmer manual (077-0444-03) for my TDS 2012C osilliscope
*IDN?
ch1:scale?
DATA:SOURCE?
DATA:SOURCE REFA
MEASU:IMMED:TYPE CUR
MEASU:IMMED:VALUE?
HARDCopy:PORT USB
HARDCopy:FORMat JPEG
HARDCopy STAR START
HARDCOPY START
DATA INIT
DAT:ENC ASCII
CURV?