Code covered by the BSD License  

Highlights from
getTEKtrace

getTEKtrace

by

 

04 May 2012 (Updated )

Retrives single trace from most Tektronix scopes over GPIB tested with TDS 3k and 784A and HP-54120B

Data=getTEKtrace(GPIB,CHstring)
function Data=getTEKtrace(GPIB,CHstring)
%Data=getTEKtrace(GPIB,CHstring)
% Retrives single trace from most Tektronix osilloscopes
% Tested with TDS 3k 2k and 784 series
% Aswell as HP-54120B
%
% GPIB: Instrument GPIB adress
% CHstring: string/num chanel number '1','2' etc or 'Ref1' etc...
%
% Output: Data <#x2>
%
% Version 2012-07-12




obj1 = instrfind('Type', 'gpib', 'BoardIndex', 0, 'PrimaryAddress', GPIB, 'Tag', '');

if isempty(obj1)
    g1=gpib('ni',0,GPIB);
else
    fclose(obj1);
    g1 = obj1(1);
end

set(g1,'InputBufferSize',8*50001);              % Standard is 512 ASCII signs that transfers

set(g1,'Timeout',10);
fopen(g1);
IDN=query(g1,'*IDN?');

if strcmp(IDN(1:9),'TEKTRONIX')
    switch CHstring(1)
        case {1, 2, 3, 4}
            CHstring=['CH' num2str(CHstring)];
        case {'1', '2', '3', '4'}
            CHstring=['CH' CHstring];
    end
    trash=query(g1,'wfmpre?'); %this should get most of the needed data
    fprintf(g1,['DATa:SOUrce ' CHstring]);
    fprintf(g1,'DATa:ENCdg ASCII');
    fprintf(g1,'DATa:WIDth 2'); % '1' = 8 bit, '2' = 16 bit
    fprintf(g1,'DATa:STArt 1');
    xLength=query(g1,'HORizontal:RECordlength?');
    fprintf(g1,['DATa:STOp ' xLength]);
    xLength=str2double(xLength);
    if xLength>10000
        set(g1,'Timeout',60);
    end
    value=str2num(query(g1,'CURve?'));
    Ymult=str2num(query(g1,['WFMPre:' CHstring ':Ymult?']));
    Yoff=str2num(query(g1,['WFMPre:' CHstring ':Yoff?']));
    value=(value-Yoff)*Ymult;
    xUnit=query(g1,['WFMPre:' CHstring ':XUNit?']);
    yUnit=query(g1,['WFMPre:' CHstring ':YUNit?']);
    units={xUnit,yUnit};
    
    startTime=str2num(query(g1,['WFMPre:' CHstring ':XZEro?']));
    timeDiv=str2num(query(g1,['WFMPre:' CHstring ':XINcr?']));
    
    IDN=query(g1,['*IDN?']);
    if strcmpi(IDN(1:18),'TEKTRONIX,TDS 784A')
        time=startTime+((0:length(value)-1)-length(value)/2)*timeDiv;
    else
        time=startTime+(0:length(value)-1)*timeDiv;
    end
else
    
    
    fprintf(obj1, 'ACQ:TYPE NORM;POINTS 1028');
    fprintf(obj1, ['DIG CHAN' CHstring]);
    fprintf(obj1, ['WAV:SOUR WMEM' CHstring ';FORM ASCII']);
    Waveform = str2num(query(obj1, 'WAV:DATA?'));
    
    Prem=str2num(query(obj1, ['WAV:SOUR WMEM' CHstring ';PRE?']));
    Xinc=Prem(5);
    Xor=Prem(6);
    Xref=Prem(7);
    Yinc=Prem(8);
    Yor=Prem(9);
    Yref=Prem(10);

    value=(Waveform-Yref)*Yinc+Yor;
    
    time=1:length(value);
    time=(time-Xref)*Xinc+Xor;
end

fclose(g1);

Data=[time' value'];

Contact us