coder.mapping.api.get - Get code mappings for model - MATLAB (original) (raw)
Main Content
Get code mappings for model
Since R2020b
Syntax
Description
[coderMapObj](#mw%5F85a36df0-d5ca-4cab-b3c1-05e2e4eb3207) = coder.mapping.api.get([simulinkModel](#mw%5F07e10cd2-81d0-48cf-a5f6-66943a4c56b5))
returns the active code mappings for the specified model as objectcoderMapObj
. Code mappings associate model data elements with configurations for C or C++ code generation. If a model has multiple code mappings, the active code mappings are the mappings associated with the active system target file.
If code mappings do not exist, an error is generated. Simulink® creates a code mappings object when you open a coder app for the model. If you have not opened a coder app for the model, you can invoke the coder.mapping.utils.create function to create a code mappings object.
Examples
Use the programmatic interface to create and use code mappings objects of Simulink models.
Load the model NoCoderMapping
.
simulinkModel = "NoCoderMapping"; load_system(simulinkModel);
Use a try-catch
block to determine whether a code mappings object exists for the model. Inside the try
block, attempt to retrieve the existing object by using function coder.mapping.api.get
. Inside the catch
block, create a new code mappings object by using the function coder.mapping.utils.create
. Store the code mappings object in the variable codeMapObj.
Add print messages to show whether the model had an existing code mappings object or not.
try codeMapObj = coder.mapping.api.get(simulinkModel); fprintf("" + ... " ========================================================\n" + ... " The model already had code mappings.\n" + ... " ========================================================\n"); catch fprintf("" + ... " ==========================================\n" + ... " The model does not have code mappings.\n" + ... " Creating new code mappings for the model.\n" + ... " ==========================================\n"); codeMapObj = coder.mapping.utils.create(simulinkModel); end
========================================== The model does not have code mappings. Creating new code mappings for the model.
Retrieve the storage class of input port inport_1
of the model.
getInport(codeMapObj,"inport_1","StorageClass")
Set the storage class of input port inport_1
to ExportedGlobal
.
setInport(codeMapObj,"inport_1",StorageClass="ExportedGlobal")
Use the same try-catch
block to see how the function coder.mapping.api.get
is now able to retrieve the existing code mappings of the model.
try codeMapObj = coder.mapping.api.get(simulinkModel); fprintf("" + ... " ========================================================\n" + ... " The model already had code mappings.\n" + ... " ========================================================\n"); catch fprintf("" + ... " ==========================================\n" + ... " The model does not have code mappings.\n" + ... " Creating new code mappings for the model.\n" + ... " ==========================================\n"); codeMapObj = coder.mapping.utils.create(simulinkModel); end
======================================================== The model already had code mappings.
Retrieve the storage class of input port inport_1
of the model. Notice that it is the storage class that you set previously.
getInport(codeMapObj,"inport_1","StorageClass")
Close the model without saving it.
close_system(simulinkModel,false)
Input Arguments
Simulink model for which to return the code mapping object, specified as a handle, or a character vector or string scalar with the model name (without the.slx
file extension), or the relative or absolute path of the model file (including the .slx
file extension).
Note
The model must be loaded (for example, by usingload_system
).
Example: "configModel"
Data Types: char
| string
| handle
Data interface dictionary for which to return the code mappings object, specified as a Simulink.data.Dictionary object, or a character vector or string scalar with the relative or full path of the dictionary file (including the .sldd
file extension).
Example: "exCodeDefs.sldd"
Data Types: char
| string
| Simulink.data.Dictionary
Output Arguments
The code mappings object for the model, returned as a CodeMapping
object or a CodeMappingCPP
.
Version History
Introduced in R2020b