determine whether a input port is connected or not to a block

9 vues (au cours des 30 derniers jours)
grapevine
grapevine le 24 Fév 2012
Commenté : Jorge Castillo le 17 Sep 2024
Hi
I need to realize a Simulink block, which is capable to determine whether a input port is connected or not to a block if it is not connected ( which means, I guess, the input is null or empty) it returns 0 and it change the color of the port, otherwise it forwards the input to the output pourt.
I thought to use a matlab Fcn to realize this function I found helpful these commands portData = get_param(gcb,'PortConnectivity'); portData.SrcBlock
But it doesn't work as I want
Do you know if there is any way to archieve that? Any advices are welcome
thanks in advance
  1 commentaire
grapevine
grapevine le 24 Fév 2012
Sorry I said something wrong I cannot use a Matlab fcn but only an Embedded Matlab fcn, because my prof-boss doesn't wanna no mfiles in the library
If it was possible to use the Matlab fcn I would write that
if exist('u')
y = u;
else
y=1
end
but I can't
little help?

Connectez-vous pour commenter.

Réponse acceptée

grapevine
grapevine le 12 Mar 2012
I found it! I wrote this code in a callback function
portData=get_param(gcb,'PortConnectivity');
if (portData(1).SrcBlock==-1)
set_param(gcb,'Intern_External','0')
else
set_param(gcb,'Intern_External','1')
end
clear PortData
and it works

Plus de réponses (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by