This example shows how to use an Simulink® Real-Time™ 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 development computer and plotted.
Open the model
xpcFileLogging. 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 all(~strcmp('xpcosc', systems)) mdlOpen = 1; open_system('xpcFileLogging'); end
Build the model and download to the target computer
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 Simulink Real-Time build procedure for model: xpcFileLogging ### Generated code for 'xpcFileLogging' is up to date because no structural, parameter or code replacement library changes were found. ### Successful completion of build procedure for model: xpcFileLogging ### Looking for target: SGI7 ### Download model onto target: SGI7
Using the Simulink Real-Time object variable,
tg, start the model.
tg = SimulinkRealTime.target; start(tg); pause(5); % Capture the target computer screen which displays the sinusoids in two target scopes. tg.viewTargetScreen(); % Wait until the run is complete. while strcmp(tg.Status, 'running') pause(0.05); end
% Attach to the target computer file system. f=SimulinkRealTime.fileSystem; % Open the file, read the data, close the file. h=fopen(f,'fLogData.dat'); data=fread(f,h); f.fclose(h); % Unpack the data. x=SimulinkRealTime.utils.getFileScopeData(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');