Simulink with ZOS-API


Badge

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?


4 replies

Userlevel 6
Badge +2

Hi Chris

I moved your post to our ZOS-API category. The Code Exchange is a space where we share working solutions. Thank you!

Userlevel 6
Badge +2

Hi @Chris.Svec - I was able to obtain a Simulink license today so I can try to look into this. How are you importing the boilerplate/.NET assemblies into Simulink? I was trying to use the guidance here, but can’t seem to get it to work. Could that be where you are having trouble? We need the .NET assemblies in order to use the Matlab API commands. 

Badge

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.

Userlevel 6
Badge +2

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:

  1. Find the location of the ZOSAPI_NetHelper DLL within the Zemax Data folder (within Zemax\ZOS-API\Libraries).
  2. Use the .NET commands in Matlab to run the NetHelper DLL
  3. Initialize a connection to OpticStudio with the following command: ZOSAPI_NetHelper.ZOSAPI_Initializer.Initialize();
  4. Once connected, use the Matlab .NET interface to add the ZOSAPI_Interfaces and ZOSAPI assemblies.
  5. Now, initialize a connection to the API (TheConnection = ZOSAPI.ZOSAPI_Connection();)
  6. Next, create a new application (TheApplication = TheConnection.CreateNewApplication();)
  7. 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