MATLAB Answers

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

95 views (last 30 days)
Ken Crandall
Ken Crandall on 1 Sep 2016
Edited: Vinod on 27 Sep 2019
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.

Answers (2)

Benjamin Huth
Benjamin Huth on 19 Jan 2019
Edited: 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', '', 'RemotePort', 5555, 'Tag', '');
% Create the tcpip object if it does not exist
% otherwise use the object that was found.
if isempty(obj1)
obj1 = tcpip('', 5555);
obj1 = obj1(1);
% Connect to instrument object, 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)

Vinod on 8 Sep 2016
Edited: Vinod on 27 Sep 2019
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('',5555);
% Connect to instrument object, obj1.
% Stop data acquisition
% 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
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
timescale = str2double(fread(scopeInterface));
% Get the timescale offset
timeoffset = str2double(fread(scopeInterface));
% Start data acquisition again, and put the scope back in local mode
Vinod on 13 Sep 2016
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.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!