Main Content

getGlobalArg

Class: Simulink.CodeImporter.SimulinkPortSpecification
Namespace: Simulink.CodeImporter

Get object definition of global variable in C Caller block

Since R2021a

Description

GlobalArg = getGlobalArg(PortSpecObj, globalVariableName), where PortSpecObj is an object of class Simulink.CodeImporter.SimulinkPortSpecification, creates a FunctionArgument object for the specified global argument. To use global variables in a model that uses C Caller blocks, enable the Enable custom code globals as function interface setting from Configuration Parameters > Simulation Target.

example

Input Arguments

expand all

Port specification, specified as a handle to a Simulink.CodeImporter.SimulinkPortSpecification object.

Name of global variable, specified as a character vector or string scalar.

Data Types: char | string

Output Arguments

expand all

Global argument object associated with the C Caller block, returned as a FunctionArgument object.

Examples

expand all

Access the properties of a global variable for a function specified in the Simulink® Code Importer.

Create a code importer object.

obj = Simulink.CodeImporter;

Set the library file name and output folder.

obj.LibraryFileName = "pumpController";
obj.OutputFolder = ".";

Set the custom code to import.

obj.CustomCode.InterfaceHeaders = ["pumpController.h"];
obj.CustomCode.IncludePaths = ["./include"];
obj.CustomCode.SourceFiles = ["src/pumpController.c" "src/utils.c"];

Allow global variables as function interfaces.

obj.CustomCode.GlobalVariableInterface = true;

Parse custom code and configure the function.

parse(obj);
fcn = getFunctions(obj.ParseInfo, "InitFunction");

Obtain and configure the global argument used in InitFunction.

timeout = getGlobalArg(fcn.PortSpecification, 'timeout');
timeout.label = "TimeoutValue";

Version History

Introduced in R2021a