Customizing the Target Build Process with sl_customization.m

Overview

The Simulink customization file sl_customization.m is a mechanism that allows you to use M-code to perform customizations of the standard Simulink user interface. The Simulink software reads the sl_customization.m file, if present on the MATLAB path, when it starts and the customizations specified in the file are applied to the Simulink session. For more information on the sl_customization.m customization file, see Customizing the Simulink User Interface in the Simulink documentation.

The sl_customization.m file can be used to register installation-specific hook functions to be invoked during the Real-Time Workshop build process. The hook functions that you register through sl_customization.m complement System Target File (STF) hooks (described in Customizing the Target Build Process with the STF_make_rtw Hook File) and post-code generation commands (described in Customizing Post Code Generation Build Processing in the Real-Time Workshop documentation).

The following figure shows the relationship between installation-level hooks and the other available mechanisms for customizing the build process.

Registering Build Process Hook Functions Using sl_customization.m

To register installation-level hook functions that will be invoked during the Real-Time Workshop build process, you create an M-file function called sl_customization.m and include it on the MATLAB path of the Simulink installation that you want to customize. The sl_customization function accepts one argument: a handle to an object called the Simulink.CustomizationManager. For example,

function sl_customization(cm)

As a starting point for your customizations, the sl_customization function must first get the default (factory) customizations, using the following assignment statement:

hObj = cm.RTWBuildCustomizer;

You then invoke methods to register your customizations. The customization manager object includes the following method for registering Real-Time Workshop build process hook customizations:

Your instance of the sl_customization function should use this method to register installation-specific hook functions.

The Simulink software reads the sl_customization.m file when it starts. If you subsequently change the file, you must restart the Simulink session or enter the following command at the MATLAB command line to effect the changes:

sl_refresh_customizations

Variables Available for sl_customization.m Hook Functions

The following variables are available for sl_customization.m hook functions to use:

If a hook is an M-script, it can directly access the valid variables. If a hook is an M-function, it can pass the valid variables as arguments to the function. For example:

hObj.addUserHook('after_make', 'afterMakeFunction(modelName,dependencyObject);');

Example Build Process Customization Using sl_customization.m

The sl_customization.m file shown in Example 1: sl_customization.m for Real-Time Workshop Build Process Customizations uses the addUserHook method to specify installation-specific build process hooks to be invoked at the 'entry' and 'after_tlc' stages of the Real-Time Workshop build. For the hook function source code, see Example 2: CustomRTWEntryHook.m and Example 3: CustomRTWPostProcessHook.m.

Example 1: sl_customization.m for Real-Time Workshop Build Process Customizations

function sl_customization(cm)
% Register user customizations

% Get default (factory) customizations
hObj = cm.RTWBuildCustomizer;

% Register Real-Time Workshop build process hooks
hObj.addUserHook('entry', 'CustomRTWEntryHook(modelName);');
hObj.addUserHook('after_tlc', 'CustomRTWPostProcessHook(modelName);');

end

Example 2: CustomRTWEntryHook.m

function [str, status] = CustomRTWEntryHook(modelName)
str =sprintf('Custom entry hook for model ''%s.''',modelName);
disp(str)
status =1;

Example 3: CustomRTWPostProcessHook.m

function [str, status] = CustomRTWPostProcessHook(modelName)
str =sprintf('Custom post process hook for model ''%s.''',modelName);
disp(str)
status =1;

If you include the above three files on the MATLAB path of the Simulink installation that you want to customize, the coded hook function messages will appear in the displayed output for Real-Time Workshop builds. For example, if you open the ERT-based model rtwdemo_udt, open the Real-Time Workshop pane of the Configuration Parameters dialog box, and click the Build button to initiate a Real-Time Workshop build, the following messages are displayed:

>> rtwdemo_udt

### Starting Real-Time Workshop build procedure for model: rtwdemo_udt
Custom entry hook for model 'rtwdemo_udt.'
Custom post process hook for model 'rtwdemo_udt.'
### Successful completion of Real-Time Workshop build procedure for model: rtwdemo_udt
>> 
  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS