To list the names of simulink models using JavaScript one must use the Simulink API (Application Programming interface) with the help of Node.js. Below is an example of how to do it:
index.tsx917 chars33 linesThe above code does the following steps:
Importing Required Libraries and Initializing Variables
path module is used to help with working with file pathssimulink-connection is the Node.js Simulink API library that provides the capability to connect and work with Simulinksimulink is an instance of Simulink class that we will use to connect to SimulinkmodelPath is the path for the directory containing the simulink models that we want to obtainSetting Configuration Options
simulink instance that we have created above. These options are such as to specify the host and port number to which we want to connect our Simulink instance.Connecting to Simulink
connect() function on our simulink instanceFetching List of Models
getModels() function to fetch the list of models, which will return a Promise with the list of models, which we store in models array.Finally Disconnecting from Simulink
disconnect() function of our simulink instance.The above example code can also be extended further to do any other additional stuff with the fetched Simulink model list.
gistlibby LogSnag