0
votes

Here is what the ideal goal is.

We have a simulink model and while it is running we want all the outcome values to be sent to our vb.net application.

I think I have found a few ways but prior to diving in would like some input. I havent used matlab or simulink in the past which is making this harder than it is.

There is a COM object for matlab but that doesnt allow for real time access to variables while simulink is running. Simulink only dumps its data to matlab after it is completed.

Option #1: Callback? I have been reading and it seems I am able to add a callback to the blocks so as the values is sent to matlab based on a timer. I would then have to make constant calls to matlab from vb to get these values. This doesnt seem efficient and would likely take up to much resources with simulnk running at the same time? How do I get data from a Simulink block into a MATLAB GUI?

Option #2: I found a 'Simulink Coder' on the mathworks website and seems like the ideal solution but would like some clarification if anyone here has used it. I have requested a trial but still have a few more hoops to jump through before I get it.

It seems to me like the coder would take the simulink model and create the algorithm in C/C++ code? Does this then mean I can create a C application and use that code as a source? So instead of running simulink with my application I would just run the code and input the parameters to give us the output variable?

I have also been reading some info about matlab outputing DLL's or mux? so can be used with .net applications?

Any input/opinions are appreciated :)

1

1 Answers

2
votes

There really isn't a simple answer to your question, with the best/right approach coming down to what functionality you require.

Firstly, regarding Simulink Coder: yes, it will convert a Simulink model to C code, at which point you can use that C code in the same way as any other piece of C code that you might write.

At that point you will no longer be using Simulink, and do not require a license for it. Which may be useful for deploying your application.

But there are restrictions. You are (generally) limited to fixed-step solvers. You cannot convert M-code S-Functions. You cannot have coder.extrinsic functions define in MATLAB Function blocs. You can only change parameters and model inputs. You cannot change the topology, i.e. number and interconnection of blocks (without regenerating the code). See Coder Limitations for a somewhat more comprehensive list.

Using run time objects (mention in the link you provide) isn't ideal, and sometimes doesn't scale particularly well (i.e. may be problematic if you have many signals that you want to view), but is really the only way to get data out of a model during simulation. (There are event_listeners that can be attached to blocks, but that doesn't scale well either.)

Note that the COM limitation you mention is not a limitation of Simulink. For efficiency reasons, Simulink only dumps data when the model is paused or stopped. That has nothing to do with the MATLAB-COM API itself.

You also mention MATLAB generating DLL's and mux [presumably you mean mex here]. Note that there are different code generation mechanisms from MATLAB (i.e. m-code) than from Simulink. Only Simulink Coder will be of use to you, not MATLAB Coder, or MATLAB Compiler. Mex (assuming that's what you meant) is the mechanism for calling compiled code from MATLAB, and is not going to have anything to do with what you're asking here.