- It depends on where this function needs to be called from. Can you elaborate on how the function needs to be used?
- For structure inputs/outputs, you need to use bus signals.
- I don't know that you see errors using 'int' - could you please paste the offending code and the error message.
- Again, please paste the offending code and the error message.
Using C code in s-functions
2 次查看(过去 30 天)
显示 更早的评论
Hi everyone;
I have a c code which need to be used in simulink block. The c code is working well, but I could not build a proper s-function with it. There are several errors;
1- In my c code there is a function other than main, How it should be implement in s function?
2- There is a struct which occurs a trouble also.
3- Does normal c syntax problem for matlab 'int' cause a error
4- Although I gave an initial value for my variables s function builder always wants a Ivalue error
If you help me I appreciate, I could not find a proper source yet. Thank you
0 个评论
回答(3 个)
Kaustubha Govind
2013-3-5
2 个评论
Kaustubha Govind
2013-3-7
Ufuk: At this point, your code is not even in an S-function, but is a regular C-executable with a main(). You probably need to get help from a more C/C++ forum than a MATLAB/Simulink forum. It's hard for me to tell, because it's not clear where symbols like CLOCAL, and types like 'termios' are being defined. Please follow basic C rules and make sure that you can compile your code outside of MATLAB.
Dan
2013-7-9
You declare to include some header files
#include fcntl.h #include errno.h #include signal.h #include stdlib.h #include termios.h #include unistd.h #include stdio.h #include string.h
But the Matlab/Simlink coder may fail to find these files. Consequently, when your codes refer to the variables predefined in these header, the compiler reports errors. Please see the Simulink 7 Writing S-Functions reference, you may need to define LIB_PATH, etc to have Matlab/Simulink to know where there header files are
0 个评论
Ahmet Tuna
2017-5-26
Hey,
I have the same problem. I have C code, in this code i am communicating with serial port. The C code is working. I have made the changes for mexFunction. When i gave the command mex serialPort.c it also works and compiles. But when i use the function the serial does not open. Do you have a solution?
best regards
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Event Functions 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!