NetSim can interface with third-party tools such as MATLAB, SUMO, Wireshark, Python, etc. In this article, we focus on how to interface NetSim and MATLAB.


Applicable Version   NetSim Standard  NetSim Pro


Applicable Release v13.0 / v13.1 / v13.2


Steps involved in interfacing with MATLAB


Step 1: Create a scenario in NetSim, model application.

Step 2: Modifiy and compile code in NetSim to interface with MATLAB using the inbuilt API. 




Note

Please refer following section of NetSim User Manual (v13.1)
a. Chapter 9 Writing Custom Code in NetSim
b. Chapter 10.3.1 NetSim-MATLAB Socket Interface


  • MATLAB socket initialisation:

    • API: netsim_matlab_interface_configure(char* appPath);

    • Call this function in the initialisation of the protocol that you need to interface with.

    • Example: If you are interfacing TCP with MATLAB then call the API in  fn_NetSim_TCP_init()


  • Interaction with MATLAB during run time NetSim simulation

    • API:

      • netsim_matlab_send_ascii_command(char* format, ...);

      • netsim_matlab_get_value(char* out, int outLen, char* name, char* type);

    • Call these API to interact with MATLAB to send commands and get the value from MATLAB after performing MATLAB operation. Usually, this function is called in the ‘run’ function of a protocol

    • Example: If you need to perform a simple math calculation a+b using MATLAB, where ‘a’ and ‘b’ are the variables of NetSim in TCP protocol then

      • Using netsim_matlab_send_ascii_command() perform  ‘c=a+b’ by passing the command

      • Using netsim_matlab_get_value() get the output of the operation performed in MATLAB. Here C is the output variable.


  • Termination of MATLAB socket interface

  • API: netsim_matlab_interface_close(); 

  • Call this API in the finish function of the protocol you initiated. This function will terminate the MATLAB socket interface and close all the instances of MATLAB.




Step 3: Upon running the NetSim scenario, you need to run MATLAB Interface from the Design window of NetSim. I.e. Go to NetSim Design Window > Options > Open MATLAB Interface


Step 4: You will observe that initially, MATLAB gets initialised, sooner MATLAB starts interacting with NetSim, and at the end of simulation MATLAB terminates.



Related Articles: