C code to S function tutorials

3 ビュー (過去 30 日間)
Paul
Paul 2014 年 1 月 20 日
コメント済み: Kaustubha Govind 2014 年 3 月 25 日
Hi does anyone have any good tutorial examples that i can use to get to grips with using the legacy code toolbox ?
I have some C code and I want to learn effective ways to to turn it into S code to put in my simulink model. This model will eventually be working on a real time machine.
I have been told that the legacy code tool box is my best candidate. Does anyone have any informative tutorials that might help ?

採用された回答

Suneesh
Suneesh 2014 年 1 月 20 日
編集済み: Suneesh 2014 年 1 月 20 日
There are several examples in Simulink documentation for the legacy code tool. Look under "Custom Blocks with S-functions, System Objects and Legacy Code Tool" in:
Do consider the S-Functions mentioned in Bruno's answer as well and choose the solution which seems more suitable for you.

その他の回答 (2 件)

Bruno Pop-Stefanov
Bruno Pop-Stefanov 2014 年 1 月 20 日
編集済み: Bruno Pop-Stefanov 2014 年 1 月 20 日
I am not familiar with legacy_tool but there is another way to create an S-Function from C code.
You can call a binary from a Simulink model using MEX files. A MEX file is a binary compiled from C, C++ or Fortran code that is properly formatted to work with MATLAB code. Here is a short introduction:
and here is good starting point in the MATLAB documentation:

Paul
Paul 2014 年 1 月 22 日
Thanks guys
I used the example to create an s function but then attempted to use the model wizard to compile the simulink model into my target machine but it comes up wth the error :
S-function 'ex_sfun_doubleit' in 'untitled/ex_sfun_doubleit' specifies option SS_OPTION_SFUNCTION_INLINED_FOR_RTW however a 'ex_sfun_doubleit.tlc' file could not be located in the current working directory, the S-function directory 'C:\Users\HIL\Documents\MATLAB\LEGACY_TEST', or the directory 'C:\Users\HIL\Documents\MATLAB\LEGACY_TEST\tlc_c'
can some one explain ?
  1 件のコメント
Kaustubha Govind
Kaustubha Govind 2014 年 3 月 25 日
As the documentation states, you also need to run legacy_code('sfcn_tlc_generate', def) in order to generate the ex_sfun_doubleit.tlc file.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeManual Performance Optimization についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by