Python scripts to control instruments using LXI SCPI - no drivers required - Page 1
Forum section: electronics / testgear

author: RoGeorge
author_rank: Super Contributor
timestamp: September 30, 2016, 01:40:43 pm
content: I have a few scripts that can control Rigol instruments connected to a LAN.They were useful to me many times, maybe others want to use them too.They are free, open source, works from the command line for both Windows and Linux, and does not need to install any drivers.DS1054Z_screen_capture- capture and save the traces data points as CSV, or capture a scope printscreen as PNG or BMPhttps://github.com/RoGeorge/DS1054Z_screen_capturehttps://hackaday.io/project/5807-driverless-rigol-ds1054z-screen-capture-over-lanDS1054Z long term logger- a script that logs Vavgfor all the 4 channels of a Rigol DS1000Z, timestamp each record, then save as a new line in a CSV file on the PChttps://www.eevblog.com/forum/testgear/rigol-ds1054z-saving-logging-values-over-long-duration/msg1077151/#msg1077151https://github.com/RoGeorge/DS1054Z_data_loggerDS1054Z encabulator- to automatically keep the trigger point at the left instead of the screen, instead of letting it in the middle, works even when the timebase changeshttps://www.eevblog.com/forum/projects/scpi-encabulator-to-keep-the-trigger-time-shifted-inside-display-rigol-ds1054/DP832_charger_logger- is displaying and logging the Voltage, Current and Power of all channels, while saving the data in the PC as CSV. The CSV file can be copied and post-processed while the logging is running, no need to wait until the logging has finished.https://github.com/RoGeorge/DP832_charger_loggerDP832 Curve Traceruses Python and Jupyter Notebooks to make automated plots of U/I characteristics, i.e. a power MOSFEThttps://www.eevblog.com/forum/testgear/rigol-dp832-power-supply-as-automated-curve-tracer/SCPI_solder_station- an automated PID loop to control a soldering iron powered by a Rigol DP832 power source. It was done mostly to evaluate different soldering irons and different soldering tips. It can be used for occasional soldering too. No soldering station is required. The temperature sensor is read by the Rigol DS1054Z oscilloscope.https://github.com/RoGeorge/SCPI_solder_stationhttps://rogeorge.wordpress.com/2016/09/23/zero-parts-thermostated-soldering-station/https://hackaday.io/project/14969-zero-parts-thermostated-soldering-stationThe story was that after I bought my first Rigol, a DS1054Z oscilloscope, I tried to control it remotely, from the PC. I ended up installing drivers from Rigol and National Instruments, drivers that came together with a few GB of bloated software, which I didn't like it at all.Later, I found out that all instruments that have LXI can talk over the LAN using plain text SCPI commands. No drivers are required for LXI. You can simply Telnet or Net Cat the SCPI command using the instrument IP and port 5555 or 5566.https://hackaday.io/project/6857-master-your-rigol-from-command-lineThis is great for most of the SCPI commands, but not good for ones that returns binary data, like the BMP file returned after an oscilloscope screen capture. So I wrote a small Python script to capture the screen from the oscilloscope. In this script I tried to use the Telnet libraries already available in Python.The problem using Telnet is that it was designed for text messages. TheRFC 854specifications for Telnet protocol, define the character NULL (0x00) as "No Operation", so when any 0x00 byte was encountered in the BMP file sent by the scope, the Python Telnet library silently discard it, messing up the BMP file format. So I hacked the Telnet library to let 0x00 unaffected, and after that it was possible to receive and decode the BMP screen captured from the scope.For other SCPI commands that returns only text messages or text values, the standard Telnet or Net Cat can be used.

