Output setted from c-mex is sometime right, sometime null

Hi all! I stop my simulation with Stop block, setting from C-mex file the respective output to 1 when a condition is verified. If this condition is valid, before to stop, I set a few values in a second output vector that I want to read externally in a M-file. I don't know why, but some times it give me in output the right values, other times it give me a null output! This problem has to do with the ode solver I use (ode45)?
Thanks in advance!

 Risposta accettata

More likely that there is something wrong with the way your S-function is written. Could you post your mdlOutputs implementation?

8 Commenti

Marcus
Marcus il 9 Ago 2012
Modificato: Marcus il 9 Ago 2012
It's very long and intricate to copy here. By the way I'm sure that it's right because: 1) sometimes goes well and sometimes not; 2) before stop the simulation I print the output values from c file (correct) but when I read them from M file they are null.
Then, perhaps you could show us how you are assigning the output to the S-function output signal?
real_T *y1 = ssGetOutputPortRealSignal(S,1);
real_T *ystop = ssGetOutputPortRealSignal(S,2);
...
if (<condition>) { //if condition is true
y1[1] = <value1>; //set some values in the y1 output
y1[2] = <value2>;
...
ssPrintf("%f\n", y1[1]); //print on the console value1
ystop[0] = 1; //stop the simulation
}
It's right? Value1 is printed correctly on the console, but the respective output y1 (read in Matlab workspace) is all null.
Just to clarify - the ss* API uses zero-based indexing, so "y1" is writing to the second output port, and "ystop" is writing to the third output port - is this intended?
If it is, could you verify that ssGetOutputPortDataType(S,1) and ssGetOutputPortDataType(S,2) both return 0? This will ensure that both outputs are indeed expecting double values.
I have another output port, so the number of that is correct. I tried also ssGetOutputDataType and it returns 0, so I think this is not the problem.
Also, not sure if it was a typo, but you should have:
y1[0] = <value1>; //set some values in the y1 output
y1[1] = <value2>;
...
(Zero-based indexing)
Marcus
Marcus il 11 Ago 2012
Modificato: Marcus il 11 Ago 2012
Indexing is not the problem (yes is a typo). I don't know what to think :/
Strange. I'm out of ideas - perhaps you should send your S-function to MathWorks Tech Support so they can investigate it more closely?

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su General Applications in Centro assistenza e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by