I have constructed successful interfaces with the ZOS-API using MATLAB, but there’s a larger system model that I’m now integrating into Simulink and I’m running into import errors because Simulink doesn’t seem to like the data structure. Has anyone tackled Simulink interfacing?
Hi Chris
I moved your post to our ZOS-API category. The Code Exchange is a space where we share working solutions. Thank you!
Hi
Hi, Allie. Thanks so much for taking time to look into this. My colleague, Ken Venzant is also in contact with your group to try to resolve this issue. He has the real low-down on what the problem is. There’s something mentioned in his communication with your group about using the “headless” version of ZEMAX to possibly eliminate the conflicts.
Hi Chris,
Thanks for the information. I didn’t realize you were working with Ken! Yes I mentioned to him that it would be good to use the Matlab Standalone Application version to ensure that Simulink opens OpticStudio and connects to it. As long as Simulink can perform the same steps as the Matlab boilerplate, it should be able to make the connection to OpticStudio. The steps are essentially this:
- Find the location of the ZOSAPI_NetHelper DLL within the Zemax Data folder (within Zemax\ZOS-API\Libraries).
- Use the .NET commands in Matlab to run the NetHelper DLL
- Initialize a connection to OpticStudio with the following command:
ZOSAPI_NetHelper.ZOSAPI_Initializer.Initialize();
- Once connected, use the Matlab .NET interface to add the ZOSAPI_Interfaces and ZOSAPI assemblies.
- Now, initialize a connection to the API (
TheConnection = ZOSAPI.ZOSAPI_Connection();
) - Next, create a new application (
TheApplication = TheConnection.CreateNewApplication();
) - Run commands through a system within TheApplication
My recommendation would be to make sure the generic boilerplate runs. Ensure TheApplication returns a variable of type (1x1 ZOSAPI_Application) and that you can run a basic command. An example would be TheApplication.PrimarySystem.LDE.NumberOfSurfaces
. This command will return the number of surfaces in the Lens Data Editor of a blank system (3). As long as you get a numeric value returned with that command, you can be sure the API has been properly initialized within Simulink.
By the way - the boilerplate for the Mathematica template has the same set of steps as for Matlab, but is laid out linearly instead of with functions. It might help you to see how the connection is initialized in that version, so I’m pasting it below:
Let me know if you have any other comments or questions here or within the case I have ongoing with Ken . Have a great holiday weekend!
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.