ASCII String with SCI Transmit

15 visualizaciones (últimos 30 días)
Daniel
Daniel el 22 de Feb. de 2011
Comentada: Kamal Joshi el 26 de Nov. de 2015
Anyone here know how to do a number to string conversion, matlab has a num2str() which would be perfect but it is not compatible with embedded matlab fcn.
My target is a TI chip (F28335). My goal is to send measurement data and see it in hyperterminal but i need to convert the numbers to ASCII before i transfer it out or i will get garbage, which i have been getting.
  2 comentarios
Walter Roberson
Walter Roberson el 22 de Feb. de 2011
None of fprintf(), sprintf(), num2str() are in the Embedded Matlab subset,
http://www.mathworks.com/help/toolbox/eml/ug/bq1h2z7-9.html
Kamal Joshi
Kamal Joshi el 26 de Nov. de 2015
Were you able to figure out how to do this within matlab ?

Iniciar sesión para comentar.

Respuesta aceptada

Daniel
Daniel el 24 de Feb. de 2011
I c, so the answer is that it can not be done unless i use s-function to run other code that has that capability? do i have this correct?
  1 comentario
Walter Roberson
Walter Roberson el 24 de Feb. de 2011
Sorry, I can't answer that with any authority: I'm going by what I've been able to _find_ in the documentation, but I don't have the appropriate toolkits to experiment with.

Iniciar sesión para comentar.

Más respuestas (5)

Doug Eastman
Doug Eastman el 22 de Feb. de 2011
If you have xPC Target you can use the ASCII Encode/Decode Block.
  1 comentario
Walter Roberson
Walter Roberson el 22 de Feb. de 2011
Daniel does not have an xPC target.

Iniciar sesión para comentar.


Walter Roberson
Walter Roberson el 22 de Feb. de 2011
Daniel, it would help to know if there are constraints on the class or range of numbers to be converted. For example is this unsigned integers or is it full floating point in exponential notation (and if so how many digits are you looking for) ?
  1 comentario
Walter Roberson
Walter Roberson el 22 de Feb. de 2011
For simple positive integers:
n = 3141;
if n == 0
s = uint8(48)
else
s = zeros(1,ceil(log10(n+1)),'uint8');
for t = size(s,2):-1:1
s(t) = mod(n,10) + 48;
n = floor(n./10);
end
end
%s is now the vector of uint8

Iniciar sesión para comentar.


Daniel
Daniel el 22 de Feb. de 2011
it can be double, uint8, etc.
It would be awesome if i can do something like this in an embedded matlab
_int sum;
sum = atoi( string );
printf("Sum = %d\n", sum );_
Embedded matlab has a sprintf function that works like this but it cannot be used in embedded matlab.
The ASCII Encode function for xPC target is perfect but it can not be used for my Ti Target.
  3 comentarios
Walter Roberson
Walter Roberson el 22 de Feb. de 2011
To confirm: you have a measurement that might be represented by any of the arithmetic types, and you would like to convert it to an ASCII representation using an arbitrary formatting including possibilities such as '%+09f.2' ?
Or are you saying that you only need to represent integral values and the data type could be whatever is most convenient for programming purposes ?
Doug Eastman
Doug Eastman el 23 de Feb. de 2011
Have you tried the xPC Target block? As far as I know it is not specific to the xPC kernel and could work on the TI processor.

Iniciar sesión para comentar.


Daniel
Daniel el 22 de Feb. de 2011
I need to keep this generic because i plan to use it has a debug probe, so i can spit out messages out a serial port. I don't want to create different functions for different data types. I have done this a lot in C using itoa(),atoi(), and printf() essentially being able to spit out anything.
Can simulink embedded package do a simple number to string conversion without s-function?
  1 comentario
Walter Roberson
Walter Roberson el 22 de Feb. de 2011
What you are asking for is not simple. glibc went through a lot of trouble to get the conversions right with proper rounding (consider, for example, denormalized numbers.)
I suggest that you consider using the vprintf() source from glibc, provided that the license terms are compatible with your purposes.
Can simulink embedded package do a simple number to string conversion without s-function? I don't know, but the embedded function list I referenced above is suggestive that it does not, as otherwise int2str() would probably be supported at a minimum.
vprintf() is a relatively large routine that would often take up too much memory to be worth-while.
It is not uncommon for programmers to find that they can live with (say) fixed point, two decimal places -- something easily done by round(x*100), convert to string, insert the '.' character at the proper location.

Iniciar sesión para comentar.


Daniel
Daniel el 23 de Feb. de 2011
I consider simple because i've programmed 8 bit microcontrollers with a 500 dollar compiler that had a simple to use function to convert a number to string and easy to use printf functions for rs232.
Are you suggesting to use vprintf() through s-function?
  2 comentarios
Walter Roberson
Walter Roberson el 23 de Feb. de 2011
I've used such things too, but they didn't have floating point conversions in the ones I had.
Walter Roberson
Walter Roberson el 23 de Feb. de 2011
One of the vfprintf source files is at
http://www.opensource.apple.com/source/Libc/Libc-166/stdio.subproj/vfprintf.c
You would not be able to use this directly, as it needs stdarg for the arguments; you would need a layer that converted Matlab variable argument lists to stdarg . I do not know, however, whether embedded Matlab supports variable arguments.

Iniciar sesión para comentar.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by