author: bson
author_rank: Unknown
timestamp: September 30, 2016, 08:20:00 pm
content: I'd recommend using python-vxi11 for actual scripting. The LXI branding just means the instrument implements VXI-11, which is a way of tunneling GPIB over SunRPC. This has some benefits in that GPIB implements various signaling that can't be communicated using plain old text, and works transparently with GPIB-to-Ethernet bridges like the ICS 8065 (which is what I use) for older instruments that have GPIB but not VXI-11, or any Ethernet at all for that matter. It also makes it easy to share instruments, so I can sit and develop a test on the couch using my MacBook Pro, then actually run it on the Linux machine I use for data logging remotely over ssh in a screen session.

author: RoGeorge
author_rank: Super Contributor
timestamp: September 30, 2016, 10:51:38 pm
content: Glad to here about alternatives.I give it a try, but python-vxi11 didn't worked for me. At a quick glance into the code, it seems like python-vxi11 is dependent of the VISA drivers, e.g. NI-VISA, and can not work without VISA installed. Thought, I am not sure about that.Canpython-vxi11work on a clean machine, without any VISA?

author: RoGeorge
author_rank: Super Contributor
timestamp: March 24, 2017, 12:45:14 pm
content: Recent changes/upgrades of the forum's database made me wonder if the old posts are still fine, so I stumble into this one, which was intended to be a collection of my Rigol scrips. Python-VXI didn't worked for me.Another script that serves me well (this one is Windows only, but it can be easily ported on Linux, too):DS1054Z_data_logger- is displaying and logging the Vavg of all 4 channels of a DS1054Z oscilloscope while saving the data in the PC as a CSV file. The CSV file can be opened or copied and post-processed while the logging is running, no need to wait until the logging has been finished.https://github.com/RoGeorge/DS1054Z_data_loggerThe value "9.9E37" is the SCPI value corresponding to the oscilloscope screen displaying "Avg=*****"This is how the produced CSV file looks like:Code:YYYY-MM-DD,HH:MM:SS,CH1(Vavg),CH2(Vavg),CH3(Vavg),CH4(Vavg)2017-03-24,14:35:09,1.133774e-01,9.9E37,9.9E37,9.9E372017-03-24,14:35:19,1.112045e-01,9.9E37,9.9E37,9.9E372017-03-24,14:35:29,5.585327e-02,9.9E37,9.9E37,9.9E372017-03-24,14:35:39,9.314423e-02,9.9E37,9.9E37,9.9E372017-03-24,14:35:49,1.023407e-01,9.9E37,9.9E37,9.9E372017-03-24,14:35:59,1.030106e-01,9.9E37,9.9E37,9.9E37And its CMD capture:

author: Neuromodulator
author_rank: Regular Contributor
timestamp: March 24, 2017, 03:45:15 pm
content: I played a bit with LXI some time ago, but used python sockets instead of Telnet. I found that remote control of the scope is very unreliable, even with their own drivers and software. For instance I found that if I sent two commands too quick, one would not be processed, even after waiting for the completion of the first command (If I remember correctly). There were also some issues when using too big memory buffers (for faster memory reading). You still can automate stuff, but the system isn't as robust as I was hoping.

author: bson
author_rank: Unknown
timestamp: March 24, 2017, 06:32:27 pm
content: Python-vxi11 doesn't need or even use VISA drivers, it talks SunRPC directly to the VXI-11 network controller. I use it on OSX and Linux and don't have that broken VISA driver garbage and discovery services installed anywhere. Instead, all my physical GPIB buses terminate at a pair of ICS8065 network controllers that talk VXI-11 only. This excepts the instruments I have that can talk VXI-11 directly. I mostly sit and work out the scripting code on a MacBook Pro on the couch and when it seems to work I move it over to a small Intel NUC box on the wall behind my bench... VXI-11 is absolutely rock solid, in fact I can go move the entire network, power cycle switches, reconfigure the VLAN, and whatnot and it'll just keep going. I can even power cycle the 8065 in use if I feel like it. This is in total contrast to the patently brittle, ghetto, over-engineered VISA discovery services and drivers where if you so much as look at it wrong you have to reboot to get it working again. For a while.

