I am writting a S Function that outputs a array of boolean (4 positions)
I am having a access memmory violation while writing the outputs inside mdlOutputs callback.
This error is not instantenous. I mean: the code runs fine until it crashes later on and Matlab gives a fatal error. I'm pretty sure the error is in the memcpy operation because I have debugged and after I comment this line of code, it works fine. Also, it runs 100% fine if the data type is a scalar.
So, I have a couple of questions:
- How can I use memcpy to write the values of an array in simulink?
- I have assumed that simulink output memmory is a continuous memmory block. Is it correct?
- Any hints on how to solve it?
Pseudo-Code is here:
static void mdlOutputs ( SimStruct* S, int_T tid ) {
(...)
//src variable defined here
(...)
void* dst;
// get output port data type id
type = ssGetOutputPortDataType ( S, i ); // type = SS_BOOLEAN
// get data type size
size = ssGetDataTypeSize ( S, type ); //size = 1 byte
// get output port signal pointer
dst = ( void* ) ssGetOutputPortSignal ( S, i ); //dst has a valid value
// get output port width
width = ssGetOutputPortWidth ( S, i ); //width is 4, since it is a 4 position array
size = size * width; // size now is 4
memcpy ( dst, src, size ); // Error
}