Getting started with Co-Simulation
Previous (setup_Python) | Back to Start | Next (run_sim)
Setting up MATLAB
You need four files in order to set up and running a co-simulation with MATLAB:
- idalibN.h
- idalibN.dll
- libzmq-mt-4_3_4.dll
- libsodium.dll
Make sure that you have the 64-bit version of the above files.
Creating a channel
This is done using the function CreateStorage which requires which requires 6 arguments: pointer to channel name, number of variables passed on the channel, number of clients linked to the same variable, extrapolation time, whether to interpolate the variables or not, and whether there is an opc server or not. I what follows an example is shown for the channel that will be reading the data from the “Export” in ICE
Channel_ptr = libpointer('cstring',Channel_name);
nVar = 1;
nSync = 1;
dTExtrap = 0;
VarInterp = 0;
VarInterp_ptr = libpointer('doublePtr',VarInterp);
opc = 0;
[hStore1]=calllib('idalibN','CreateStorage',Channel_ptr,nVar,nSync,dTExtrap,VarInterp_ptr,opc);
The second channel that will communicate with the “Import” in ICE can be created and opened in the same way, but takes the following parameters
Channel2_ptr = libpointer('cstring',Channel2_name);
nVar = 1;
nSync = 1;
dTExtrap = 125;
VarInterp = 0;
VarInterp_ptr = libpointer('doublePtr',VarInterp);
Retrieve and send data
To retrieve and send data now, all that needs to be done is to use the functions StoreData and RetrieveStoredData
calllib('idalibN','CloseStorage',hStore1);
unloadlibrary('idalibN');