Simulink to C-Code, Problem with "Variable Transport Delay" (Access Violation)
이전 댓글 표시
Hello,
I have a problem embedding c-code which was generated by Matlab/Simulink in a VS C++ 2010 Express-project:
What I did:
- Use "Code Generation"/"Build" to create c-code (using grt.tlc)
- Create new c-project using Visual C++ 2010 Express
- copy all files to the project and include "mySimulinkFunction" in "myProgramm.c"
.
Sequence of execution (myProgramm.c):
main() {
mySimulinkFunction_initialize(1)
rtmSetTFinal(mySimulinkFunction_M,10)
while (t<tFinal){
mySimulinkFunction_output(1)
mySimulinkFunction_update(1)
}
}
.
This one worked fine for a simple Simulink-model. Now I have another simple model which contains a "variable transport delay" (Input->VTD->Output). Unfortunately, I can't execute this one, if I set the time-delay > 0. The error occurs in this line (looking at mySimulinkFunction.c):
if ((tMinusDelay <= tBuf[oldestIdx]))
...
with tMinusDelay > 0 and oldestIdx = 0 and tBuf = 0x00000000
There is an access violation while reading at position 0x0 (code 0xC0000005).
Can anyone help me figure out how to solve the problem? Because the code was generated automatically there are 2 possible solutions:
- I have to make some preparations before generate the code (in Simulink)
- My way of embedding the code is wrong and I have to do some rework there
Robert
PS: By the time this problem is solved, I also may need some help embedding "Simulink with Simscape" generated c-code in a vs-project. This one did not work at all (until now).
채택된 답변
추가 답변 (1개)
Robert
2011년 11월 28일
0 개 추천
댓글 수: 2
Kaustubha Govind
2011년 11월 28일
What version of MATLAB are you using? I see the following in R2011b:
rtmGetTFinal(S)-rtmGetT(S) > rtmGetT(S)*DBL_EPSILON
(The DBL_EPSILON is missing in what you pasted)
Also, how do you pass in tFinal? Do you observe the same issue when using the exe generated directly from Simulink? Perhaps there are macros/symbols defined in the generated makefile that are required. Try re-compiling your version of grt_main.c using the generated makefile.
Robert
2011년 12월 5일
카테고리
도움말 센터 및 File Exchange에서 General Applications에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!