1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 % This file compiles the BSD socket
interface for Simulink.
5 % On
Windows, it requires the Microsoft compiler
7 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8 %
Note: We set the
number of outputs to 1024, since matlab requires the
9 % size of output arrays to be fixed.
11 % - change the entry y4[1024] in the assignment of '
funSpe' below,
12 % - change
NDBLMAX=1024 in the file exchangeDoublesWithSocket.m,
14 % - change the entry #define
NDBLMAX 1024 in the file lib/defines.h
16 % Then, compile the matlab files by opening a development console.
17 % On
Windows, this can be done by double-clicking the file
18 %
bcvtb/bin/setDevelopmentEnvironment.bat. On Linux
and Mac,
19 % this can be done by starting a terminal window
and typing
20 %
source bin/setDevelopmentEnvironment.sh
21 % from the BCVTB root directory. Next, type
25 % This will recompile all
required files.
28 % Compile matlab library
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 LIBBCVTB='../util/libbcvtb.dylib';
37 LIBBCVTB='../util/libbcvtb.so';
42 'includepath', './..', ...
43 'mfilename', '
bcvtb.m')
45 % -------------------------------------------------------------------
46 % Check
if Simulink is installed on this system. If Simulink is
51 disp('Simulink is not installed on this computer.')
52 disp('The Simulink library will not be compiled.')
58 def=legacy_code('initialize');
60 def.HeaderFiles={
'simulinkSocket.h'};
61 def.SampleTime =
'inherited';
63 funNam = {
'establishBSDSocket',
'exchangeDoublesWithBSDSocket',
'closeBSDSocket'};
64 funSpe = {
'int16 y1 = establishBSDSocket(int16 u1[1])', ...
65 'int16 y1 = exchangeDoublesWithBSDSocket(int16 u1[1], int16 u2[1], int16 y2[1], int16 u3[1], double u4[1], double u5[], double y3[1], double y4[1024])', ...
66 'int16 y1 = closeBSDSocket(int16 u1[1], int16 u2[1])'};
72 disp(
'*** Generating mex file')
73 legacy_code('sfcn_cmex_generate',
def)
74 disp('*** Compiling code')
75 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76 %%%%%%%%%%% fix from Mathworks (email from 2/7/08)
78 %% FSCHANGE is a Mathworks internal
function that is used
79 %% for troubleshooting purposes. It takes the name of a directory
80 %% as an input
and forces the MATLAB path manager to
81 %% recheck the contents of the directory to check for
82 %%
new (or deleted) files. When an empty
string is
83 %% passed as an input the entire path is rechecked.
84 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89 legacy_code('compile',
def, {
'../util/bcvtb.lib',
'-I../util',
'-I..'})
91 % Compilation
for Mac OS X
and Linux
92 disp(
'*** Compiling MATLAB interface for Mac OS X or Linux')
94 legacy_code(
'compile',
def, {
'-lxml2',
'-I..',
'-L../util',
'-lbcvtb'})
97 disp(
'*** Error when compiling MATLAB interface ***')
98 disp(getReport(
ME, 'extended'))
103 disp('*** Returned from legacy_code')
105 disp('*** Generating Simulink block')
109 disp('*** Error when generating Simulink interface ***')
110 disp(getReport(ME, 'extended'))
115 %
delete the files that we no longer need
exchanges data with the BCVTB The input arguments are
getenv('BCVTB_OS' deblank()
loadlibrary(LIBBCVTB,... 'matlabSocket.h',... 'includepath', './..',... 'mfilename', 'bcvtb.m')%-------------------------------------------------------------------%Check if Simulink is installed on this system.If Simulink is%is not installed
function sockfd will be a positive integer for the socket file descriptor In case of error
elseif(strcmp(os,'mac')) LIBBCVTB
FSCHANGE is a Mathworks internal function that is used for troubleshooting purposes It takes the name of a directory as an input and forces the MATLAB path manager to recheck the contents of the directory to check for new(or deleted) files.When an empty string is%%passed as an input the entire path is rechecked.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Compilation for Windows if(strcmp(os
This file compiles the BSD socket interface for Simulink It is called by ant On it requires the Microsoft compiler Note
end Establish the socket connection if and(libisloaded(BCVTBLIB),(status==1)) sockfd
static void XMLCALL end(void *data, const char *el)
Call back functions that will be used by the expat xml parser.
This file compiles the BSD socket interface for Simulink It is called by ant On it requires the Microsoft compiler since matlab requires the size of output arrays to be fixed If more elements are required
if(strcmp(os,'windows'))%have Windows LIBBCVTB
This file compiles the BSD socket interface for Simulink It is called by ant On Windows
exit continue and compile simulink libraries retVal
#define NDBLMAX
Maximum number of double values that can be exchanged by Simulink.
function[retVal, flaRea, simTimRea, dblValRea]
function if the BCVTB library can be loaded and if sockfd is not a negative number
FSCHANGE is a Mathworks internal function that is used for troubleshooting purposes It takes the name of a directory as an input and forces the MATLAB path manager to recheck the contents of the directory to check for windows have Windows c
int source
flag for function /c getepvariables 0=EnergyPlus, 1=Ptolemy
disp('***Generating mex file') legacy_code('sfcn_cmex_generate'
if strcmp(retVal, '') disp('Simulink is not installed on this computer.') disp('The Simulink library will not be compiled.') else makeSBlock