Using array input and output for simulink S-function C code block
I’m having a tough time attempting to use a C code block that needs uint8 array input and output . I’ve tried starting from a number of legacy code examples but encounter crashes every time my C code actually tries to access the incoming memory. If someone can point me to a working example (I’ve already tried everything that looked relevant here) I’d appreciate it. In my latest attempt I gave up on using the legacy code functions and took code from this example Create a Basic C MEX S-Function – MATLAB & Simulink (mathworks.com) which at least runs without crashing, and started to change it to take uint8 in/out as below. However I’ve no idea where to find the equivalent of InputRealPtrsType for unit8_T . If I use InputPtrsType instead of InputRealPtrsType I get the error error C2100: you cannot dereference an operand of type const void`
static void mdlOutputs(SimStruct *S, int_T tid)
{
int_T i;
// replced ssGetInputPortRealSignalPtrs(S,0) with ssGetInputPortSignalPtrs
InputRealPtrsType uPtrs = ssGetInputPortSignalPtrs(S,0);
// replaced ssGetOutputPortRealSignal(S,0) with ssGetOutputPortSignal
real_T *y = ssGetOutputPortSignal(S,0);
int_T width = ssGetOutputPortWidth(S,0);
for (i=0; i<width; i++) {
*y++ = 2.0 *(*uPtrs[i]);
}
}I’m having a tough time attempting to use a C code block that needs uint8 array input and output . I’ve tried starting from a number of legacy code examples but encounter crashes every time my C code actually tries to access the incoming memory. If someone can point me to a working example (I’ve already tried everything that looked relevant here) I’d appreciate it. In my latest attempt I gave up on using the legacy code functions and took code from this example Create a Basic C MEX S-Function – MATLAB & Simulink (mathworks.com) which at least runs without crashing, and started to change it to take uint8 in/out as below. However I’ve no idea where to find the equivalent of InputRealPtrsType for unit8_T . If I use InputPtrsType instead of InputRealPtrsType I get the error error C2100: you cannot dereference an operand of type const void`
static void mdlOutputs(SimStruct *S, int_T tid)
{
int_T i;
// replced ssGetInputPortRealSignalPtrs(S,0) with ssGetInputPortSignalPtrs
InputRealPtrsType uPtrs = ssGetInputPortSignalPtrs(S,0);
// replaced ssGetOutputPortRealSignal(S,0) with ssGetOutputPortSignal
real_T *y = ssGetOutputPortSignal(S,0);
int_T width = ssGetOutputPortWidth(S,0);
for (i=0; i<width; i++) {
*y++ = 2.0 *(*uPtrs[i]);
}
} I’m having a tough time attempting to use a C code block that needs uint8 array input and output . I’ve tried starting from a number of legacy code examples but encounter crashes every time my C code actually tries to access the incoming memory. If someone can point me to a working example (I’ve already tried everything that looked relevant here) I’d appreciate it. In my latest attempt I gave up on using the legacy code functions and took code from this example Create a Basic C MEX S-Function – MATLAB & Simulink (mathworks.com) which at least runs without crashing, and started to change it to take uint8 in/out as below. However I’ve no idea where to find the equivalent of InputRealPtrsType for unit8_T . If I use InputPtrsType instead of InputRealPtrsType I get the error error C2100: you cannot dereference an operand of type const void`
static void mdlOutputs(SimStruct *S, int_T tid)
{
int_T i;
// replced ssGetInputPortRealSignalPtrs(S,0) with ssGetInputPortSignalPtrs
InputRealPtrsType uPtrs = ssGetInputPortSignalPtrs(S,0);
// replaced ssGetOutputPortRealSignal(S,0) with ssGetOutputPortSignal
real_T *y = ssGetOutputPortSignal(S,0);
int_T width = ssGetOutputPortWidth(S,0);
for (i=0; i<width; i++) {
*y++ = 2.0 *(*uPtrs[i]);
}
} sfunction, c-code, legacy code MATLAB Answers — New Questions