www.gusucode.com > simulinkcoder 案例源码程序 matlab代码 > simulinkcoder/IntExtCodeIntoModelUsingStateflowExample.m
%% Integrate External C++ Code Into a Model Using Stateflow % This example shows how to use Stateflow(R) to integrate external C++ code % into a model. % Copyright 2015 The MathWorks, Inc. %% Open Model model='rtwdemo_sfcpp'; open_system(model); %% % To setup a C++ compiler, on the command line, enter |mex -setup|. %% Integrate C++ Code % % 1. Create C-style wrapper functions or access macros for each method called from the C action language. %% %Open example wrapper functions. filename=fullfile(matlabroot, 'toolbox', 'rtw', 'rtwdemos', 'custom_cpp_src', 'adder_cpp.cpp'); eval('edit(filename)'); clear filename; filename=fullfile(matlabroot, 'toolbox', 'rtw', 'rtwdemos', 'custom_cpp_src', 'adder_cpp.h'); eval('edit(filename)'); clear filename; %% % 2. On the Configuration Parameters dialog box *Code Generation > Custom Code* % pane, enter the S-Function source files and include directories. %% %Open Configuration Parameters dialog box slCfgPrmDlg(model,'Open'); slCfgPrmDlg(bdroot,'TurnToPage','Code Generation/Custom Code'); %% % 3. On the Configuration Parameters dialog box *Simulation Target* % pane, enter the S-Function source files and include directories. %% %Open Configuration Parameters dialog box slCfgPrmDlg(model,'Open'); slCfgPrmDlg(bdroot,'TurnToPage','Simulation Target'); %% Generate C++ Code % % On the Configuration Parameters dialog box *Code Generation* pane, set % *Language* to |C++|. To generate code, select *Build*. %% %Open Configuration Parameters dialog box slCfgPrmDlg(model,'Open'); slCfgPrmDlg(bdroot,'TurnToPage','Code Generation'); clear model; %% See Also % * <matlab:helpview(fullfile(docroot,'rtw','helptargets.map'),'rtw_language_support'); Language Considerations> % * <matlab:helpview(fullfile(docroot,'rtw','helptargets.map'),'rtw_cpp_limitations'); C++ Language Limitations> %% Close Model rtwdemoclean; close_system('rtwdemo_sfcpp',0);