Scripting setup for Rigol devices - Page 1
Forum section: electronics / testgear

author: edgelog
author_rank: Regular Contributor
timestamp: June 01, 2017, 07:39:59 pm
content: 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?

author: thm_w
author_rank: Super Contributor
timestamp: June 01, 2017, 08:17:09 pm
content: There are some people here that have worked in matlab (probably too expensive) or python:https://www.eevblog.com/forum/testgear/rigol-dp832-firmware-updates-and-bug-list/msg587350/#msg587350https://www.eevblog.com/forum/testgear/rigol-dp832-firmware-updates-and-bug-list/msg650855/#msg650855https://www.eevblog.com/forum/testgear/calibrating-a-dp832-with-python-ivi-(also-a-keithley-2000-driver-for-python-ivi)/

author: H.O
author_rank: Frequent Contributor
timestamp: June 01, 2017, 08:21:37 pm
content: 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.

author: TK
author_rank: Super Contributor
timestamp: June 01, 2017, 10:00:30 pm
content: If it is for non-commercial use, you can buy the National Instruments Labview Home Edition for $49.99http://store.digilentinc.com/labview-home-bundle/https://www.labviewmakerhub.com/

author: LaurentR
author_rank: Frequent Contributor
timestamp: June 02, 2017, 02:18:43 am
content: 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 StudioYou 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.

author: edgelog
author_rank: Regular Contributor
timestamp: June 02, 2017, 06:48:06 am
content: Quote from: LaurentR on June 02, 2017, 02:18:43 amThat 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.

author: Fungus
author_rank: Super Contributor
timestamp: June 02, 2017, 06:53:21 am
content: Quote from: edgelog on June 01, 2017, 07:39:59 pmTelnet port 5555?

author: edgelog
author_rank: Regular Contributor
timestamp: June 02, 2017, 07:05:08 am
content: Quote from: Fungus on June 02, 2017, 06:53:21 amYes, 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.

author: Fungus
author_rank: Super Contributor
timestamp: June 02, 2017, 07:08:02 am
content: Quote from: edgelog on June 02, 2017, 07:05:08 amYes, 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

author: Karel
author_rank: Super Contributor
timestamp: June 02, 2017, 07:10:54 am
content: Quote from: LaurentR on June 02, 2017, 02:18:43 amThat'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

author: edgelog
author_rank: Regular Contributor
timestamp: June 02, 2017, 07:11:21 am
content: Quote from: Fungus on June 02, 2017, 07:08:02 amI 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.

author: LaurentR
author_rank: Frequent Contributor
timestamp: June 02, 2017, 07:14:25 am
content: Quote from: Karel on June 02, 2017, 07:10:54 amFair. You don't need the full Visa stack, but you need a USBTMC driver.

author: Karel
author_rank: Super Contributor
timestamp: June 02, 2017, 07:18:29 am
content: Quote from: LaurentR on June 02, 2017, 07:14:25 amThe 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...

author: LaurentR
author_rank: Frequent Contributor
timestamp: June 02, 2017, 07:24:29 am
content: Quote from: Karel on June 02, 2017, 07:18:29 amI was going to say that for Windows, I don't think there is a USBTMC driver outside of the commercial Visa stacksNo further comment on the "most used OS in the world".

author: Karel
author_rank: Super Contributor
timestamp: June 02, 2017, 07:54:47 am
content: 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.htmlI 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:MESSAGE="*IDN?\n"exec 5<>/dev/tcp/192.168.1.6/5555printf $MESSAGE >&5MESSAGE=$(dd bs=$NUM_BYTES count=$COUNT <&5 2> /dev/null)echo $MESSAGEexec 5<&-exec 5>&-

author: edgelog
author_rank: Regular Contributor
timestamp: June 02, 2017, 07:57:29 am
content: Quote from: Karel on June 02, 2017, 07:54:47 amHm... interesting. Could be handy for short scripts, but probably unwieldy for anything more complicated.

author: Karel
author_rank: Super Contributor
timestamp: June 02, 2017, 08:38:43 am
content: Quote from: Mechatrommer on June 02, 2017, 08:03:35 amNo, it's Linux.

author: H.O
author_rank: Frequent Contributor
timestamp: June 02, 2017, 10:04:16 am
content: 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 onedgelog'sOS of choice -whatever that is.

author: edgelog
author_rank: Regular Contributor
timestamp: June 02, 2017, 10:19:01 am
content: Quote from: H.O on June 02, 2017, 10:04:16 amMacOS, in my case. But, if need be, I can live with one of "the others".

author: H.O
author_rank: Frequent Contributor
timestamp: June 02, 2017, 10:56:45 am
content: Yeah, I'm sorry, you've told us. I didn't mean to imply you hadn't, my last sentence should probably haveread 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.

author: Dwaine
author_rank: Frequent Contributor
timestamp: June 02, 2017, 11:56:24 am
content: 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.

author: edgelog
author_rank: Regular Contributor
timestamp: June 02, 2017, 01:04:41 pm
content: Quote from: Dwaine on June 02, 2017, 11:56:24 amNice. I'll try that if my Swift attempt becomes too onerous.

author: Dwaine
author_rank: Frequent Contributor
timestamp: June 02, 2017, 03:58:51 pm
content: 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 usbtmcimport vxi11import serialimport Gpibimport os.pathimport sysimport timefrom BME280 import *LogDir = '/pub/logs/'LogFile= LogDir + 'DM3068_Log.csv'Reflevel = 16.800000000# SensorsBME_Enabled = 0if (BME_Enabled == 1):BMEsensor = BME280(address=0x76)# Rigol DM3068 Lan Connectioninst = 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 measurementsinst.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 Measurementinst.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 headerif (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)*1E6if (BME_Enabled == 1):# Reads sensor dataTemperature = 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()

author: edgelog
author_rank: Regular Contributor
timestamp: June 02, 2017, 04:10:05 pm
content: Quote from: Dwaine on June 02, 2017, 03:58:51 pmGreat stuff! Thx!

author: Karel
author_rank: Super Contributor
timestamp: June 02, 2017, 06:57:10 pm
content: Quote from: H.O on June 02, 2017, 10:04:16 amWithout Linux, no Android.Without Android, Linux doesn't care at all.

author: kandrey89
author_rank: Contributor
timestamp: June 04, 2017, 04:00:12 am
content: Is anyone else peeved about Rigol's RS232 implementation regarding termination characters?Specifically,INSTRUMENT RECEIVE: requires "\r\n" in order to process the commands correctlyINSTRUMENT SEND: instrument sends data with "\n" only, its not possible to choose the termination character, unlike Keithley instruments that can do "\r\n", "\r", "\n", "\n\r" or "" (ie none).Basically, I was setting up a class for RS232 communication, and I have many devices that it needs to talk to and I found that I had to change "newline" definitions in windows SerialPort C# wrapper between read and write commands, otherwise Rigol wouldn't communicate properly. "\r\n" for write and "\n" for read is a PITA.I think I'm going to send them an email asking that they update the firmware to allow instrument selection of termination character, currently there's only 2 options available for selection: Baud rate and Parity, there's no Data Bits, Stop Bits, nor Flow Control.