addSignal
Description
addSignal(
adds signals specified by the block output port handles to the specified model code
mappings.coderMapObj
,portHandle
)
This function does not apply to signals that originate from root-level Inport blocks.
addSignal(
specifies one or more name-value arguments in addition to the input argument in the previous
syntax.coderMapObj
,portHandle
,Name=Value
)
Examples
Programmatically Add and Remove Signal Lines in Code Mappings of Simulink Models
Use the programmatic interface to add and remove signals in the code mapping configuration of a Simulink model.
To interactively observe how your commands are reflected in the Code Mappings editor, make sure it is open with the Signals/States tab selected. To learn how to open the Code Mappings editor, see Open the Code Mappings Editor – C.
Open the model CoderMapAPI
.
simulinkModel = "CoderMapAPI";
open_system(simulinkModel);
Use the function coder.mapping.api.get
to retrieve the code mapping object of the model.
codeMapObj = coder.mapping.api.get(simulinkModel);
Get the handles of the output ports of the four Gain
blocks and store them in variables.
port_handle_1 = get_param(simulinkModel+"/gain_1","PortHandles").Outport; port_handle_2 = get_param(simulinkModel+"/gain_2","PortHandles").Outport; port_handle_3 = get_param(simulinkModel+"/gain_3","PortHandles").Outport; port_handle_4 = get_param(simulinkModel+"/gain_4","PortHandles").Outport
port_handle_4 = 302.0016
Use the function addSignal
to add the signal to the code mappings of the model. Set the storage class of sig_1
and sig_3
to ImportedExtern
and the storage class of sig_2
and sig_4
to ImportedExternPointer
. Update the model.
addSignal(codeMapObj,[port_handle_1,port_handle_3],StorageClass="ImportedExtern") addSignal(codeMapObj,[port_handle_2,port_handle_4],StorageClass="ImportedExternPointer") set_param(simulinkModel,"SimulationCommand","update")
Use the slbuild
command to generate code from the model.
evalc("slbuild(simulinkModel)");
Signals with ImportedExtern
and ImportedExternPointer
storage classes are declared in separate sections of the generated private header file of the model. Store the name of the private header file in the variable priv_h_file
.
priv_h_file = fullfile(simulinkModel+"_grt_rtw",simulinkModel+"_private.h")
priv_h_file = "CoderMapAPI_grt_rtw/CoderMapAPI_private.h"
The declarations of the signals appear as the following code in the header file:
/* Imported (extern) block signals */ extern real_T sig__1; /* '<Root>/gain_1' */ extern real_T sig__3; /* '<Root>/gain_3' */ extern real_T in_port_1; /* '<Root>/in_port_1' */ extern real_T in_port_2; /* '<Root>/in_port_2' */ /* Imported (extern) pointer block signals */ extern real_T *sig__2; /* '<Root>/gain_2' */ extern real_T *sig__4; /* '<Root>/gain_4' */ extern real_T *in_port_3; /* '<Root>/in_port_3' */ extern real_T *in_port_4; /* '<Root>/in_port_4' */
The signals are defined according to the specified storage classes.
To open the header file, enter this command in the MATLAB Command Window.
edit(priv_h_file)
Use the function removeSignal
to remove the first two signal lines from the code mappings of the model. Update the model.
removeSignal(codeMapObj,[port_handle_1,port_handle_2]) set_param(simulinkModel,"SimulationCommand","update")
Rebuild the model with the slbuild
command.
evalc("slbuild(simulinkModel)");
The updated sections appear as the following code in the header file.
/* Imported (extern) block signals */ extern real_T sig__3; /* '<Root>/gain_3' */ extern real_T in_port_1; /* '<Root>/in_port_1' */ extern real_T in_port_2; /* '<Root>/in_port_2' */ /* Imported (extern) pointer block signals */ extern real_T *sig__4; /* '<Root>/gain_4' */ extern real_T *in_port_3; /* '<Root>/in_port_3' */ extern real_T *in_port_4; /* '<Root>/in_port_4' */
The removed signals no longer appear in the header file.
Input Arguments
coderMapObj
— Code mapping object
CodeMapping
object
Code mapping object (model code mappings) returned by a call to function
coder.mapping.api.get
.
portHandle
— Signal to add to code mappings
block output port handle | port handle array
Signal to add to the code mappings, specified as the output port handle of the source block of the signal. To add multiple signals simultaneously, specify an output port handle array.
Example: addSignal(coderMapObj,[outport_1_Handle,outport_2_Handle])
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Example: StorageClass="ExportedGlobal"
StorageClass
— Name of storage class
"Auto"
| "ExportedGlobal"
| ...
The name of the storage class to set for the specified signals. The storage class is either defined in the internal Embedded Coder® Dictionary of the model, or in a shared Embedded Coder Dictionary that is attached to the model.
To learn more about signal data configuration for code generation, see Configure Signal Data for C Code Generation.
Identifier
— Name of variable
character vector | string scalar
Name for the variable that represents the signal data in the generated code.
Data Types: char
| string
DefinitionFile
— C source file
character vector | string scalar
File name for a C source file that contains definitions for global data read by
data elements and external code. Applies to storage classes
ExportToFile
and Volatile
.
Data Types: char
| string
GetFunction
— Name of get function
character vector | string scalar
Name of a get
function that a data element calls in the
generated code. Applies to storage class GetSet
.
Data Types: char
| string
HeaderFile
— C header file
character vector | string scalar
File name for a C header file that contains declarations for global data read by
data elements and external code. Applies to storage classes
ExportToFile
, GetSet
,
ImportFromFile
, and Volatile
.
Data Types: char
| string
Owner
— Owner of global data
character vector | string scalar
Name of the model that owns global data that is used by other models in the same
model hierarchy. The code generated for the owner model includes the global data
definition. Applies to storage classes ExportToFile
and
Volatile
.
Data Types: char
| string
PreserveDimensions
— Boolean flag indicating whether to preserve dimensions of multidimensional arrays
True
| False
When model configuration parameter Array layout is set to
Row-major
, a flag that indicates whether to preserve
dimensions of a data element that is represented in generated code as a
multidimensional array. Applies to storage classes ExportToFile
,
GetSet
, ImportFromFile
,
Localizable
, and Volatile
.
Data Types: logical
SetFunction
— Name of set function
character string | string scalar
Name of a set
function that a data element calls in the
generated code. Applies to storage class GetSet
.
Data Types: char
| string
StructName
— Name of structure
character vector | string scalar
Name that the code generator uses to identify the structure for a data element in
the generated code. Applies to storage classes Bitfield
and
Struct
.
Data Types: char
| string
storageClassPropertyName
— Value of storage class property
depends on property definition
Storage class property defined in the Embedded Coder Dictionary. Values that you can specify vary depending on the storage class definition.
MeasurementService
— Name of measurement service interface
Dictionary default
(default) | character vector | string scalar
String or character vector containing the name of a measurement service interface
defined in the Embedded Coder Dictionary. By configuring the measurement service
interface for signals, states, and data stores, you can preserve the data in the
generated code for measurement. To use the dictionary default, specify
"Dictionary default"
. If data from the state does not need to be
preserved in the code, specify "Not measured"
.
To configure the measurement service interface, the Embedded Coder Dictionary that defines a service interface configuration must be attached to the model. For more information, see Configure Measurement Service Interfaces for Signals, States, and Data Stores.
Data Types: char
| string
Version History
Introduced in R2020b
See Also
coder.mapping.api.CodeMapping
| coder.mapping.api.get
| find
| getDataDefault
| getSignal
| removeSignal
| setDataDefault
| setSignal
Comando de MATLAB
Ha hecho clic en un enlace que corresponde a este comando de MATLAB:
Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)