Ce programme a pour but de transformer le langage binaire de l oscilloscope numérique en des données exploitables sur l écran de l ordinateur. Il est également utilisé par le programme programme_principal_binaire_temp MODIFIED  pour commander le déplacement du laser de lecture.


Voici le code réalisé sous Matlab, qui nous a permit de faire ce programme. 

% version épurée par OX de LCread pour éviter de perdre du temps à lire des
% choses inutiles.
% Rq: vérifier que les choses supprimées sont bien inutiles :-)
% Pour celà, comparer avec LCread


% LCREAD read binary waveform file created by a LeCroy Oscilloscope
%   W=LCREADOX(FILENAME) loads the waveform file into the workspace variable W.
%     FILENAME can either be a variable or a string constant enclosed by quotes.
%
%   The return value W is a record containing four elements:
%     W.INFO   Waveform information, in readable formats. For example Oscilloscope ID, sampling time and settings
%     W.DESC   Waveform information used for further calculations. For example Sampling rate
%     W.Y      Values sampled by the oscilloscope
%     W.X      Array of time values corresponding to W.Y. Time '0' marks the trigger event
%
%   The routine was tested with files generated by a LC564A, Template LECROY_2_2
%
% See also LCPLOT LCPLOTEXT
%
%------------------------------------------------------
% (c)2001 Hochschule für Technik+Architektur Luzern
% Fachstelle Elektronik
% 6048 Horw, Switzerland

function wave=ReadLecroy(fn);
%---------------------------------------------------------------------------------------
% Seek offset in the header block
%---------------------------------------------------------------------------------------
fid=fopen(fn,'r');
if fid==-1
   disp (sprintf('ERROR: file not found: %s', fn));
   return
end;

data=fread(fid,50);
WAVEDESC=findstr('WAVEDESC', char(data(1:50)'))-1;
    % subtract 1 because:
   %        - 1st byte in the File = Index [0]
   %        - 1st byte in the Matlab-Array = Index[1]
  
%---------------------------------------------------------------------------------------
% Define the addresses of the various informations in the file
% These addresses are valid for the template LECROY_2_2 and are subject to change in
% future revisions of the LeCroy firmware
%---------------------------------------------------------------------------------------
TESTED_TEMPLATE = 'LECROY_2_3';

%Addresses (WAVEDESC + address as stated in the LECROY template)
aTEMPLATE_NAME        = WAVEDESC+ 16;
aCOMM_TYPE            = WAVEDESC+ 32;
aCOMM_ORDER            = WAVEDESC+ 34;
aWAVE_DESCRIPTOR    = WAVEDESC+ 36;    % length of the descriptor block
aUSER_TEXT            = WAVEDESC+ 40;    % length of the usertext block
aWAVE_ARRAY_1        = WAVEDESC+ 60;    % length (in Byte) of the sample array
aVERTICAL_GAIN        = WAVEDESC+ 156;
aHORIZ_INTERVAL    = WAVEDESC+ 176;
aHORIZ_OFFSET        = WAVEDESC+ 180;

%---------------------------------------------------------------------------------------
% determine the number storage format HIFIRST / LOFIRST     (big endian / little endian)
%---------------------------------------------------------------------------------------

fseek(fid,aCOMM_ORDER,'bof');
COMM_ORDER=fread(fid,1,'int16');
fclose(fid);
% reopen the data file using the correct HIFIRST/LOFIRST format
if COMM_ORDER==0   
   fid=fopen(fn,'r','ieee-be');        % HIFIRST
else
   fid=fopen(fn,'r','ieee-le');        % LOFIRST
end;

%---------------------------------------------------------------------------------------
% Get the waveform information
%--------------------------------------------------------------------------
% Instrument
wave.info.Filename                = fn;

% Vertical settings
VERTICAL_GAIN                = ReadFloat    (fid, aVERTICAL_GAIN);

% Horizontal settings
HORIZ_INTERVAL            = ReadFloat(fid, aHORIZ_INTERVAL);
HORIZ_OFFSET            = ReadDouble(fid, aHORIZ_OFFSET);

%---------------------------------------------------------------------------------------
% Read samples array (Plain binary ADC values)
%---------------------------------------------------------------------------------------
COMM_TYPE            = ReadWord(fid, aCOMM_TYPE);
WAVE_DESCRIPTOR     = ReadLong(fid, aWAVE_DESCRIPTOR);
USER_TEXT            = ReadLong(fid, aUSER_TEXT);
WAVE_ARRAY_1        = ReadLong(fid, aWAVE_ARRAY_1);

fseek(fid, WAVEDESC + WAVE_DESCRIPTOR + USER_TEXT, 'bof');
if COMM_TYPE == 0  % byte
   wave.y=fread(fid,WAVE_ARRAY_1, 'int8');
   % Transform the ADC values to voltages and create corresponding array of
   % time
   wave.y = VERTICAL_GAIN * wave.y ;
   wave.x = [0:(WAVE_ARRAY_1-1)]'*HORIZ_INTERVAL ;
else    %    word
   wave.y=fread(fid,WAVE_ARRAY_1, 'int16');
   wave.y = VERTICAL_GAIN * wave.y ;
   wave.x = [0:(WAVE_ARRAY_1-1)/2]'*HORIZ_INTERVAL + HORIZ_OFFSET ;
end;

%---------------------------------------------------------------------------------------
% close the waveform file
%---------------------------------------------------------------------------------------
fclose(fid);

%=======================================================================================
% Support functions
%=======================================================================================
  
%---------------------------------------------------------------------------------------
% Read 16Bit signed Word
%---------------------------------------------------------------------------------------
function w=ReadWord(fid, Addr)
    fseek(fid,Addr,'bof');
    w=fread(fid,1,'int16');
   
%---------------------------------------------------------------------------------------
% Read 32Bit signed Long
%---------------------------------------------------------------------------------------
function l=ReadLong(fid, Addr)
    fseek(fid,Addr,'bof');
    l=fread(fid,1,'int32');
  
%---------------------------------------------------------------------------------------
% Read 32Bit IEEE Float
%---------------------------------------------------------------------------------------
function f=ReadFloat(fid, Addr)
    fseek(fid,Addr,'bof');
    f=fread(fid,1,'float32');
   
%---------------------------------------------------------------------------------------
% Read 64Bit IEEE Double
%---------------------------------------------------------------------------------------
function d=ReadDouble(fid, Addr)
    fseek(fid,Addr,'bof');
    d=fread(fid,1,'float64');
  

Retour en haut de la page.