Author Topic: Scripting setup for Rigol devices  (Read 12480 times)

0 Members and 1 Guest are viewing this topic.

Offline edgelogTopic starter

  • Regular Contributor
  • *
  • Posts: 70
  • Country: se
Scripting setup for Rigol devices
« on: June 01, 2017, 07:39:59 pm »
I'm trying to find a working combination of software, so that I can script commands to Rigol devices. I have three: DP832, DG1022Z, and an MSO1104Z. All on latest firmware. All just a month old or so. All on the local LAN.

I've tried the examples provided by Rigol, but they're old, mostly VB6, or Visual C++ 2005 or so. Their example code makes no sense either. Any comments in the code seem to be in scrambled chinese, not making things any easier.

So I tried National Instruments, but the price scared me off before I even started.

So then I downloaded the Keysight IO library, but the "command expert" can't load the rgdp800 driver (I'm guessing 32 vs 64 bit problem).

Before getting completely lost going down one or more rabbit holes, I'd like to know if anyone here has a working setup, allowing scripting in any language (yes, I'd take anything by now) for these instruments, over LAN, on Win 10. (Now, if anyone has MacOS working for this, I'd be euphoric, but that's too much to ask, I'm sure.)

It doesn't look like Rigol keeps their drivers updated, or in an easily locatable place, either. Or?
 

Offline thm_w

  • Super Contributor
  • ***
  • Posts: 6272
  • Country: ca
  • Non-expert
Profile -> Modify profile -> Look and Layout ->  Don't show users' signatures
 

Online H.O

  • Frequent Contributor
  • **
  • Posts: 807
  • Country: se
Re: Scripting setup for Rigol devices
« Reply #2 on: June 01, 2017, 08:21:37 pm »
Have you looked at Python with PyVISA?
That's what I've settled on, running on W10. Got it installed and managed to connect with my instruments (also Rigol) but I have not done anything more than that really.
 

Offline TK

  • Super Contributor
  • ***
  • Posts: 1722
  • Country: us
  • I am a Systems Analyst who plays with Electronics
Re: Scripting setup for Rigol devices
« Reply #3 on: June 01, 2017, 10:00:30 pm »
If it is for non-commercial use, you can buy the National Instruments Labview Home Edition for $49.99

http://store.digilentinc.com/labview-home-bundle/
https://www.labviewmakerhub.com/
 

Offline LaurentR

  • Frequent Contributor
  • **
  • Posts: 536
  • Country: us
Re: Scripting setup for Rigol devices
« Reply #4 on: June 02, 2017, 02:18:43 am »
First, in IO Libraries, you do not want to run Command Expert as there is no command list for the Rigol stuff.

Instead, in the Keysight Connection Expert window, pick your instrument and click on "Interactive IO".
There, you can type any SCPI command from the Rigol manual.
For instance, type "*IDN?" then click "Send & Read".

Now, to talk to your instrument, you have a few options:
A) Use a high-level IVI driver (see Rigol website). This also requires running a Visa stack (Keysight IO Libraries or NI Visa). This wraps the SCPI commands in a higher-level API accessible through higher level languages. Typically usable from LabView, Matlab and the various C languages with the proper libraries. The APIs are standard across brands (i.e. a DMM is a DMM), so it's easier to port code between instruments. But it leaves out a lot of your instruments specifics.
If this is for limited scripting use, I _do not_ recommend you try to go this route.

B) Script the instruments directly using their instrument-specific SCPI command (that's what you're doing at the top of this message when sending "*IDN?"). The command sets are usually well documented in the user manual or a SCPI-specific manual.
I strongly recommend you go this route.

To send SCPI commands to the instrument, you have 2 options:

B1) Use a Visa stack (like Keysight IO Libraries or NI Visa, which is installed by default when installing the various Ultra* tools from Rigol). These do not require instrument specific drivers if you are going to use SCPI commands.
From there, you have to use a language that has a Visa library to talk to the Visa stack. This includes:
* PyVisa (Python - already mentioned above)
* Matlab through Visa (need the Instrument Control toolbox). Note: Matlab Personal + IC toolbox is $149+$45.
* Visa library in Visual Studio
You will need to find your instrument in the Visa stack so that you can open it from your language of choice. You can assign aliases to instruments in the Visa stack to make finding the instrument easier.

