removeSignal
Description
removeSignal(
removes signals specified by the block output port handles from the specified model code
mappings. coderMapObj
,portHandle
)
This function does not apply to signals that originate from root-level Inport blocks.
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
— Output port handles of signal source blocks
block output port handle | port handle array
Signal to remove from the code mappings, specified as the output port handle of the source block of the signal. To remove multiple signals simultaneously, specify an output port handle array.
Example: removeSignal(codeMapObj,[outport_1_Handle,outport_2_Handle])
Version History
Introduced in R2020b
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 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)