C S-Function to TLC conversion sytax help needed

11 vues (au cours des 30 derniers jours)
Rich
Rich le 6 Fév 2012
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];
}
}

Réponse acceptée

Rich
Rich le 9 Fév 2012
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
  1 commentaire
Kaustubha Govind
Kaustubha Govind le 9 Fév 2012
Thanks for posting back with the answer!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Simulink Coder dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by