This example shows how to use an xPC Target™ file scope to log signal data to the file system on the target computer. Signals are logged during model execution. At the end of the run, the data is read from the file, uploaded to the host computer and plotted.
Open the model xpcFileLoggingxpcFileLogging. This model generates 20 sinusoids, each having a different amplitude. The signals are logged to the file fLogData.dat in the file system root directory on the target computer.
Note: Scopes of type 'target' are limited to 10 signals. However, scopes of type 'host' and 'file' can store a number of signals limited only by the hardware resources of the target computer.
% Open the model. mdlOpen = 0; systems = find_system('type', 'block_diagram'); if isempty(strmatch('xpcFileLogging', systems, 'exact')) mdlOpen = 1; open_system('xpcFileLogging'); end
Build the model and download to the target computer, TargetPC1.
set_param('xpcFileLogging','RTWVerbose','off'); % Configure for a non-Verbose build. rtwbuild('xpcFileLogging'); % Build and download application. % Close the model if we opened it. if (mdlOpen) bdclose('xpcFileLogging'); end
### Starting xPC Target build procedure for model: xpcFileLogging Warning: This model contains blocks that do not handle sample time changes at runtime. To avoid incorrect results, only change the sample time in the original model, then rebuild the model. ### Successful completion of build procedure for model: xpcFileLogging ### Looking for target: TargetPC1 ### Download model onto target: TargetPC1
Using the xPC Target object variable, tg, start the model.
tg = xpc; start(tg); pause(5); % Capture the target computer video screen which displays the sinusoids in two target scopes. xpctargetspy % Wait until the run is complete. while strcmp(tg.Status, 'running') pause(0.05); end
% Attach to the target computer file system. f=xpctarget.fs; % Open the file, read the data, close the file. h=fopen(f,'fLogData.dat'); data=fread(f,h); fclose(f,h); % Unpack the data. x=readxpcfile(data); % Plot 1 second of the data. figure; plot(x.data(:,21),x.data(:,1:20)); set(gca,'XLim',[0 1]); grid on; xlabel('Time (sec)'); ylabel('Amplitude');