getInterfaceImpl
Syntax
interface = getInterfaceImpl(obj)
Description
MATLAB®
specifies the inputs and outputs of a System block as either data or a
message.interface
= getInterfaceImpl(obj
)
Run-Time Details
getInterfaceImpl
is part of the matlab.System
class and is called before the setupImpl
method.
Method Authoring Tips
You must set Access = protected
for this method.
You cannot modify any properties in this method.
Input Arguments
obj
— System object™
System object
System object handle used to access properties, states, and methods specific to the object. If
your getInterfaceImpl
method does not use the object, you can replace this
input with ~
.
Output Arguments
interface
— MATLAB System block interface
scalar of interface objects | vector of interface objects
MATLAB System block interface, returned as a scalar or vector of
matlab.system.interface.*
objects. Use
matlab.system.interface.Input
(signalName
,signalType
)
to define input signal types. Use
matlab.system.interface.Output
(signalName
,signalType
)
to define output signal types.
signalName
– Defines the name of the port. Represented by a character array.signalType
– Defines the type of port. The value is eithermatlab.system.interface.Data
ormatlab.system.interface.Message
.
Examples
Process Message Payload Using MATLAB System Block
This example shows how to send, receive, and process messages using the MATLAB System block. Use System objects to author blocks to model custom behavior to send and receive messages and manipulate the message payload.
Load and Open the Model
Open the slexMessageArrivalExample
model.
open_system('slexMessageArrivalExample');
This model contains a random number generator as a data source. Based on that data, the Message Sender sends a message with a sine wave payload to a queue block. The queue block stores the messages, and the Message Receiver converts the message back to data.
Specify Message Ports Using getInterfaceImpl
API
This message uses getInterfaceImpl
to specify the input and output message ports in the MATLAB System block for both the Message Sender and the Message Receiver. For the Message Sender, getInterfaceImpl
defines the output of the MATLAB System block as a message. This action prompts the System object™ to create a message output. For the Message Receiver, getInterfaceImpl
defines the input of the System object as a message and the output as data.
%Function to send messages function interface = getInterfaceImpl(~) import matlab.system.interface.*; interface = Output("Out1", Message); end
%Function to receive messages and output as data function interface = getInterfaceImpl(obj) import matlab.system.interface.*; interface = [Input("In1", Message), ... Output("Out1", Data), Output("out2", Data)]; end
Set the Propagators and Sample time
The following four propagators need to be set in the Message Sender: getOutputSizeImpl
, getOutputDataTypeImpl
, isOutputComplexImpl
, isOutputFixedSizeImpl
.
In this example, the message queue has a maximum capacity of 16 messages. The random number generator has a sample time of 0.1. The receiver has a sample time of 1. The Message Receiver sample time is set in the MATLAB System block using the getSampleTimeImpl
API.
function sts = getSampleTimeImpl(obj) sts = createSampleTime(obj,'Type','Discrete', ... 'SampleTime',obj.SampleTime); end
Simulate the Model and Review Results
The Scope block displays the results. These results show that as you run more simulations, the random number generator produces a number greater than zero 50% of the time, as expected.
Version History
Introduced in R2021a
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)