Registering mpt User Object Types

Introduction

Real-Time Workshop® Embedded Coder™ software allows you to create custom mpt object types and specify properties and property values to be associated with them (see Creating mpt Data Objects with Data Object Wizard). Once created, a user object type can be applied to data objects displayed in Model Explorer. When you apply a user object type to a data object, by selecting a type name in the User object type pull-down list in Model Explorer, the data object is automatically populated with the properties and property values that you specified for the user object type.

To register mpt user object type customizations, use the Simulink® customization file sl_customization.m. This file 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.

Registering mpt User Object Types Using sl_customization.m

To register mpt user object type customizations, you create an instance of 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.slDataObjectCustomizer;

You then invoke methods to register your customizations. The customization manager object includes the following methods for registering mpt user object type customizations:

Your instance of the sl_customization function should use these methods to register mpt object type customizations for your Simulink installation.

The Simulink software reads the sl_customization.m file when it starts. If you subsequently change the file, you must restart your MATLAB session to effect the changes.

Example mpt User Object Type Customization Using sl_customization.m

The sl_customization.m file shown in Example 2: sl_customization.m for mpt Object Type Customizations uses the addMPTObjectType method to register the user signal types EngineType and FuelType for mpt objects.

Example 2: sl_customization.m for mpt Object Type Customizations

function sl_customization(cm)
% Register user customizations

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

% Add commonly used signal types
hObj.addMPTObjectType(...
    'EngineType','Signal',...
    'DataType', 'uint8',...
    'Min', 0,...
    'Max', 255,...
    'DocUnits','m/sec');  

hObj.addMPTObjectType(...
    'FuelType','Signal',...
    'DataType', 'int16',...
    'Min', -12,...
    'Max', 3000,...
    'DocUnits','mg/hr');  

end

If you include the above file on the MATLAB path of the Simulink installation that you want to customize, the specified customizations will appear in Model Explorer. For example, you could view the customizations as follows:

  1. Start a MATLAB session.

  2. Open Model Explorer, for example, by entering the MATLAB command daexplr.

  3. Select Base Workspace.

  4. Add an mpt signal, for example, by selecting Add > MPT Signal.

  5. In the right-hand pane display for the added mpt signal, examine the User object type drop-down list, noting the impact of the changes specified in Example 2: sl_customization.m for mpt Object Type Customizations.

  6. From the User object type drop-down list, select one of the registered user signal types, for example, FuelType, as shown below, and verify that the displayed settings are consistent with the arguments specified to the addMPTObjectType method in sl_customization.m.

  


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