Discussion:
legacy code tool with complex c functions
(too old to reply)
Laura
2010-03-31 17:13:04 UTC
Permalink
Hello,

I have a fairly complex c function that I need to call in simulink using the legacy code tool. Specifically, this function returns multiple outputs by expedient of passing in a structure variable by reference. Within the function, the values in this structure are updated. When I use this function within a c library, the calling program then grabs the updated values to finish whatever processing is required.

Now, I'd like to be able to call this function from a simulink model. However, according to the documentation at "http://www.mathworks.com/access/helpdesk/help/toolbox/simulink/sfg/bq4g1es-1.html#bq4g1es-6" on how to do so, I cannot actually do this because the function must not change the value of of input arguments, and that is what I end up doing. Nor can I modify my function to return a reference to the output structure, since the same rules state I can't have a function return a pointer.

Now, I don't see anything that indicates I can't simply return the output structure directly, but I can't seem to find any directions on how this is actually done. Can someone point me to an example? For that matter, are there any examples of using the legacy code tool with pointers to structures as inputs to a function?

Thanks,
Laura
Christian
2016-12-08 15:54:03 UTC
Permalink
Well, I can see this question rather old, but still I would be very interested in a answer as well.
Especially if this answer qould solve the problem of returning multiple return values from a single function.

Currently I am looking into a solution, that somewhat interacts similar to a mexFunction.
e.g. [int y1, int y2] = fun(int u1, int u2)

I stumbled upon an example that mentioned following struture:

Declared in mex.h (line 141+ in R2014b)

void mexFunction (
int nlhs, /* number of expected outputs */
mxArray *plhs[], /* array of pointers to output arguments */
int nrhs, /* number of inputs */
mxArray *prhs[], /* array of pointers to input arguments */
);


If this could be implemented with the support of the legacy_code tool, it would be fantastic, but I fear I mistunderstood something. The problem should be 'mxArray' since it isn't a supported Datatype as far as I can see.

Still, I would be happy if someone had a solution that would help me to receive multiple values from one called function / method by a wrapper function utilized with the legacy_code tool.


With best regards,
Christian
Post by Laura
Hello,
I have a fairly complex c function that I need to call in simulink using the legacy code tool. Specifically, this function returns multiple outputs by expedient of passing in a structure variable by reference. Within the function, the values in this structure are updated. When I use this function within a c library, the calling program then grabs the updated values to finish whatever processing is required.
Now, I'd like to be able to call this function from a simulink model. However, according to the documentation at "http://www.mathworks.com/access/helpdesk/help/toolbox/simulink/sfg/bq4g1es-1.html#bq4g1es-6" on how to do so, I cannot actually do this because the function must not change the value of of input arguments, and that is what I end up doing. Nor can I modify my function to return a reference to the output structure, since the same rules state I can't have a function return a pointer.
Now, I don't see anything that indicates I can't simply return the output structure directly, but I can't seem to find any directions on how this is actually done. Can someone point me to an example? For that matter, are there any examples of using the legacy code tool with pointers to structures as inputs to a function?
Thanks,
Laura
Salah Abdul Gafoor
2022-11-21 09:34:04 UTC
Permalink
Post by Christian
Well, I can see this question rather old, but still I would be very interested in a answer as well.
Especially if this answer qould solve the problem of returning multiple return values from a single function.
Currently I am looking into a solution, that somewhat interacts similar to a mexFunction.
e.g. [int y1, int y2] = fun(int u1, int u2)
Declared in mex.h (line 141+ in R2014b)
void mexFunction (
int nlhs, /* number of expected outputs */
mxArray *plhs[], /* array of pointers to output arguments */
int nrhs, /* number of inputs */
mxArray *prhs[], /* array of pointers to input arguments */
);
If this could be implemented with the support of the legacy_code tool, it would be fantastic, but I fear I mistunderstood something. The problem should be 'mxArray' since it isn't a supported Datatype as far as I can see.
Still, I would be happy if someone had a solution that would help me to receive multiple values from one called function / method by a wrapper function utilized with the legacy_code tool.
With best regards,
Christian
Post by Laura
Hello,
I have a fairly complex c function that I need to call in simulink using the legacy code tool. Specifically, this function returns multiple outputs by expedient of passing in a structure variable by reference. Within the function, the values in this structure are updated. When I use this function within a c library, the calling program then grabs the updated values to finish whatever processing is required.
Now, I'd like to be able to call this function from a simulink model. However, according to the documentation at "http://www.mathworks.com/access/helpdesk/help/toolbox/simulink/sfg/bq4g1es-1.html#bq4g1es-6" on how to do so, I cannot actually do this because the function must not change the value of of input arguments, and that is what I end up doing. Nor can I modify my function to return a reference to the output structure, since the same rules state I can't have a function return a pointer.
Now, I don't see anything that indicates I can't simply return the output structure directly, but I can't seem to find any directions on how this is actually done. Can someone point me to an example? For that matter, are there any examples of using the legacy code tool with pointers to structures as inputs to a function?
Thanks,
Laura
Does anybody got a solution for this?
Salah Abdul Gafoor
2022-11-21 09:35:47 UTC
Permalink
Post by Christian
Well, I can see this question rather old, but still I would be very interested in a answer as well.
Especially if this answer qould solve the problem of returning multiple return values from a single function.
Currently I am looking into a solution, that somewhat interacts similar to a mexFunction.
e.g. [int y1, int y2] = fun(int u1, int u2)
Declared in mex.h (line 141+ in R2014b)
void mexFunction (
int nlhs, /* number of expected outputs */
mxArray *plhs[], /* array of pointers to output arguments */
int nrhs, /* number of inputs */
mxArray *prhs[], /* array of pointers to input arguments */
);
If this could be implemented with the support of the legacy_code tool, it would be fantastic, but I fear I mistunderstood something. The problem should be 'mxArray' since it isn't a supported Datatype as far as I can see.
Still, I would be happy if someone had a solution that would help me to receive multiple values from one called function / method by a wrapper function utilized with the legacy_code tool.
With best regards,
Christian
Post by Laura
Hello,
I have a fairly complex c function that I need to call in simulink using the legacy code tool. Specifically, this function returns multiple outputs by expedient of passing in a structure variable by reference. Within the function, the values in this structure are updated. When I use this function within a c library, the calling program then grabs the updated values to finish whatever processing is required.
Now, I'd like to be able to call this function from a simulink model. However, according to the documentation at "http://www.mathworks.com/access/helpdesk/help/toolbox/simulink/sfg/bq4g1es-1.html#bq4g1es-6" on how to do so, I cannot actually do this because the function must not change the value of of input arguments, and that is what I end up doing. Nor can I modify my function to return a reference to the output structure, since the same rules state I can't have a function return a pointer.
Now, I don't see anything that indicates I can't simply return the output structure directly, but I can't seem to find any directions on how this is actually done. Can someone point me to an example? For that matter, are there any examples of using the legacy code tool with pointers to structures as inputs to a function?
Thanks,
Laura
Does anybody get a solution here?

Loading...