author: RoGeorge
author_rank: Super Contributor
timestamp: March 24, 2017, 07:31:28 pm
content: Quote from: Neuromodulator on March 24, 2017, 03:45:15 pmFrom my tests, either Telnet or a simple TCP socket works good enough (lately I was dropping the Telnet and used a TCP socket, too), and any instability seems to be related to the LXI implementation or the firmware version. If I check for errors and for command completeness, then it is stable enough for use in a supervised lab.Still, as you noticed too, Rigol LXI is far from perfect. I will not use any Rigol LXI instruments to control a nuclear power plant.

author: Chalky
author_rank: Regular Contributor
timestamp: July 13, 2017, 02:30:20 am
content: How are you checking for errors and command completeness?Yeah, all you need to do is fart in the wrong direction and DS2000's LXI hangs.

author: RoGeorge
author_rank: Super Contributor
timestamp: July 13, 2017, 08:14:46 am
content: In the first versions I was simply waiting about a second between commands. Of course, this was very slow.Then, I was using *OPC?. I guess my scripts published on github are still using OPC query. For big data transfers, OPC doesn't help, you must check that all the expected data has arrived before sending another command.Later, I stopped using Telnet, and open a TCP socket instead. Also I start looking for errors too, not only for the completeness of SCPI command, but I bumped into some firmware bugs that make my DS1054Z to freeze any LXI communication until the next power cycle, so these changes are not published yet on my github scripts. Since the actual scripts cover my needs, I didn't spent more time for improvements.So far, yes, it works, but I won't use Rigol for life support equipment any time soon.

author: moffy
author_rank: Super Contributor
timestamp: September 09, 2023, 10:09:57 am
content: I know it is an old post but I just want to thank RoGeorge for the info. Looking to upgrade to a DHO914 when they are in stock so I thought I would first experiment with my MSO1074Z logging to a PC, it is then I ran across RoGeorge's posts.

author: coromonadalix
author_rank: Super Contributor
timestamp: September 09, 2023, 12:02:53 pm
content: you should check lxi tools thread herehttps://www.eevblog.com/forum/testgear/open-source-lxi-tools-v2-0-released/

author: RoGeorge
author_rank: Super Contributor
timestamp: September 09, 2023, 12:12:44 pm
content: Quote from: moffy on September 09, 2023, 10:09:57 amGlad you found that useful, thank you and have fun experimenting!

author: moffy
author_rank: Super Contributor
timestamp: September 09, 2023, 01:24:34 pm
content: Quote from: coromonadalix on September 09, 2023, 12:02:53 pmThanks for the tip. I downloaded Ubuntu 22.04 into VirtualBox, used 'snap' to install lxi-tools and it all seems to run.

author: RoGeorge
author_rank: Super Contributor
timestamp: September 09, 2023, 02:16:01 pm
content: If you have Ubuntu, then there's nothing to install, open a terminal (CTRL+ALT+t) and try this trick (not mine):Code:echo ":DISPLAY:DATA? ON,OFF,PNG" | nc -w1 192.168.32.208 5555 | dd bs=1 skip=11 of=image.pngIf you use the address of your oscilloscope (connected in the same LAN with the PC), then that command line will save the oscilloscope's screen as 'image.png', nothing to install of course.For Rigol oscilloscopes, you may want to consider theDSremote, too, also not mine.

author: moffy
author_rank: Super Contributor
timestamp: September 09, 2023, 02:35:48 pm
content: I must say VirtualBox and VMs have improved since I last used one. I was able to download Qt plus the compiler and the DSRemote source and compile the whole thing. It didn't feel like a VM but a real linux machine. So much easier than previously.

author: RoGeorge
author_rank: Super Contributor
timestamp: September 09, 2023, 02:54:15 pm
content: VirtualBox works great on either Solaris, Linux, Mac or Windows machines.It even works on FreeBSD (except for no USB2.0 or 3.0 support, only USB1.1 on FreeBSD).Updated the OP with a few more links to SCPI tools wrote since then.