A small python program to read/decode/plot/save the trace dump from the Rohde-Schwarz FSA Spectrum Analyzer that uses the GPIB bus to communicate with the PC. If you don't have an expensive GPIB interface like me, you might be interested in bulding a super easy one with just an Arduino Nano, a mutilated Centronics connector (yeah, you should have one in some closet from the days printers were connected by thick cables...) and a few interconnecting wires. The Arduino runs a slightly modified version of this code: https://github.com/JacekGreniger/gpib-conv-arduino-nano
In my home lab I have two R&S instruments: the FSAS spectrum analyzer and the SPMC signal generator. I have a GPIB cable connecting them and the Arduino interface piggybacks on one, then the USB cable goes to the PC via a 115kbps serial connection.
In the python source you may customize your equipment addresses, serial interface and commands to send for analysis. To use the program, just run on a terminal:
python fsas.py
it will then print instructions on how to use: direct capture from instrument or existing tracedump (re-)processing.
The second tool I am currently developing (so it certainly has some small bug...) is gpib.py
. With this you can create a different text file for each analysis operating over all your GPIB connected instruments.
At the moment I implemented a very basic (but intuitive) scripting language that can help you modularize sequences of commands, create local variables, calling metafunctions defined in the Python source code for dealing with complex IN/OUT like the trace dump of the basic tool fsas.py
. Be careful that GOTO
commands only go forward for now, so no loops yet ;)
I included an example script called commands.txt
that should be processed in this way:
python gpib.py -p commands.txt
If you have more than one trace dump, I save them all to a multi page PDF file instead of filling your directory with JPGs. The PDF file will overwrite the output.pdf
every time: be advised!
Instead of having to modify the python source code for every analysis you plan, I implemented a very basic (pun intended :) ) command interpreter to control any GPIB enabled instrument you have connected.
At the moment you can do the following operations:
- write comments, disregarded by the interpreter;
- define new user variables: they may be integers, floats or strings (the variables CANNOT be used inside GPIB commands yet!) but they can be given to user defined functions in the Python code. Variable values still cannot be dynamically modified like A=A+1, future development...;
- use GOTO commands to skip certain parts of the analysis;
- call user definable complex functions. At the moment I just defined three:
- delay,
- trace_dump (from my FSAS)
- set_listener_talker
- the output of the trace dumps will go to a multipage PDF file along with their TITLE;
- the raw pickle output gets overwritten at the moment and only the last one is kept: be careful :)
Next I'll try to implement LOOPS in order to be able to perform optimization analyses actively varying some parameters such as tracking generator frequency and amplitude or sending GPIB commads to user ports etc.
Please study the commands.txt
to understand the basic scripting rules.
THE CODE IS RELEASED UNDER THE GPL V3.0. Donations via PayPal TO cogoni AT gmail DOT com are welcome and will contribute to make me work on the project! Thanks.
Have fun!
marco / IS0KYB