• Re: legacy code tool with complex c functions

    From Salah Abdul Gafoor@21:1/5 to Christian on Mon Nov 21 01:35:47 2022
    On Thursday, 8 December 2016 at 21:24:07 UTC+5:30, Christian wrote:
    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


    "Laura" wrote in message <hovvr0$m1t$1...@fred.mathworks.com>...
    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?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Salah Abdul Gafoor@21:1/5 to Christian on Mon Nov 21 01:34:04 2022
    On Thursday, 8 December 2016 at 21:24:07 UTC+5:30, Christian wrote:
    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


    "Laura" wrote in message <hovvr0$m1t$1...@fred.mathworks.com>...
    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?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)