Jump to content

Matlab-Simio Integration Issue


silverChariot

Recommended Posts

Hello everyone,

I met a problem during the use of 'CallMatlab' UserExtension process.

I am using Simio 8, MATLAB 2019a, and Windows 10, following the process introduced here: 

The problem is that when Simio is trying to call MATLAB function, some files are not registered and a certain dll cannot be found. Has anyone met such a problem before? Or is there anyway to write the CallMatlab myself?

image.thumb.png.1eb6fcd4dbb5e3026e1b578aa58c25d6.png

 

Thank you.

Shu

Link to comment
Share on other sites

This can be done by calling c# from simio and calling Matlab from c# with Simio API. Details can be found here: https://www.sciencedirect.com/science/article/pii/S1569190X16301356

And here: https://www.simio.com/resources/events/2018-User-Group-Meeting/presentations/API.pdf

 

But another problem is that how do we pause Simio until the MATLAB problem is finished? Any suggestions on this?

Link to comment
Share on other sites

  • 1 month later...
On 6/10/2020 at 11:10 PM, silverChariot said:

This can be done by calling c# from simio and calling Matlab from c# with Simio API. Details can be found here: https://www.sciencedirect.com/science/article/pii/S1569190X16301356

And here: https://www.simio.com/resources/events/2018-User-Group-Meeting/presentations/API.pdf

 

But another problem is that how do we pause Simio until the MATLAB problem is finished? Any suggestions on this?

To pause Simio can be implemented by add a breakpoint after the step that calls MATLAB function and continue the model after the MATLAB program is finished.

Link to comment
Share on other sites

The answer is no! If you call MATLAB via user generated MATLAB step simio will temporarily suspend till the outgoing token will return (with a value or not). If you add a breakpoint, simio will come to a "full stop". This means simio can not send any token to run/call matlab/codes. Most likely your problem is that the matlab user defined step does not work properly. If it works properly you need not to stop simio anyway. Try to locate the required files appropriately or check your visual studio edition etc.? I am not sure what is the problem but the .dll file can be outdated?

Link to comment
Share on other sites

9 minutes ago, gocken said:

The answer is no! If you call MATLAB via user generated MATLAB step simio will temporarily suspend till the outgoing token will return (with a value or not). If you add a breakpoint, simio will come to a "full stop". This means simio can not send any token to run/call matlab/codes. Most likely your problem is that the matlab user defined step does not work properly. If it works properly you need not to stop simio anyway. Try to locate the required files appropriately or check your visual studio edition etc.? I am not sure what is the problem but the .dll file can be outdated?

Hi gocken,

Thank you for your reply and your attention to this problem! The current method that adds a breakpoint after 'CallMATLAB' function works in my project. Before Simio runs MATLAB, Simio will send out needed data to SQL server and then call MATLAB function. MATLAB receives the data through the database, implements the algorithm, and writes the data into the database. The Simio program pauses at the step that Simio reads the MATLAB results from the database.

image.png.e775313c8e587416456080a7c8e1de1f.png

I have validated the .dll file with a simple MATLAB program that plays a music file and it works. Because the Simio API is a little complex, I just use the code from https://www.sciencedirect.com/science/article/pii/S1569190X16301356 and recomplie that to obtain the .dll. Through this example, I also found Simio continues running after the matlab file is executed

Otherwise, if I didn't pause the Simio after the MATLAB function is called, it generates error like this

image.thumb.png.0d390d18935b49742f32c7c9a1bcef2c.png

I also find that when the MATLAB program is running, it will open a MATLAB command window. If you don't pause, sometimes the MATLAB is still running when the command window exists, and Simio also begins to run before that window closes, and it will generate the same error like abov e. So I guess I have to pause it to let MATLAB program finishes.

I have attached the UserStep.cs that generates CallMatlab.dll. If you have any further idea on this problem, I am really glad to know that. Again, thanks for your reply and idea on this problem.

Shu

UserStep.cs

Link to comment
Share on other sites

Probably your Matlab version is different from the step. Please check your step's matlab version (from which forum  did you download your step) There is a step for Matlab 2017a in this discussion:

 

Link to comment
Share on other sites

  • 3 weeks later...
On 7/23/2020 at 5:28 PM, atuba said:

Probably your Matlab version is different from the step. Please check your step's matlab version (from which forum  did you download your step) There is a step for Matlab 2017a in this discussion:

 

Hi atuba,

Thank you for your friendly reply! I'm using Matlab 2019a and Simio12 in Windows10. I did try to use the CallMATLAB dll file online, but that required the corresponding software version and system version. I rewrite the code in C# that calls Matlab with cmd. The created dll file works but requires a pause after the CallMatlab step, and it was inconvenient but helped me obtains the experiment result. I will definitely try your suggestion next time the optimization-based simulation is needed.

Thank you!

Link to comment
Share on other sites

  • 1 month later...
×
×
  • Create New...