S-Functions: ssWriteRTWParamSettings in mdlRTW does not work.

조회 수: 10 (최근 30일)
Eike
Eike 2011년 2월 23일
Hey there,
I've got a problem regarding the inlining of some C S-Functions.
My S-Function expects some non tuneable parameters (e.g., "port_number"), which I try to write to the .rtw file in order to access them with my corresponding .tlc file.
My C Code looks as follows:
#define PORT_NUMBER (( uint8_T )( mxGetPr( ssGetSFcnParam( S , PORT_NUMBER_IDX ) )[ 0 ] ) + (uint8_T)1 )
static void mdlRTW(SimStruct *S)
{
if(!ssWriteRTWParamSettings (S, 1, SSWRITE_VALUE_NUM, "port_number", PORT_NUMBER))
{
return; /* An error occurred. */
}
}
I tried accessing the parameter with
%assign port_number = SFcnParamSettings.port_number
in my tlc file, but when building the model, I kept getting "unidentified identifier SFcnParamSettings".
Subsequently I searched the built .rtw file for "SFcnParamSettings", but nothing was found. Shouldn't there be a block with this title in it? For me it looks like the mdlRTW function wasn't executed correctly, but why?
And how can I check if it works?

채택된 답변

Eike
Eike 2011년 3월 14일
Note: This seems to be triggered by the same problem I encountered here. I built the model in my own development path using copies of all relevant files/libraries instead of doing so in the original project folder.
I do not know about Matlab's exact problem before, but building in the original folder solved the issue. Again, I find Matlab's error reporting kind of misleading.
With kind regards,
Eike

추가 답변 (2개)

Kaustubha Govind
Kaustubha Govind 2011년 2월 23일
I wonder if the write is failing becausing SSWRITE_VALUE_NUM requires a real_T value, but you are passing in a uint8_T value. You could try using ssWarning or ssPrintf inside your if condition to detect when ssWriteRTWParamSettings is unsuccessful.
Use SSWRITE_VALUE_DTYPE_NUM to write a SS_UINT8 type value, by passing in a void pointer to the same. See the documentation for more details.

Eike
Eike 2011년 2월 24일
Thank you for your reply!
The issue regarding the data type sounds logical to me, I have corrected that one. I also tried doing some error handling using ssWarning, ssPrintf and fprintf (to create a log file), but none of these produced any output. And I still keep getting the "undefined Identifier SFcnParamSettings". How can I find out if my mdlRTW is used at all?
At the moment, my code looks like this:
#define MDL_RTW
static void mdlRTW(SimStruct *S)
{
ssWriteRTWParamSettings (S, 1, SSWRITE_VALUE_DTYPE_NUM, "port_number", &PORT_NUMBER, DTINFO(SS_UINT8, 0));
ssPrintf ("An error occured during .rtw generation!");
}
And I still don't get any output. I don't have to configure anything to use a mdlRTW function, do I? Just put the c and tlc file of same name in the workspace, and Matlab recognises both?
  댓글 수: 3
Eike
Eike 2011년 2월 25일
That's right, that was probably a flaw, I have corrected that one, too. Thanks!
However, there's still no SFcnParamSettings block in my model.rtw.
Fortunately, while searching, I noticed that the parameter does exist in the rtw-File including its value, just not under that name.
Now I'm using "%assign ::port_number = block.Parameter[1].Value[0] + 1", which works.
I have completely no clue why the SFcnParamSettings thing does not work for me, but I don't care anymore ;-)
Eike
Eike 2011년 3월 1일
Appendix: I realized, that for this solution the mdlRTW function is completely irrelevant. I removed it from my C file and parameter passing still works.
Just if anyone's interested.

댓글을 달려면 로그인하십시오.

카테고리

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