I rewrote the code (from blog post in 2020) for my Tektronix oscilloscope to use a recent version of MATLAB and Instrument Control Toolbox—i.e., no VISA, just the TCP/IP client from the scope.
The full article and code can be found here:
https://www.biophysicslab.com/2024/08/01/matlab-script-for-tektronix-scope-plot-and-measure/Because I include the pre-trigger sample number ('WFMOutpre:PT_OFF?'), the plot looks like the scope display - i.e., x=0 is not necessarily in the center of the plot.
Here are the SCPI commands used for accurate time and scale plotting:
% ymult > SCPI command: 'WFMOutpre:YMULT?'
% yzero > SCPI command: 'WFMOutpre:YZERO?'
% yoff > SCPI command: 'WFMOutpre:YOFF?'
% xincr > SCPI command: 'WFMOutpre:XINCR?'
% xzero > SCPI command: 'WFMOutpre:XZERO?'
% pre_trig_record > SCPI command: 'WFMOutpre:PT_OFF?'
Here is the setup code to demonstrate what features I baked into the MATLAB script:
%% User Inputs
% Controls for oscilloscope
input_channel = 'CH3';
timeout = 10; % time allowed to complete operations in seconds
buffer_size = 3E6; % large enough to capture 2-byte int16 data
scope_vendor = "Tektronix";
% Controls for Matlab ICT tcpclient scope connect function
% for troubleshooting:
% - enter the IP address into a web browser (to get eScope utility)
% - refer to scope menu: Utility > IO > Lan
TCPIP_address = "192.168.1.160";
TCPIP_port = 4000;
% Controls for saving data as an image, figure, or workspace mat
save_plot = false;
save_fig = false; % may take a long time
save_workspace = false; % may take a long time
save_plot_resolution = 300; % dpi
save_plot_extension = 'png'; % 'jpeg' | 'png' | 'tiff' | 'pdf' | 'eps' | ...
% example file name for saving data: scope_mso64b_channel1_07312024_131849
file_name_base = 'scope';
figure_name = "MATLAB script tcpclient_scope_demo.m";
plot_channel = plot_channelname(input_channel);
plot_color = get_plotcolor();
% Position legend inside or outside the plot
% my favorites: 'best' | 'northeast' 'northwest' [default] | 'eastoutside' | ...
plot_legend_position = 'northwest';
plot_fullsize = true; % false > use default plot size (~ 30% of screen)
% Control for user changeable scope and plot measurements
plot_measurements = true;