- 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 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Rick Gijsberts
le 17 Fév 2024
Réponse apportée : Rick Gijsberts
le 8 Mai 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 commentaires
Ayush
le 1 Avr 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!
Réponse acceptée
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Event Functions dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!