silverChariot Posted June 8, 2020 Share Posted June 8, 2020 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? Thank you. Shu Link to comment Share on other sites More sharing options...
silverChariot Posted June 11, 2020 Author Share Posted June 11, 2020 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 More sharing options...
silverChariot Posted July 20, 2020 Author Share Posted July 20, 2020 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 More sharing options...
gocken Posted July 21, 2020 Share Posted July 21, 2020 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 More sharing options...
silverChariot Posted July 21, 2020 Author Share Posted July 21, 2020 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. 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 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 More sharing options...
atuba Posted July 23, 2020 Share Posted July 23, 2020 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 More sharing options...
silverChariot Posted August 10, 2020 Author Share Posted August 10, 2020 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 More sharing options...
LindaP Posted September 30, 2020 Share Posted September 30, 2020 Hi Silver, Could you share the modified CallMATLAB ? I would like to try it on version12 Link to comment Share on other sites More sharing options...
silverChariot Posted October 8, 2020 Author Share Posted October 8, 2020 On 9/30/2020 at 4:43 PM, LindaP said: Hi Silver, Could you share the modified CallMATLAB ? I would like to try it on version12 Sure, here you are. You can try this one. The inputs are the function name without .m and the function address. CallMATLAB2.dll 1 Link to comment Share on other sites More sharing options...
Recommended Posts