How to connect Tektronix Oscilloscope TDS 224 to Matlab 2012b?

1 view (last 30 days)
I am trying to connect the oscilloscope so I can capture the waveform to the computer. Here is what I have so far.
function [s] = ConnectScope () % Disconnect and close all RS232 connections, to ensure proper % reconnections TEMP = instrfind; if ~isempty(TEMP) fclose(TEMP); delete(TEMP); clear TEMP; end
% set serial USB connection of COM3 to variable 'oscope'
% go into control panel of PC and find the right COM to connect
s = serial('COM5');
% Set buffer size and timeout
set(s,'BaudRate',9600,'DataBits',8,'Parity','none','StopBits',1);
set(s,'InputBufferSize',1024,'Terminator','LF','Timeout',30);
set(s,'ReadAsyncMode','continuous');
if strcmp(s.status,'closed') %%&& strcmp(SCOPE_address.PinStatus.CarrierDetect,'on')
fopen(s);
end
if strcmp(s.status,'open') && strcmp(s.PinStatus.CarrierDetect,'on')
% Reset system and clear error register
fprintf(s,'*RST');
fprintf(s,'*CLS');
% Wait for reset to complete
fprintf(s,'*OPC?');
status1 = fscanf(s);
% Set channel parameters
fprintf(s,'Display:Contrast 30');
fprintf(s,'SEL:CH1 ON'); % channel 1 on
fprintf(s,'SEL:CH2 ON'); % channel 2 on
fprintf(s,'SEL:CH3 ON'); % channel 3 on
fprintf(s,'SEL:CH4 OFF'); % channel 4 off
fprintf(s,'CH3:PROB 1');
fprintf(s,'CH2:PROB 10');
fprintf(s,'CH1:PROB 10');
fprintf(s,'CH4:PROB 1');
fprintf(s,'CH3:COUP AC');
fprintf(s,'CH2:COUP AC');
fprintf(s,'CH1:COUP DC');
fprintf(s,'CH4:COUP AC');
fprintf(s,'ACQ:MOD AVE');
fprintf(s,'ACQ:NUMAV 4');
fprintf(s,'MEASUREMENT:MEAS1:TYPE PK2PK; SOURCE CH3;');
fprintf(s,'MEASUREMENT:MEAS2:TYPE PK2PK; SOURCE CH2;');
fprintf(s,'MEASUREMENT:MEAS3:TYPE MEAN; SOURCE CH1;');
fprintf(s,'MEASUREMENT:MEAS4:TYPE FREQUENCY; SOURCE CH3;');
fprintf(s,'*IDN?');
% Set trigger parameters
fprintf(s,'TRIG:MAI:EDGE:SOU CH4');
fprintf(s,'TRIG:MAI:EDGE:COUP AC');
fprintf(s,'TRIG:MAI:LEV 0');
%
%%Check for errors
fprintf(s,'*ESR?');
%%gives each line more time to load properly 'experimental'
status2 = fscanf(s);
fprintf(s,'ALLE?');
status3 = fscanf(s);
display(['SCOPE error message: ', status3])
fread(s)
else
fclose(s);
delete(s);
clear scope;
s = 'error';
display('SCOPE error message: hardware not found')
end
end
I get error like:
Warning: Unsuccessful read: A timeout occurred before the Terminator was reached.

Answers (0)

Community Treasure Hunt

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

Start Hunting!