- Setup you S-function block with three output ports, one for the message, one for the message length and the last one for the trigger signal for function call subsystem
- Implement a logic in your S-function block that would output the signal whenever you want to call the function and send it to the “trigger” block input port.
- Create a “function call subsystem” and connect the trigger output port from the S-function block.
setting an outputport to the function call type in an s function
4 views (last 30 days)
Show older comments
Rick Gijsberts
on 17 Feb 2024
Answered: Rick Gijsberts
on 8 May 2024
Hello community.
I am working on a UDP receive block that is used with generated code for an embedded linux platform.
My goal is to have it output the message, message length and a function call output to process the message.
The block setup is currently like this
function sfcn_UDPReceive(block) %setup
tsamp = 1;
buff_len = 2;
%% Register number of input and output ports
block.NumInputPorts = 0;
block.NumOutputPorts = 2;
%% function call
%block.OutputPort(1); %Somehow set this to a function call? C code
%seems to suggest DatatypeID 9 is a function call, but it gives me an
%error when I use it here.
%% message length
block.OutputPort(2).Dimensions = 1;
block.OutputPort(2).DatatypeID = 7; %uint32
block.OutputPort(2).Complexity = 'Real';
block.OutputPort(2).SamplingMode = 'sample';
%% message
block.OutputPort(3).Dimensions = block.DialogPrm(buff_len).Data;
block.OutputPort(3).DatatypeID = 3; %uint8
block.OutputPort(3).Complexity = 'Real';
block.OutputPort(3).SamplingMode = 'sample';
% Number of S-Function parameters expected
% (tsamp, buff_len)
block.NumDialogPrms = 2;
block.SampleTimes = [block.DialogPrm(tsamp).Data 0];
block.RegBlockMethod('WriteRTW', @WriteRTW);
end
function WriteRTW(block)
buff_len = 2; % make buff_len available to .tlc file
block.WriteRTWParam('string', 'buff_len', num2str(block.DialogPrm(buff_len).Data));
end
How do I set block.OutputPort(1).DatatypeID to fcncall?
I have found examples of how to do it in C, which would then have to be compiled to mex files, but I like this interface being in regular matlab script.
The documentation for doing things this way seems way more scarse than that for the C-mex interface.
2 Comments
Ayush
on 1 Apr 2024
Hello Rick,
To integrate a function call output to an S-function block in MATLAB requires specific setup for the formatted output containing the message, its length along with the function call itself. Although there is no direct way to do the same, a similar output can be achieved by triggering a function call subsystem via the S-function block’s output acting as a trigger signal. Here are the steps for the same:
You can also refer to the documentation below to know more about “Trigger block” and “Function-Call subsystems”:
Hope this helps!
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Event Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!