image thumbnail

Simulink block set for Gtkwave : An alternative of simulink scope.

by

 

04 Jun 2012 (Updated )

Simulink blockset to display the simulation data from simulink on GTKWave

GTKWaveCollectData
%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%
%   File Name       : GTKWaveBlockSet:GTKWaveCollectData.m
%   Version         : v1.2
%   Created By      : Tabrez Alam (TAB)
%   Last updated on : 11 June,2012
%   -----------------------------
%       Change Log
%   -----------------------------
%   Initial
%   v1.1 -  Version updated due to change in library model.   
%   v1.2 -  Version updated due to change in file GTKWaveCreateVCD.m
%                    
%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%

%%
function GTKWaveCollectData

    %----------------------------------------------------------------------
    % Check for initial errors
    %----------------------------------------------------------------------
    LaunchFlag = get_param(gcbh,'LaunchFlag');
    if strcmp(LaunchFlag,'On')
    else
        return;
    end
    
    % Get model name
    MdlName = bdroot(gcs);
    MdlParent = get_param(gcb,'Parent');

    % If GTKWavSetup block is not in root model, Give error
    if (~strcmp(MdlName,MdlParent))
            msgbox(sprintf(...
            'GTKSetup block is not in root of the model.\nPlease insert the block at root level of model only.'),...
            'GTKSetup block error','error'); 
        return;
    end

    %----------------------------------------------------------------------
    % Constant data used in the model
    %----------------------------------------------------------------------
    MatlabDType = {'boolean','uint8','int8','uint16','int16','uint32','int32','single','double'};
    GTKDType    = {'B'      ,'U8'   ,'S8'  ,'U16'   ,'S16'  ,'U32'   ,'S32'  ,'F32'   ,'F64'   };

    
    %----------------------------------------------------------------------
    % Collect the logging information
    %----------------------------------------------------------------------
    % Find all GTKLogPort in the model
    GTKlogBh = find_system(gcs,'FindAll','on','BlockType','SubSystem','MaskType','GTKLogPort');
    NoOfSig = length(GTKlogBh);
    
    % Collect the information from GTKLogPort block
    if NoOfSig<=0
        fprintf('\n[GTKSetup] No GTKLogPort found in the model.\n');
        fprintf('Please add GTKLogPort to start logging & Enjjoyy...\n\n');
        return;
    elseif NoOfSig==1
        SigName  = {get_param(GTKlogBh,'SigName')};
        SigDType = {get_param(GTKlogBh,'SigDType')};
        SigFlow  = {get_param(GTKlogBh,'SigFlow')};
    else
        SigName  = get_param(GTKlogBh,'SigName');
        SigDType = get_param(GTKlogBh,'SigDType');
        SigFlow  = get_param(GTKlogBh,'SigFlow'); 
    end
    
    
    %----------------------------------------------------------------------
    % Create the wait bar an place it always on top
    %----------------------------------------------------------------------
    Wbh = waitbar(0,'Collecting the simulation data','Name','Generatig data for GTKWave','WindowStyle','modal');
    frames = java.awt.Frame.getFrames();
    frames(end).setAlwaysOnTop(1); 

    %----------------------------------------------------------------------
    % Set the name of VCD file with full path
    %----------------------------------------------------------------------
    VCDFileName = [cd '\' MdlName '_GTKWaveData'];
        
    %----------------------------------------------------------------------
    % Copy the time series value
    %----------------------------------------------------------------------
    TimSer = evalin('base',['gw' SigName{1} '.time']);

    %----------------------------------------------------------------------
    % Get the number of signals & pre-allocate memory for them
    %----------------------------------------------------------------------
    
    SignalStruct(NoOfSig).Name  = '';
    SignalStruct(NoOfSig).Type  = '';
    SignalStruct(NoOfSig).Flow  = '';
    SignalStruct(NoOfSig).Value = 0;

    WaitBarfr = 1/NoOfSig;
    WaitBarCtr = 0;
    
    %----------------------------------------------------------------------
    % Create the group structure of signals to be passed for writing
    % VCD file
    %---------------------------------------------------------------------- 
    FlowType = 'Input';
    for y=1:2
       
        for x=1:NoOfSig
            if(strcmp(SigFlow{x},FlowType))
                SignalStruct(x).Name = SigName{x};
                SignalStruct(x).Type = GTKDType{strcmp(MatlabDType,SigDType{x})==1};
                SignalStruct(x).Flow = FlowType;
                SignalStruct(x).Value = evalin('base',['gw' SigName{x} '.signals.values']);
            end
            % Update waitbar
            waitbar(WaitBarCtr,Wbh,'Formating the simulation data');
            WaitBarCtr = WaitBarCtr+WaitBarfr;
        end

       if(y==1)
           FlowType = 'Output';
       end

    end
    
    %----------------------------------------------------------------------
    % Create the VCD file
    %----------------------------------------------------------------------
    try
        GTKWaveCreateVCD(MdlName,VCDFileName,TimSer,SignalStruct,Wbh);
        close(Wbh);
        GTKWaveRunVCD(VCDFileName);
    catch Err
        msgbox(sprintf('VCD file error.\n%s',Err.message'),'GTKWave Error','error','modal');
        close(Wbh);
    end
    

end
%%


Contact us