Code covered by the BSD License  

Highlights from
xPC Target Data Logging Methodologies

image thumbnail

xPC Target Data Logging Methodologies


Doug Jones (view profile)


12 Nov 2007 (Updated )

Describes several methods available to log and access signal data with xPC Target.

% FILESCOPEDATALOGGINGDEMO - Demonstrates xPC Target Data Logging Using a File Scope
%    This M-file was created in support of the xPC Target Application Note 
%    (xPCTAN-0100): "xPC Target Data logging Methodologies"

% Open, build, and run model.
open_system('sosModel4');                   % Open the model
set_param('sosModel4','RTWVerbose','off');  % Configure RTW for a non-Verbose build
rtwbuild('sosModel4');                      % Build and download to the target PC
close_system('sosModel4',0);                % Close the model
tg = xpc;                                   % Create an xPC Target Object
start(tg);                                  % Start xPC Target Object (run the model)

% Wait until model has finished running.
while ~strcmpi(tg.Status,'stopped');        % Is the run complete?

% Get data.
sc=getscope(tg,2);                          % Get file scope (Id: 2)
fsys = xpctarget.fs;                        % Connect to the target PC file system
h = fsys.fopen(sc.FileName);                % Open the log file
fsysData = fsys.fread(h);                   % Read the data
fsys.fclose(h);                             % Close the log file
dataLog = readxpcfile(fsysData);            % Convert uint8 log data to double
fsTime =,end);               % Get file scope time log (last column)
fsData =,1:end-1);           % Get file scope data log (other columns)

% Plot and save data.
plot(fsTime, fsData); grid on;              % Plot the data
title('DEMO: File Scope Data Logging');  
save sosFSDataLog.mat fsTime fsData;        % Save the data
disp('Data saved in: sosFSDataLog.mat')

Contact us