B2) Connect to the instrument directly using RS232 (if you have a RS232 port) or Ethernet (if you have an Ethernet port). In this case, you don't need a Visa stack. You just need to find in your language of choice how to open a serial port (RS232) or a TCP socket (Ethernet). You can talk to your instrument using a terminal emulator like Putty and configuring it for serial or telnet.
There is no such method for connecting through USB. A USB instrument can only be accessed through a Visa stack.
« Last Edit: June 02, 2017, 02:24:01 am by LaurentR »
 

Offline edgelogTopic starter

  • Regular Contributor
  • *
  • Posts: 70
  • Country: se
Re: Scripting setup for Rigol devices
« Reply #5 on: June 02, 2017, 06:48:06 am »
B2) Connect to the instrument directly using RS232 (if you have a RS232 port) or Ethernet (if you have an Ethernet port). In this case, you don't need a Visa stack. You just need to find in your language of choice how to open a serial port (RS232) or a TCP socket (Ethernet). You can talk to your instrument using a terminal emulator like Putty and configuring it for serial or telnet.
There is no such method for connecting through USB. A USB instrument can only be accessed through a Visa stack.

That sounds most palatable. I could connect fine through telnet on port 5555, so I can do the same from code, avoiding all the dependencies on IVI drivers and the Visa stack. Which brings me back to familiar territory, doing it all in Swift on XCode with standard tools. I think this will be the route I'll take.

Thanks everyone for the tips. Now I have several backup plans.
 

Offline Fungus

  • Super Contributor
  • ***
  • Posts: 16560
  • Country: 00
Re: Scripting setup for Rigol devices
« Reply #6 on: June 02, 2017, 06:53:21 am »
I'm trying to find a working combination of software, so that I can script commands to Rigol devices.

Telnet port 5555?
 

Offline edgelogTopic starter

  • Regular Contributor
  • *
  • Posts: 70
  • Country: se
Re: Scripting setup for Rigol devices
« Reply #7 on: June 02, 2017, 07:05:08 am »
Telnet port 5555?

Yes, as I said above, I realized that after going the complicated route. That seems to be the simplest by far. Though not through telnet but through code.
 

Offline Fungus

  • Super Contributor
  • ***
  • Posts: 16560
  • Country: 00
Re: Scripting setup for Rigol devices
« Reply #8 on: June 02, 2017, 07:08:02 am »
Telnet port 5555?

Yes, as I said above, I realized that after going the complicated route. That seems to be the simplest by far. Though not through telnet but through code.

Yes, you use telnet as the "driver". It's much easier/cleaner than all that other crap.

