Applicable Versions | NetSim Standard | NetSim Pro |
Applicable Release | v13.1 |
NetSim User Manual section 10.3.1 explains how NetSim can be interfaced with MATLAB using the NetSim-MATLAB Socket Interface.
To trigger a call to MATLAB whenever an event occurs in NetSim, for example, when a packet arrives at the network layer, a call to the netsim_matlab_send_ascii_command() function can be made to send a command to MATLAB. The command could be for calling a MATLAB function, executing a .m file, etc.
If a series of calls are to be made each time an event occurs in NetSim, for example,
- pass parameters from NetSim to an algorithm in MATLAB,
- get the output values from MATLAB and
- use the MATLAB output to modify simulation variables in NetSim
then a dedicated function can be written in NetSim which contains calls to functions such as
- netsim_matlab_send_ascii_command()
- netsim_matlab_get_value( )
to send parameters, execute commands, read output values, etc.
This function can be called each time an event occurs in NetSim.
On the other hand, custom timer events can also be created to trigger calls to MATLAB. These events can be added whenever an associated event occurs, e.g., whenever a packet arrives.
Related Examples:
- In section 10.3.1.2 of the NetSim User Manual, a dedicated fn_netsim_matlab_run() function is defined when involves calls to MATLAB for executing commands and getting values from the workspace. This function is called whenever fading power is to be calculated in NetSim.
- In the RPL DoDAG Visualization project, the function fn_netsim_matlab_DODDAG_run() is created which handles calls to MATLAB executing commands to send variables to MATLAB workspace and call a MATLAB function in an M-Script file. This function is called whenever there is a change in the DoDAG structure as part of the RPL protocol in the NetSim IoT module.
These are general guidelines and some code customization may be required depending on each use case. Users can contact our technical support with details on their requirements for specific suggestions.