WriteRTW in a M Level2 S-Function

Hi.
I like to write a TLC to inline a Matlab level2 S-Function. Making the S-Function ready for code-generation.
To access the parameter in the RT-Code, I have to write a "WriteRTW" Function. For Arrays it is not a problem, but I don't know how to handle with strings.
M-File:
...
function WriteRTW(block)
b =char([block.DialogPrm(1).Data 0]);
block.WriteRTWParam('matrix', 'Params', cast(b,'uint8'));
%end Terminate
...
TLC-File:
...
char ip[13];
ip[0] = (char)(uint8_T)%<ParamSettings.Params[0][0]>;
ip[1] = (char)(uint8_T)%<ParamSettings.Params[0][1]>;
ip[2] = (char)(uint8_T)%<ParamSettings.Params[0][2]>;
ip[3] = (char)(uint8_T)%<ParamSettings.Params[0][3]>;
ip[4] = (char)(uint8_T)%<ParamSettings.Params[0][4]>;
ip[5] = (char)(uint8_T)%<ParamSettings.Params[0][5]>;
ip[6] = (char)(uint8_T)%<ParamSettings.Params[0][6]>;
ip[7] = (char)(uint8_T)%<ParamSettings.Params[0][7]>;
ip[8] = (char)(uint8_T)%<ParamSettings.Params[0][8]>;
ip[9] = (char)(uint8_T)%<ParamSettings.Params[0][9]>;
ip[10] = (char)(uint8_T)%<ParamSettings.Params[0][10]>;
ip[11] = (char)(uint8_T)%<ParamSettings.Params[0][11]>;
ip[12] = (char)(uint8_T)%<ParamSettings.Params[0][12]>;
...
I like to use it in this way:
block.WriteRTWParam('string', 'Params', block.DialogPrm(1).Data);
Can someone help me?

回答(1 个)

I experimented a little with the demo file sldemo_msfcn_frame and the contained S-function (run edit msfcn_frame_filt to see the source code), it seems that you should be able towrite:
M-File:
...
function WriteRTW(block)
block.WriteRTWParam('string', 'MyStringParam', block.DialogPrm(1).Data);
...
TLC-File:
%assign myParam = ParamSettings.MyStringParam
const char ip[] = "%<myParam>";
Does this work?

6 个评论

No, unfortunately not.
I get following error:
### Starting build procedure for model: test_MS
### Generating code into build folder: C:\Users\...\UserProgramm_Simulink\test_MS_ert_rtw
### Invoking Target Language Compiler on test_MS.rtw
### Using System Target File: C:\Program Files (x86)\MATLAB\R2012a\rtw\c\ert\ert.tlc
Error: File: C:\...\UserProgramm_Simulink\test_MS_ert_rtw\test_MS.rtw Line: 2235 Column: 24
syntax error
### Build procedure for model: 'test_MS' aborted due to an error.
test_MS.rtw:
...
ParamSettings {
MFile mlpiConnectionBlock
runAccelOnTLC no
isSimViewDevice no
Start Start
Outputs Outputs
MyStringParam 192.168.1.13
...
Also, I try it like this. Without success:
block.WriteRTWParam('string', 'MyStringParam', char(block.DialogPrm(1).Data));
If I enter a text(TestString) in the parameter dialog, it works. But when I write the IP-Address (192.168.1.13), it faults with the same error. And when I write it in this way('192.168.1.13'), it will generate code. But the result is false. const char ip[] = "'192.168.1.13'";
Can you help me?
This is not working:
block.WriteRTWParam('string', 'MyStringParam', '192.168.1.13');
But this is Ok:
block.WriteRTWParam('string', 'MyStringParam', ' 192.168.1.13');
That is crazy.
What is the generated code when you simply enter 192.168.1.13?
It do not generate code, it aborted with error during build rtw.
Thomas: Could you paste the error message please?
Matlab Level-2 S-function of myUserBlock:
...
function WriteRTW(block)
block.WriteRTWParam('string', 'MyStringParam', '192.168.1.13');
%end Terminate
...
Error:
### Starting build procedure for model: Model
### Generating code into build folder: C:\...
### Invoking Target Language Compiler on Model.rtw
### Using System Target File: C:\...\ert.tlc
Error: File: C:\...\Model_ert_rtw\Model.rtw Line: 2466 Column: 24
syntax error
### Build procedure for model: 'Model' aborted due to an error.
Model.rtw:
...
MFile MyUserBlock
runAccelOnTLC no
isSimViewDevice no
Start Start
Outputs Outputs
MyStringParam 192.168.1.13
...

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Simulink Coder 的更多信息

标签

提问:

2012-11-13

Community Treasure Hunt

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

Start Hunting!

Translated by