Author Topic: Python scripts to control instruments using LXI SCPI - no drivers required  (Read 10560 times)

0 Members and 1 Guest are viewing this topic.

Offline RoGeorgeTopic starter

  • Super Contributor
  • ***
  • Posts: 6185
  • Country: ro
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.



The 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-line

This 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. The RFC 854 specifications 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.
« Last Edit: September 09, 2023, 02:55:01 pm by RoGeorge »
 
The following users thanked this post: bingo600

Offline bson

  • Supporter
  • ****
  • Posts: 2269
  • Country: us
Re: Python scripts to control instruments using LXI SCPI - no drivers required
« Reply #1 on: September 30, 2016, 08:20:00 pm »
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.
 

Offline RoGeorgeTopic starter

  • Super Contributor
  • ***
  • Posts: 6185
  • Country: ro
Re: Python scripts to control instruments using LXI SCPI - no drivers required
« Reply #2 on: September 30, 2016, 10:51:38 pm »
Glad to here about alternatives.  :D

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.

Can python-vxi11 work on a clean machine, without any VISA?
« Last Edit: September 30, 2016, 10:54:01 pm by RoGeorge »
 

Offline RoGeorgeTopic starter

  • Super Contributor
  • ***
  • Posts: 6185
  • Country: ro
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.

The value "9.9E37" is the SCPI value corresponding to the oscilloscope screen displaying "Avg=*****"

This is how the produced CSV file looks like:
Code: [Select]
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.9E37
2017-03-24,14:35:19,1.112045e-01,9.9E37,9.9E37,9.9E37
2017-03-24,14:35:29,5.585327e-02,9.9E37,9.9E37,9.9E37
2017-03-24,14:35:39,9.314423e-02,9.9E37,9.9E37,9.9E37
2017-03-24,14:35:49,1.023407e-01,9.9E37,9.9E37,9.9E37
2017-03-24,14:35:59,1.030106e-01,9.9E37,9.9E37,9.9E37

And its CMD capture:

Offline Neuromodulator

  • Regular Contributor
  • *
  • Posts: 67
  • Country: cl
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.
 

Offline bson

  • Supporter
  • ****
  • Posts: 2269
  • Country: us
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.
 

Offline RoGeorgeTopic starter

  • Super Contributor
  • ***
  • Posts: 6185
  • Country: ro
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.

From 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.
:)
« Last Edit: March 24, 2017, 07:34:07 pm by RoGeorge »
 
The following users thanked this post: Chalky

Offline Chalky

  • Regular Contributor
  • *
  • Posts: 94
  • Country: nz
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.
 

Offline RoGeorgeTopic starter

  • Super Contributor
  • ***
  • Posts: 6185
  • Country: ro
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.
 ;D

Online moffy

  • Super Contributor
  • ***
  • Posts: 1719
  • Country: au
Re: Python scripts to control instruments using LXI SCPI - no drivers required
« Reply #9 on: September 09, 2023, 10:09:57 am »
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. :)
 
The following users thanked this post: RoGeorge

Offline coromonadalix

  • Super Contributor
  • ***
  • Posts: 5876
  • Country: ca
 

Offline RoGeorgeTopic starter

  • Super Contributor
  • ***
  • Posts: 6185
  • Country: ro
Re: Python scripts to control instruments using LXI SCPI - no drivers required
« Reply #11 on: September 09, 2023, 12:12:44 pm »
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. :)

Glad you found that useful, thank you and have fun experimenting!  :-+

Online moffy

  • Super Contributor
  • ***
  • Posts: 1719
  • Country: au
Re: Python scripts to control instruments using LXI SCPI - no drivers required
« Reply #12 on: September 09, 2023, 01:24:34 pm »
you should check   lxi tools thread here

https://www.eevblog.com/forum/testgear/open-source-lxi-tools-v2-0-released/

Thanks for the tip. I downloaded Ubuntu 22.04 into VirtualBox, used 'snap' to install lxi-tools and it all seems to run. :)
 

Offline RoGeorgeTopic starter

  • Super Contributor
  • ***
  • Posts: 6185
  • Country: ro
Re: Python scripts to control instruments using LXI SCPI - no drivers required
« Reply #13 on: September 09, 2023, 02:16:01 pm »
If you have Ubuntu, then there's nothing to install, open a terminal (CTRL+ALT+t) and try this trick (not mine):
Code: [Select]
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.  ;D

For Rigol oscilloscopes, you may want to consider the DSremote, too, also not mine.

Online moffy

  • Super Contributor
  • ***
  • Posts: 1719
  • Country: au
Re: Python scripts to control instruments using LXI SCPI - no drivers required
« Reply #14 on: September 09, 2023, 02:35:48 pm »
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.
 

Offline RoGeorgeTopic starter

  • Super Contributor
  • ***
  • Posts: 6185
  • Country: ro
Re: Python scripts to control instruments using LXI SCPI - no drivers required
« Reply #15 on: September 09, 2023, 02:54:15 pm »
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.
« Last Edit: September 09, 2023, 03:02:27 pm by RoGeorge »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf