MATLAB Answers

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

118 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.

  0 Comments

Sign in to comment.

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', '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.


Vinod
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('192.168.1.1',5555);
% Connect to instrument object, obj1.
fopen(scopeInterface);
% 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

Ken Crandall
Ken Crandall on 9 Sep 2016
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?
Ken Crandall
Ken Crandall on 9 Sep 2016
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?
Vinod
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.