Real-Time Workshop User's Guide | ![]() ![]() |
Signal Objects
This section discusses how to use signal objects in code generation.
Configuring Signal Objects for Code Generation
In configuring signal objects for code generation, you use the following code generation options and signal object properties:
RTWInfo.StorageClass
. The storage classes defined for signal objects, and their effect on code generation, are the same for model signals and signal objects (see Storage Classes for Signals).RTWInfo.TypeQualifier
. This property is a storage type qualifier. The string is included as a prefix in the generated storage declaration. The syntax of the string is not checked for validity.Other signal object properties (such as user-defined properties of classes derived from Simulink.Signal) do not affect code generation.
Effect of Storage Classes on Code Generation for Signal Objects
The way in which the Real-Time Workshop uses storage classes to determine how signals are stored is the same with and without signal objects. However, if a signal's label resolves to a signal object, the object's RTWInfo.StorageClass
property is used in place of the port configuration of the signal.
The default storage class is Auto
. If the storage type is Auto
, the Real-Time Workshop follows the Signal storage reuse and Local block outputs code generation options to determine whether signal objects are stored in reusable and/or local variables. Make sure that these options are set correctly for your application.
To generate a a test point or externally-interfaceable signal storage declaration, use an explicit RTWInfo.StorageClass
assignment. For example, setting the storage class to SimulinkGlobal, as in the following command, is equivalent to declaring a signal as a test point.
SinSig.RTWInfo.StorageClass = 'SimulinkGlobal';
Example of Signal Object Code Generation
The discussion and code examples in this section refers to the model shown in Figure 3-14.
Figure 3-14: Example Model With Signal Object
To configure a signal object, you must first create it and associate it with a labelled signal in your model. To do this:
Simulink.Signal
. In this example, the signal object is an instance of the example class UserDefined.Signal, which is provided with Simulink. For the definition of UserDefined.Signal, see the directory matlabroot
/toolbox/simulink/simdemos/@UserDefined
.
SinSig = UserDefined.Signal;
Make sure that the name of the signal object matches the label of the desired signal in your model. This ensures that Simulink can resolve the signal label to the correct object. For example, in the model shown in Figure 3-14, the signal label SinSig would resolve to the signal object SinSig.
SinSig.RTWInfo.StorageClass = 'ExportedGlobal';
RTWInfo.StorageClass
property is not Auto
, you can assign a storage type qualifier to the RTWInfo.TypeQualifier property, for example,SinSig.RTWInfo.StorageClass = 'const';
Table 3-8 shows, for each setting of RTWInfo.StorageClass
, the variable declaration and the code generated for Sine Wave output (SinSig
) of the model shown in Figure 3-14.
![]() | Parameter Objects | Object Property Information in the model.rtw File | ![]() |