How to hide code in S-Function block in simulink?

Using legacy tool and minGW compiler, i have compiled my c code (.c) and header file as well (.h). In result of same i get S-Function Source file (.c) and mex file.
Using mex file, i have created a S-Function block in MATLAB simulink.
Now as per my requirements, i wanted to hide the S-Function Source file (.c) which can be seen via S-Function block in MATLAB simulink.
ultimately my requirement is to, hide the code from user.
Saying all of above, i wanted to know:
  1. Am i able to hide code sing S-Function block in simulink?
  2. If Answer to first queston is yes, then how to do so?

 Risposta accettata

You have your source code (in .c or .m or Fortran), compile them into a .mex (or .dll) file using mex() command, then you can use the S-function block in Simulink to use this function.
When you deploy it to other users, you can just copy the .mex or .dll file without including the source code. The user will be able to use the S-function but won't be able to view your source code.

4 Commenti

Thanks Fangjun Jiang for your reply.
There are few more queries regarding above thread is,
We are working on one part of final code (not full code). As said earlier we will generate .mex file and same will be provided to user (who will generate/prepare the final code). So user will generate final code for application. Saying this,
  1. Our requirement is that, user should able to get machine code for our system but should not able to generate/access/see source code (.c) and header files(.h)
Is it possible for user to do so, by giving only .mex file?
You can develop your core algorithms in C functions and provide a header file. Then you compile it to a library file (.lib). Your S-function would be a wrapper to call those functions. As long as you provie the library file and header file (just function prototype declation, no algorithms), the user would be able to run simulation and generate code. To build the generated C code for the end target though, you have to make sure the C compiler is the same and the target is the same.
Ok.
The .lib file you are talking about is to generated in MATLAB or Code composer studio?
If it is in MALTAB then how to do so?
And if from code composer studio then, will .lib file from code composer studio will work with MATLAB?
Thanks in advance.
The .lib file is compiled by a C compiler, such as MS Visual C. The C language S-function is still C code. It can use the functions in the .lib file. The header file is to tell you what functions and their calling syntax.
If you generate the C code and want to use it for embedded control, make sure you provide the .lib file compiled by that embedded C compiler.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Simulink Coder in Centro assistenza e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by