With variable sized signals in Simulink, how can TLC code access the "CurrentDimensions" of a variable sized signal?

조회 수: 3 (최근 30일)
For context, imagine an S-function that outputs a variable-sized signal. How can code be generated that specifies not only the signal's value, but also its current dimensions (since they are variable).
TLC library functions like LibBlockOutputSignalDimensions only return the numeric values for the signal's maximum dimensions (e.g. [1 16]). Variable-sized signals have block state variables that hold the "actual" dimensions. How can we gain access to the C language variable names that hold this state?
For example, here is the automatically generated C code struct that holds the block states I want to access:
<< in the ModelName.h file >>
/* Block states (auto storage) for system '<Root>' */
typedef struct
{
int32_T MyBlock_DIMS1[2]; /* '<Root>/MyBlock' */
}
DW_ModelName_T;
<< in the ModelName.c file >>
/* Block states (auto storage) */
DW_ModelName_T ModelName_DW;
So for this example, I'm looking for TLC syntax that emits something similar to ModelName_DW.MyBlock_DIMS1 into my generated code.

답변 (1개)

Prashant Arora
Prashant Arora 2017년 4월 26일
Hi Keith,
Have you tried using LibBlockInputSignalWidth or LibBlockInputSignalSymbolicWidth?
I have not tried it myself, but it does seem to do the expected.
  댓글 수: 1
Keith Lundberg
Keith Lundberg 2017년 4월 26일
Hi Prashant, Thank you I had not tried LibBlockOutputSignalWidth yet... however, after just trying it now I see it behaves the same as the other "dimension" routines I mentioned. They all just return numeric values for the maximum signal size. All of the following routines just give us numbers, while instead I was hoping for a variable name:
LibBlockOutputSignalWidth
LibBlockOutputSignalSymbolicWidth
LibBlockOutputSignalDimensions
LibBlockOutputSignalSymbolicDimensions
So for example a variable sized signal with a maximum size of [2 10] returns a LibBlockOutputSignalWidth of "20".
By the way, as a workaround to this code interfacing trouble, I have begun using bus signals instead of variable sized signals. I create a bus that contains both the full-sized signal and a value for the currently valid portion of this signal.
Bus signals are less convenient in several ways, but they do give full code-generation access to the variable that specifies the current width. Emitting a bus requires my S-Function to use C MEX interfaces instead of Level 2 MATLAB, but it works.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by