Borrar filtros
Borrar filtros

Using string parameters in S-Functions generated by the legacy code tool

5 visualizaciones (últimos 30 días)
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

Respuestas (2)

Vincent
Vincent el 21 de Mayo de 2014
I found a temporary solution: adding the ending 0 in the list of bytes given in the parameter field. That would do something like that:
[unicode2native('string', 'ISO-8859-1') 0]
I would still like to understand how it is supposed to be handled to just have 'string'.

Anthony Poulin
Anthony Poulin el 3 de Jul. de 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))

Categorías

Más información sobre Simulink Coder en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by