I want to initialization code for one-time execute.
example)
main()
{
--initialization---
a = port input value (port input at power-on)
---------------------
while(1)
{
b = current port input value
if (a ~= b)
{~~~~~~~
}
}
}
how can i use to one time execute code?
解決済! 解決策の投稿を見る。
Hi byeongjinkim,
Simulink generated code has 3 main functions:
- step()
- initialize()
- terminate()
You need to inject the code into the initialize function because that is called only once in the beginning.
You can do this by using 2 standard (S-Function Builder and Initialize Function) Simulink blocks and one file from the Toolbox (mcd_s12zvm_user_copy_required_files.m)
The procedure is like this (an example is attached)
1: First you add the Initialize Function Block into your model
2: inside the Initialize function you add the S-Function Builder
3: inside the S-Function Builder you call your custom C-functions/C-files/C-headers
4: Use Toolbox Custom file copy to move all the custom files into the automatic generated folder before building the application
5: You build the application and check if the code was injected in the right place.
Please find attached an example - all you have to do is to:
- copy and replace the file: mcd_s12zvm_user_copy_required_files.m into c:\MCToolbox\mctbx_9s12zvm\mctbx_s12zvm\mctbx_s12zvm\mscripts\ folder
- add you own code into my_code function.
Hope this helps!
Daniel
Hi byeongjinkim,
Simulink generated code has 3 main functions:
- step()
- initialize()
- terminate()
You need to inject the code into the initialize function because that is called only once in the beginning.
You can do this by using 2 standard (S-Function Builder and Initialize Function) Simulink blocks and one file from the Toolbox (mcd_s12zvm_user_copy_required_files.m)
The procedure is like this (an example is attached)
1: First you add the Initialize Function Block into your model
2: inside the Initialize function you add the S-Function Builder
3: inside the S-Function Builder you call your custom C-functions/C-files/C-headers
4: Use Toolbox Custom file copy to move all the custom files into the automatic generated folder before building the application
5: You build the application and check if the code was injected in the right place.
Please find attached an example - all you have to do is to:
- copy and replace the file: mcd_s12zvm_user_copy_required_files.m into c:\MCToolbox\mctbx_9s12zvm\mctbx_s12zvm\mctbx_s12zvm\mscripts\ folder
- add you own code into my_code function.
Hope this helps!
Daniel
A build error occurs.
matlab version : 2015a
you attached '*.slx' file is 2016 version. so, not open.
i used '.mdl' file.
what is the command "rp_copy"?
this is not find matlab command.
Hello,
The build error indicates that the custom files were not copied inside the *_mcd_rtw folder where those are needed to be.The rp_copy is a toolbox function.Try the open the m file in the MATLAB editor and place a breakpoint and then build again. Does the breakpoint gets hit?If not then the file was not copied in the location expected by the toolbox.
Idid not know your MATLAB version and I exported the mdl in 2014 version just to be covered. It should works.
Best regards, Daniel
initialize function block is not supported in simulink of matlab version 2015a.
matlab command "help rp_copy" --> not find rp_copy
rp_copy is wrong. The exact command is "copyfile".
after corrected command, compile is right operating.
but, initialize function is wrong position.
i think, initialize function block is not operation in 2015a version.
Hi byeongjinkim,
You're right - it look the Simulink introduced the Simulink Block Initialize Function after 2015.
I think there is still a hope even in the older Matlabs - even if you will not have the block in Simulink.
Can you try this approach Integrate Custom C/C++ Code for Simulation - MATLAB & Simulink ?
Hope this will work for you!
Daniel