(in reality it's just a TCP connection, you can use 'telnet' as a command line for playing around with it)

The programming guide is here:

http://int.rigol.com/File/TechDoc/20151218/MSO1000Z&DS1000Z_ProgrammingGuide_EN.pdf
« Last Edit: June 02, 2017, 07:09:58 am by Fungus »
 

Offline Karel

  • Super Contributor
  • ***
  • Posts: 2214
  • Country: 00
Re: Scripting setup for Rigol devices
« Reply #9 on: June 02, 2017, 07:10:54 am »
A USB instrument can only be accessed through a Visa stack.

That's not true. The visa stack uses the usbtmc protocol for usb connection.
When using the usbtmc protocol (without the visa stack), it's basically the same as direct tcp/ip.
For example, DSRemote uses usbtmc without visa stack.

If you want to learn more about it, read this: http://literature.cdn.keysight.com/litweb/pdf/5989-6718EN.pdf


 

Offline edgelogTopic starter

  • Regular Contributor
  • *
  • Posts: 70
  • Country: se
Re: Scripting setup for Rigol devices
« Reply #10 on: June 02, 2017, 07:11:21 am »
Yes, you use telnet as the "driver". It's much easier/cleaner than all that other crap.

The programming guide is here:

http://int.rigol.com/File/TechDoc/20151218/MSO1000Z&DS1000Z_ProgrammingGuide_EN.pdf

I have the programming guide, np.

Well, I'm not going to use telnet (the command line application), but the networking library that is standard in XCode/Swift. Same thing, but easier (for me). So my "scripting" will simply be Swift code.
 

Offline LaurentR

  • Frequent Contributor
  • **
  • Posts: 536
  • Country: us
Re: Scripting setup for Rigol devices
« Reply #11 on: June 02, 2017, 07:14:25 am »
A USB instrument can only be accessed through a Visa stack.

That's not true. The visa stack uses the usbtmc protocol for usb connection.
When using the usbtmc protocol (without the visa stack), it's basically the same as direct tcp/ip.
For example, DSRemote uses usbtmc without visa stack.

If you want to learn more about it, read this: http://literature.cdn.keysight.com/litweb/pdf/5989-6718EN.pdf

Fair. You don't need the full Visa stack, but you need a USBTMC driver.
 

Offline Karel

  • Super Contributor
  • ***
  • Posts: 2214
  • Country: 00
Re: Scripting setup for Rigol devices
« Reply #12 on: June 02, 2017, 07:18:29 am »
A USB instrument can only be accessed through a Visa stack.

That's not true. The visa stack uses the usbtmc protocol for usb connection.
When using the usbtmc protocol (without the visa stack), it's basically the same as direct tcp/ip.
For example, DSRemote uses usbtmc without visa stack.

If you want to learn more about it, read this: http://literature.cdn.keysight.com/litweb/pdf/5989-6718EN.pdf

Fair. You don't need the full Visa stack, but you need a USBTMC driver.

The most used operating system in the world has it already builtin.
It's like saying that you need a tcp/ip driver if you want to use LAN connection...
 

Offline LaurentR

  • Frequent Contributor
  • **
  • Posts: 536
  • Country: us
Re: Scripting setup for Rigol devices
« Reply #13 on: June 02, 2017, 07:24:29 am »
A USB instrument can only be accessed through a Visa stack.

That's not true. The visa stack uses the usbtmc protocol for usb connection.
When using the usbtmc protocol (without the visa stack), it's basically the same as direct tcp/ip.
For example, DSRemote uses usbtmc without visa stack.

If you want to learn more about it, read this: http://literature.cdn.keysight.com/litweb/pdf/5989-6718EN.pdf

Fair. You don't need the full Visa stack, but you need a USBTMC driver.

The most used operating system in the world has it already builtin.
It's like saying that you need a tcp/ip driver if you want to use LAN connection...

I was going to say that for Windows, I don't think there is a USBTMC driver outside of the commercial Visa stacks  ;D
No further comment on the "most used OS in the world".
 

Offline Karel

  • Super Contributor
  • ***
  • Posts: 2214
  • Country: 00
Re: Scripting setup for Rigol devices
« Reply #14 on: June 02, 2017, 07:54:47 am »
Here you can read how to control your scope via lan from within a script without the need to install any drivers,
using direct tcp/ip: http://xmodulo.com/tcp-udp-socket-bash-shell.html

I just tried and it works fine. Dont forget to put a newline ('\n') at the end of a command.
Works probably as well on MacOS.

Code: [Select]
MESSAGE="*IDN?\n"
exec 5<>/dev/tcp/192.168.1.6/5555
printf $MESSAGE >&5
MESSAGE=$(dd bs=$NUM_BYTES count=$COUNT <&5 2> /dev/null)
echo $MESSAGE
exec 5<&-
exec 5>&-
 

Offline edgelogTopic starter

  • Regular Contributor
  • *
  • Posts: 70
  • Country: se
Re: Scripting setup for Rigol devices
« Reply #15 on: June 02, 2017, 07:57:29 am »
Here you can read how to control your scope via lan from within a script without the need to install any drivers,
using direct tcp/ip: http://xmodulo.com/tcp-udp-socket-bash-shell.html

Hm... interesting. Could be handy for short scripts, but probably unwieldy for anything more complicated.
 

Offline Karel

  • Super Contributor
  • ***
  • Posts: 2214
  • Country: 00
Re: Scripting setup for Rigol devices
« Reply #16 on: June 02, 2017, 08:38:43 am »
No further comment on the "most used OS in the world".
thats android.

No, it's Linux.
 

Online H.O

  • Frequent Contributor
  • **
  • Posts: 807
  • Country: se
Re: Scripting setup for Rigol devices
« Reply #17 on: June 02, 2017, 10:04:16 am »
That's Android, that's Linux, not if you count this, yes, if you count that. For crying out loud, who gives a shit!

The only important thing here is that the solution works on edgelog's OS of choice - whatever that is.
 

Offline edgelogTopic starter

  • Regular Contributor
  • *
  • Posts: 70
  • Country: se
Re: Scripting setup for Rigol devices
« Reply #18 on: June 02, 2017, 10:19:01 am »
The only important thing here is that the solution works on edgelog's OS of choice - whatever that is.

MacOS, in my case. But, if need be, I can live with one of "the others".
 

Online H.O

  • Frequent Contributor
  • **
  • Posts: 807
  • Country: se
Re: Scripting setup for Rigol devices
« Reply #19 on: June 02, 2017, 10:56:45 am »
Yeah, I'm sorry, you've told us. I didn't mean to imply you hadn't, my last sentence should probably have read whatever it is.
All I meant to say is that it's your choice. Weather or not your OS of choice is number 1,2 or 10 on the "most used" list is completely irrelevant. And arguing over which one that is even more irrelevant - and so is this post, for which I apologize.
 

Offline Dwaine

  • Frequent Contributor
  • **
  • Posts: 299
  • Country: ca
Re: Scripting setup for Rigol devices
« Reply #20 on: June 02, 2017, 11:56:24 am »
Python works well since its runs on multiple platforms.  I use the raspberry Pi image with the python scripts.  It has a web server so you can access the graphs from any device. 

Here is my Rigol DM3068 setup.

 

Offline edgelogTopic starter

  • Regular Contributor
  • *
  • Posts: 70
  • Country: se
Re: Scripting setup for Rigol devices
« Reply #21 on: June 02, 2017, 01:04:41 pm »
Python works well since its runs on multiple platforms.  I use the raspberry Pi image with the python scripts.  It has a web server so you can access the graphs from any device. 

Here is my Rigol DM3068 setup.

Nice. I'll try that if my Swift attempt becomes too onerous.
 

Offline Dwaine

  • Frequent Contributor
  • **
  • Posts: 299
  • Country: ca
Re: Scripting setup for Rigol devices
« Reply #22 on: June 02, 2017, 03:58:51 pm »
Here is a reference python script.  Works great. 

# Rigol DM3068 Multi Meter Python Measurement Script

# Import the libraries for the Rigol DM3068 Multi Meter.
import usbtmc
import vxi11
import serial
import Gpib
import os.path
import sys
import time
from BME280 import *

LogDir = '/pub/logs/'
LogFile= LogDir + 'DM3068_Log.csv'
Reflevel = 16.800000000

# Sensors
BME_Enabled = 0
if (BME_Enabled == 1):
  BMEsensor = BME280(address=0x76)

# Rigol DM3068 Lan Connection
inst = vxi11.Instrument("192.168.1.201")
inst.clear()

# Rigol DM3068 USB Connection
#inst = usbtmc.Instrument("USB::0x1ab1::0x0c94::INSTR")
#inst.clear()

# Rigol DM3068 GPIB Connection
# inst = Gpib.Gpib(0,7)
# inst.clear()


# Rigol DM3068 Serial Port Connection
# ser = serial.Serial(
#      port='/dev/serial1',
#      baudrate = 115200,
#      parity=serial.PARITY_NONE,
#      stopbits=serial.STOPBITS_ONE,
#      bytesize=serial.EIGHTBITS,
#      timeout=1
#)
#
# ser.write("*IDN?\n")
# time.sleep(2)
# bytesToRead = ser.inWaiting()
# print ser.read(bytesToRead)
#
# ser.close()

# Setup Rigol DM3068 Meter for all types of measurements
inst.write("*CLS")
inst.write("SYSTem:DISPlay:BRIGht 32")
inst.write("[SENSe:]ZERO:AUTO ON")
inst.write('DISPlay:TEXT "Logging On!"')
inst.write("SYSTem:BEEPer:STATe ON")
inst.write("SYSTem:BEEPer")
inst.write("SYSTem:BEEPer:STATe OFF")

# DC Voltage Measurement
inst.write(":FUNCtion:VOLTage:DC")
inst.write("CONFigure:VOLTage:DC 20 V")
measurementvalue = ":MEASure:VOLTage:DC?"

# AC Voltage Measurement
# inst.write(":FUNCtion:VOLTage:AC")
# inst.write("CONFigure:VOLTage:AC 20 V")
# measurementvalue = ":MEASure:VOLTage:AC?"

# 2 Wire Ohms Resistence Measurement
# inst.write(":FUNCtion:RESistance")
# inst.write("CONFigure:RESistance 20000")
# measurementvalue = ":MEASure:RESistance?"

# 4 Wire Ohms Resistence Measurement
# inst.write(":FUNCtion:FRESistance")
# inst.write("CONFigure:FRESistance 20000")
# measurementvalue = ":MEASure:FRESistance?"

# Check file presence, write header
if (os.path.isfile(LogFile) == False):
  with open(LogFile, 'a') as MeterLog:
    if (BME_Enabled == 1):
      MeterLog.write("TimeStamp,Voltage,ppm,Temperature,Pressure,Humidity\r\n")
    else:
      MeterLog.write("TimeStamp,Voltage,ppm\r\n")
    MeterLog.close()

while True:
    with open(LogFile, 'a') as MeterLog:
      data = inst.ask(measurementvalue)
      ppm = ((float(data) / Reflevel)-1)*1E6
      if (BME_Enabled == 1):
         # Reads sensor data
         Temperature = BMEsensor.read_temperature()
         Pressure = BMEsensor.read_pressure()
         Humidity = BMEsensor.read_humidity()
         print time.strftime("%d/%m/%Y\t%H:%M:%S") + ("\t%.8f\t%.1f ppm\t%4.2f\t%6.0f\t%4.1f\r\n" % (float(data),float(ppm),float(Temperature),float(Pressure),float(Humidity)) )
         MeterLog.write (time.strftime("%d/%m/%Y-%H:%M:%S,") + ("%.8f,%.1f,%4.2f,%6.0f,%4.1f\r\n" % (float(data),float(ppm),float(Temperature),float(Pressure),float(Humidity))))
      else:
        print time.strftime("%d/%m/%Y\t%H:%M:%S") + ("\t%.8f\t%.1f ppm" % (float(data),float(ppm) ) )
        MeterLog.write (time.strftime("%d/%m/%Y-%H:%M:%S,") + ("%.8f,%.1f\r\n" % (float(data),float(ppm) ) ))
MeterLog.close()
 

Offline edgelogTopic starter

  • Regular Contributor
  • *
  • Posts: 70
  • Country: se
Re: Scripting setup for Rigol devices
« Reply #23 on: June 02, 2017, 04:10:05 pm »
Here is a reference python script.  Works great. 

Great stuff! Thx!
 

Offline Karel

  • Super Contributor
  • ***
  • Posts: 2214
  • Country: 00
Re: Scripting setup for Rigol devices
« Reply #24 on: June 02, 2017, 06:57:10 pm »
That's Android, that's Linux, not if you count this, yes, if you count that.

Without Linux, no Android.
Without Android, Linux doesn't care at all.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf