C S-Function to TLC conversion sytax help needed

조회 수: 11 (최근 30일)
Rich
Rich 2012년 2월 6일
편집: Image Analyst 2013년 10월 7일
I need some help converting some simple C code from an S-Function to a TLC file, but I'm not familiar with the syntax enough to do so. I'm not even sure if it can be done or not.
Here's the C code:
/* Function: mdlOutputs =======================================================*/
static void mdlOutputs(SimStruct *S, int_T tid)
{
union {real32_T x; uint8_T c[4];} sp;
real32_T *in;
uint8_T *out[4];
int_T i;
in = (real32_T *) ssGetInputPortSignal(S, 0);
sp.x = *in;
for (i=0; i<4; i++)
{
out[i] = (uint8_T *) ssGetOutputPortSignal(S, i);
*(out[i]) = sp.c[i];
}
}

채택된 답변

Rich
Rich 2012년 2월 9일
Figured it out...
%%File : sfun_Single2FourBytes.tlc
%%Description:
Real-Time Workshop interface for S-function "sfun_Single2FourBytes.c"
%implements sfun_Single2FourBytes "C"
%function Outputs(block, system) Output
/* S-Function "sfun_Single2FourBytes" Block: %<Name> */
%assign in = LibBlockInputSignal(0, "", "", 0)
{
union {real32_T x; uint8_T c[4];} sp;
sp.x = %<in>;
%foreach i = 4
%assign out = LibBlockOutputSignal(i, "", "", 0)
%<out> = sp.c[%<i>];
%endforeach
}
%endfunction
%%[EOF] sfun_Single2FourBytes.tlc

추가 답변 (0개)

카테고리

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