필터 지우기
필터 지우기

How to pass a string parameter to a Simulink S-function using the S-Function Builder

조회 수: 46 (최근 30일)
Hi all,
I've created a Simulink S function that calls a DLL file containing the model functions in C using the S-Function Builder in Simulink 2021a
However, during the initialization of this model, I need to pass a string that points to a JSON file containing all the model parameters. Currently, I've hard-coded the file path for testing, and it works. However, I would like to be able to pass this as a parameter.
// TODO: make params_file_path a parameter
const char* params_file_path = "default_parameters.json";
params = load_parameters(params_file_path);
When I click on the parameter data types in the S-Function Builder, I see options for double, single, int8, int16, int32, uint8, uint16, uint32, and boolean, but I do not see an option for strings or characters.
I assume that I will need to manually modify the autogenerated wrapper.c file, but I would appreciate some guidance on how to do this.
Regards,

채택된 답변

Sarthak
Sarthak 2023년 8월 21일
Hi Marco,
As per my understanding, the data type of the ports and parameters for the S-Function, can only be Simulink built-in numeric data types. You can try to create a character array and pass the parameter value as you have done since there is no direct option for a string datatype.
const char* params_file_path = "default_parameters.json";
params = load_parameters(params_file_path);
There can also be fixdt data types and bus types for ports. The "int64" and "uint64" data types are not supported for parameters as mentioned in the following documentation.
  댓글 수: 1
Marco Furlan
Marco Furlan 2023년 8월 30일
편집: Marco Furlan 2023년 8월 30일
Hi Sarthak,
Thanks for your answer. I also found very useful the answer to this other question:
I was able to pass in the full path to the file using a uint8 array of characters. I just had to convert the string to uint8 usign the uint8 function.
Then, inside the S-Funcition Builder Editor for C code, I convert it back to a character array:
const char* params_file_path_char = params_file_path;

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink Functions에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by