Using string parameters in S-Functions generated by the legacy code tool
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello, I'm quite new to Simulink, and I'm trying to have S-Function parameters working with a char * type, and I'm using the legacy_code tool to create my S-Function. I understand that Simulink represents characters with the uint8 type, so I created my function like that:
my_init_func(uint8 p1[], uint8 p2[])
The problem is that when opening the parameter window and entering 'string' in the field, it is accepted, but on the simulation run, there is the following error:
Unable to map dialog parameter 1 of S-function 'my_block' in 'my_model/my_block' to a run-time parameter. This parameter is an unsupported variable class such as a string, structure, cell, or an unsupported data type
In found some kind of fix, putting this in the parameter field instead of the plain string:
unicode2native('string', 'ISO-8859-1')
But that results in a non null-terminated string, and a crashing behaviour of the rest of the S-Function and Simulink.
I found a post mentioning the mxGetString, but I don't see how I can have a mxArray from the parameter. So, the question: What is the correct way to get a null-terminated string from the string parameter in the S-Function, with the legacy_code tool?
Thanks a lot
0 Kommentare
Antworten (2)
Anthony Poulin
am 3 Jul. 2014
Hi, I don't know if I'm going to answer well to your question. What I understand is that you want to keep in your s-function a paramter (which is a string) that you put in the mask of your s-function.
When I want to do that I use the functions ssGetSFcnParam and mxArrayToString.
If you call often the parameter in your code, it's intresting to use define like follow:
#define PARAM(n) ssGetSFcnParam(S ,n) // n is the number of your paramters (0: first param, 1:second...)
#define myStrParam mxArrayToString(PARAM(0))
0 Kommentare
Siehe auch
Kategorien
Mehr zu Simulink Coder finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!