%% gpibee_vxi11_demo.m % % MATLAB demo talking to an HP 34401A (or any SCPI DMM) over VXI-11 % through a GPIBee, using the Instrument Control Toolbox's visadev() % interface. % % Unlike the Octave port next door (which talks native VXI-11 with no % VISA runtime installed at all), MATLAB's VXI-11/TCPIP support sits on % top of VISA -- see README.md for why, and what you need installed. % Same instrument, same GPIBee, same VXI-11 wire protocol underneath; % just a different client-side stack. % % Run: open this file in MATLAB and press Run, or `run gpibee_vxi11_demo` % Requires: MATLAB Instrument Control Toolbox, and a VISA runtime % (NI-VISA, Keysight IO Libraries, R&S VISA, ...) installed separately. %% ---- configuration ----------------------------------------------------- instrument_ip = "192.168.3.2"; % GPIBee / instrument LAN address instrument_name = "inst0,4"; % VXI-11 device name (same % "inst0,4"-style convention used % by every other example in this % project -- see the top-level % README.md) resource = "TCPIP0::" + instrument_ip + "::" + instrument_name + "::INSTR"; read_count = 100; % number of MEAS:VOLT:DC? readings io_timeout_s = 3; % matches the 3 s timeout used % throughout this project %% ---- connect and log ----------------------------------------------------- fprintf("Connecting to %s ...\n", resource); v = []; try v = visadev(resource); v.Timeout = io_timeout_s; % writeline()/writeread()'s default Terminator is "LF" ("\n"), % matching the LF write/read termination used by every other % example in this project. idn = writeread(v, "*IDN?"); fprintf("*IDN?: %s\n", idn); fprintf("Reading %d DC-voltage measurement(s) via MEAS:VOLT:DC? ...\n", read_count); readings = zeros(read_count, 1); elapsed_s = zeros(read_count, 1); t0 = tic; for i = 1:read_count response = writeread(v, "MEAS:VOLT:DC?"); readings(i) = str2double(response); elapsed_s(i) = toc(t0); fprintf("#%3d: %-18s -> %.6f Vdc (t = %.2f s)\n", ... i, strtrim(response), readings(i), elapsed_s(i)); end catch ME if ~isempty(v) clear v end rethrow(ME) end clear v % releases the VISA session -- visadev has no explicit close(); % the connection is closed when the object is cleared or goes % out of scope fprintf("Connection closed.\n"); %% ---- plot ------------------------------------------------------------ figure; plot(elapsed_s, readings, "-o"); grid on; xlabel("Elapsed time (s)"); ylabel("DC Voltage (V)"); title(sprintf("HP 34401A MEAS:VOLT:DC? -- %d readings via %s", read_count, resource));