MATLAB Answers

0

I would like an example of scpi over ethernet to Rigol Instruments using the instrument control toolbox.

Asked by Ken Crandall on 1 Sep 2016
Latest activity Answered by Peter Gamma on 19 Jun 2019 at 17:47
There seems to be a lack of any examples that show how to set up a communications session with Rigol Instruments such as their oscilloscopes, multimeters, arbgens, power supplies . . . using TCP/IP and SCPI commands.

  0 Comments

Sign in to comment.

3 Answers

Answer by Benjamin Huth on 19 Jan 2019
Edited by Benjamin Huth on 20 Jan 2019

I have several RIGOL instruments, and they all communicate over TCPIP on port 5555. I have the instrument control app, and once I found the port number, I can add the instruments with the port via the communications screen that is part of the app. This works for DM3068, DG4102, DS2202E, and DP832A. The following example is from the session log:
%% Instrument Connection
% Find a tcpip object.
obj1 = instrfind('Type', 'tcpip', 'RemoteHost', '192.168.1.62', 'RemotePort', 5555, 'Tag', '');
% Create the tcpip object if it does not exist
% otherwise use the object that was found.
if isempty(obj1)
obj1 = tcpip('192.168.1.62', 5555);
else
fclose(obj1);
obj1 = obj1(1);
end
% Connect to instrument object, obj1.
fopen(obj1);
%% Instrument Configuration and Control
% Communicating with instrument object, obj1.
data1 = query(obj1, '*IDN?');
I get back the instrument identifier string.
If you are not using the Test and Measurement GUI, then change the instrfind code to:
obj1 = tcpip('RemoteAddr',5555)

  0 Comments

Sign in to comment.


Answer by Vinod
on 8 Sep 2016

I've not tested this as I don't have a Rigol scope, but you should be able to start from here:
# Initialize scope. The port number may be 5556 on certain scopes.
scopeInterface = tcpip('192.168.1.1',5555);
# Stop data acquisition
fwrite(scopeInterface,':STOP')
# Grab the data from channel 1
fwrite(scopeInterface, ':WAV:POIN:MODE NOR');
fwrite(scopeInterface,':WAV:DATA? CHAN1');
data = fread(scopeInterface,9000,'uint8');
# Get the voltage scale
write(scopeInterface, ':CHAN1:SCAL?');
voltscale = str2double(fread(scopeInterface));
# And the voltage offset
fwrite(scopeInterface,':CHAN1:OFFS?');
voltoffset = str2double(fread(scopeInterface));
# Walk through the data, and map it to actual voltages
data = data * -1 + 255;
# Now, we know from experimentation that the scope display range is actually
# 30-229. So shift by 130 - the voltage offset in counts, then scale to
# get the actual voltage.
data = (data - 130.0 - voltoffset/voltscale*25) / 25 * voltscale;
# Get the timescale
fwrite(scopeInterface,':TIM:SCAL?')
timescale = str2double(fread(scopeInterface));
# Get the timescale offset
fwrite(scopeInterface,':TIM:OFFS?');
timeoffset = str2double(fread(scopeInterface));
# Start data acquisition again, and put the scope back in local mode
fwrite(scopeInterface,':RUN')
fwrite(scopeInterface,':KEY:FORC')

  3 Comments

1. changed # to % for Matlab comment. 2. I get the error on line 4 fwrite statement: "OBJ must be connected to the hardware with FOPEN"
Have you tested this code on any instruments?
1. To resolve the error, I added the line fopen(scopeInterface) and at the end a fclose(scopeInterface). 2. Trying port 5555, there is a time-out error. 3. Trying port 5556, the error was "Connection refused"
So I'm still stuck. Any suggestions?
Sorry - I do not have a Rigol scope to test the code. The FOPEN is definitely needed.
The "Connection refused" could be because of a number of reasons
  1. A firewall or antivirus is blocking the connection. The firewall could be on the PC or on the scope
  2. The SCPI parser is not running on the scope
  3. Some network infrastructure is blocking the connection
  4. An incorrect IP address for the scope
I'd recommend getting in touch with Rigol tech support to see what needs to be done to have an external application connect to the scope over TCPIP

Sign in to comment.


Answer by Peter Gamma on 19 Jun 2019 at 17:47

I have a similar problem with an Owon oscilloscope as Ken Crandall has. Matlab supports the SCPI protocol, and Owon supports the SCPI protocol, so it should work that they can talk together.
Unfortunately, I could not find an example in the Owon documentation, which explains how to do this. And I did not get an answer from the Owon support either, when I asked them wheather their oscilloscopes support Matlab:
I found the examples and explanations described here very helpful, and I ask myself wheather they can be modified and also apply for Owon oscilloscopes. I did not tested it yet. It is a bit of a challenge for a beginner like me in the field of SCPI protocols.
Owon has a very detailed manual for the SCPI protocol for Owon VDS Series oscilloscopes:
But I miss a simple example how to connect an Owon oscilloscope to Matlab via the SCPI protocol.

  0 Comments

Sign in to comment.