Simulink mex s-function: rename in/output port from c-code?
Show older comments
Hi
I'm struggeling with a problem: to rename scalar in/output signals of a custom mex-s-function block during initialization time (mdlInitializeSize() for example).
Is this possible? I tried several hacks so far, but got nothing but a bunch of MATLAB crashes... alas, we reached 2012, so at least web2.0 has to be good for something ;-)
My first try was to execute normal matlab code from the C-side using mexEvalString(). So something equivalent to:
p = get_param(gcb, 'PortHandles')
l = get_param(p.Outport, 'Line')
set_param(l, 'Name', 'myname')
But the "gcb" statement may choose some other blocks, and not always the block where the C-code is residing in... Is there some other possibility to access the current S-Function block at this stage?
In the documentation I found the suggestion to be at least able to check the name of an "Bus Port" (and only after certain things are applied, so this just may go in a kind of right direction and not solve my problem):
DTypeId dType = ssGetOutputPortDataType(S, 0);
int numElems = ssGetNumBusElements(S, dType);
const char *elemName = (char*)ssGetBusElementName(S, dType, 0);
std::cout << elemName << std::endl;
...which will crash during execution. probably because i dont have a bus but a single port... Since I found no field named "name" or typed "char*" in the SimStruct*-argument i suppose there is no such information on the C-side.
Whatever. Do you pros have an idea what I could or should do?
Thanks a lot!
Accepted Answer
More Answers (1)
marvin
on 6 Mar 2012
Categories
Find more on Write C Functions Callable from MATLAB (MEX Files) 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!