I created a C function in test.c
#include <stdio.h>
int Test()
{
FILE * fp = fopen("C:\\workspace\\test.txt", "rw");
fprintf(fp, "test hello world");
fclose(fp);
return 10;
}
And I defined a state in stateflow of simulink. I used
en: Test();
I specified the file in both Tools->Open Simulation Target->Custom Code->Include List of additional and Include Custom C Code in generated (using absolute path and file name) When I tried to run the model, I got parser error: en: Test(); ^ Function named 'Test' is not a Stateflow Function.
What should I do?
Got it done by my own. In the "Include Custom C Code in generated:"->Header file tab, I should specify my header file as
#include "test.h"
instead of
test.h
And c file should be specified in "Include list of additional"->Source files as
test.c
Adding reference to an online example for adding custom C code to Stateflow that will help other users who run into similar issues: http://www.mathworks.com/support/solutions/en/data/1-1727V/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With