Validate is there is an s-function in the Simulink model with embedded coder
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Benjamin Couillard
el 10 de Ag. de 2023
Respondida: Ayush
el 21 de Ag. de 2023
We have 2 simulink models that we convert to C++. In one simulink model we have a non-inlineable S-function. The S-function in C++ performs dynamic allocation therefore we need to check whether or not the dynamic allocation at startup has been succesful. We do something like this
for (int i = 0; i < rtM->Sizes.numSFcns; i++) {
SimStruct* rts = rtM->childSfunctions[i];
if (ssGetErrorStatus(rts) != (NULL)) {
error = true;
//TODO : Implement strncpy_s
strncpy(infoMsg, ssGetErrorStatus(rts), 100);
}
}
However, in the 2nd model, we don't have an S-function and the above code fails. Is there a way to check whether or not there's an S-function in the Simulink model either using TLC or other options in embedded coder?
we cannot use the regular initialize C++ function as the function has no return arguments and we cannot know whether or not it has failed.
0 comentarios
Respuesta aceptada
Ayush
el 21 de Ag. de 2023
Yes, there is a way to check whether a Simulink model contains an S-function or not. Here's one possible approach using your TLC file:
1. Set a boolean variable `containsSFunction` to `false` initially.
2. Get the root SimStruct pointer using `ssGetRootSS(S)`.
3. Start a loop to traverse through the model hierarchy:
- Check if the current SimStruct has any registered S-function parameters using `ssGetNumSFcnParams(S)`.
- If the count of registered S-function parameters is greater than zero, set `containsSFunction` to `true` and break out of the loop.
- Get the parent SimStruct using `ssGetParentSS(S)`.
- Repeat the loop until reaching the top-level SimStruct or until `S` becomes `NULL`.
4. After the loop, check the value of `containsSFunction`: which can tell whether model has a S-function or not.
This algorithm traverses the model hierarchy starting from the root SimStruct and checks if any S-function parameters are registered at each level. If at least one S-function parameter is found, it indicates the presence of S-function blocks in the model.
To read more about above functions kindly view the following documentations:
Hope this helps!
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Simulink Coder en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!