Octave SCPI reference
On this page you will learn how to send SCPI-commands to a Bode device using the tool Octave.
Preconditions
The SCPI-Server is up and running and the Server_IP as well as Port are known.
Connecting to the Server
Note
The default port is 5025 for all Bode devices
A connection to the Server can be created using the tcpclient() function provided by the Instrument Control package.
Firstly load the instrument control package.
pkg load instrument-control
%Open TCP connection
t0 = tcpclient('Your IP here', 5025);
Also don't forget to specify the termination character.
configureTerminator(t0, 'LF') %'\n';
Note
We are using TCP connections here because Visa is not yet implemented in the Instrument Control package.
Sending queries and reading responses
If only sending commands without intention to read responses use the writeline() function
writeline(t0, '*RST');
If you want to read a possible response use the writeread() function.
response = writeread(t0, '*IDN?');
Note
Because this doesn't use Visa the communication can't be observed with NI I/O-Trace. We suggest using Wireshark to observe the TCP communication.
Estimating Measurement duration
Important
If you want many measurement points, the measurement is going to take longer. Therefore, you might need to reconfigure the timeout as shown above to ensure the measurement is finished, before a timeout occurs.
The timeout needs to be longer than the duration of the measurement. You can calculate how long the measurement is going to take with this simple query
time = char(writeread(t0, ":SENS:SWE:TIME?"));
disp("Measurement duration: ");
disp(time);
This will give you an estimation on the duration and you can configure the timeout value based on this result.
Note
Calculate the duration of the measurement only after configuring the sweep settings.
Terminate
After the communication is finished don't forget to close the session to prevent errors in following command cycles.
clear t0;
Example connection test
Here is an example on how to test your connection to the SCPI-Server on any Bode.
pkg load instrument-control
%Open TCP connection
t0 = tcpclient('Your IP here', 5025);
response = writeread(t0, '*IDN?');
id = char(response);
disp(id)
clear t0;
Example Sweep Measurement
Here is an example on how to perform a single sweep measurement.
clear all;
pkg load instrument-control
disp('Hello World')
%Show which interfaces are supported
supportedinterfaces = instrhwinfo().SupportedInterfaces;
%disp(supportedinterfaces)
disp('Trying to connect to Server: ');
tic;
%Open TCP connection
t0 = tcpclient('172.22.44.19', 5025); %replace this with your IP
configureTerminator(t0, 'LF');
%Get the SCPI Server id
response = writeread(t0, '*IDN?');
id = char(response);
disp('SCPI client connected to SCPI Server: ');
disp(id);
clear response;
%Trying to lock the Bode device
response = writeread(t0, ':SYST:LOCK:REQ?');
lockOK = char(response);
disp('Locking status: ');
disp(lockOK);
clear response;
%Resets
writeline(t0, '*CLS');
writeline(t0, '*RST');
writeline(t0, '*ESE 255'); %enable errorchecks
%check for errors after reset
response = writeread(t0, ':SYST:ERR?');
error = char(response);
disp('After reset: ');
disp(error);
clear response;
clear error;
%Sweep config
writeline(t0, ':SENS:FREQ:STAR: 10kHz'); %start freq = 10kHz
writeline(t0, ':SENS:FREQ:STOP 10MAHz'); %stop freq = 10MAHz
writeline(t0, ':SENS:SWE:POIN 20'); %Measurement points = 20
writeline(t0, ':SENS:SWE:TYPE LOG'); %logarithmic sweep
writeline(t0, ':SENS:BAND 300Hz'); %receiver bandwidth = 300Hz
%check for errors after sweep config
response = writeread(t0, ':SYST:ERR?');
error = char(response);
disp('After sweep config: ');
disp(error);
clear response;
clear error;
%estimate measurement duration
time = char(writeread(t0, ":SENS:SWE:TIME?"));
disp("Measurement duration: ");
disp(time);
%trigger config
writeline(t0, ':CALC:PAR:DEF Z'); %one-port impedance measurement
writeline(t0, ':CALC:FORM SLIN'); %linear magnitude and phase
writeline(t0, ':TRIG:SOUR BUS'); %Bus is trigger source
writeline(t0, ':INIT:CONT ON'); %initialize the trigger
writeline(t0, ':TRIG:SING'); % trigger single measurement
%check for errors after trig config
response = writeread(t0, ':SYST:ERR?');
error = char(response);
disp('After trig config: ');
disp(error);
clear response;
clear error;
%Wait until all operations are finished
response = writeread(t0, '*OPC?');
opc = char(response);
disp('Operations finished status: ');
disp(opc);
clear response;
%get the frequency points
response = writeread(t0, ':SENS:FREQ:DATA?');
freqs = char(response);
disp('frequencies: ');
disp(freqs);
clear response;
%get the measurement data
response = writeread(t0, ':CALC:DATA:SDAT?');
results = char(response);
disp('results: ');
disp(results);
clear response;
%Release the Bode device
response = writeread(t0, ':SYST:LOCK:REL?');
relOK = char(response);
disp('release stauts: ');
disp(relOK);
clear response;
duration = toc;
%Convert data into readable arrays
freqlist = str2double(strsplit(freqs, ','));
allResults_list_raw = str2double(strsplit(results, ','));
magnitude = allResults_list_raw(1:20); % change this according to your measurement points
phase = allResults_list_raw(21:end); % same here
%print the data
disp(freqlist);
disp(magnitude);
disp(phase);
disp('Measurment complete. Time in seconds: ');
disp(duration);
clear t0;