ASCII String with SCI Transmit
15 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Walter Roberson
il 22 Feb 2011
None of fprintf(), sprintf(), num2str() are in the Embedded Matlab subset,
http://www.mathworks.com/help/toolbox/eml/ug/bq1h2z7-9.html
Risposta accettata
Daniel
il 24 Feb 2011
1 Commento
Walter Roberson
il 24 Feb 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.
Più risposte (5)
Walter Roberson
il 22 Feb 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 Commento
Walter Roberson
il 22 Feb 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
Daniel
il 22 Feb 2011
3 Commenti
Walter Roberson
il 22 Feb 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
il 23 Feb 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.
Daniel
il 22 Feb 2011
1 Commento
Walter Roberson
il 22 Feb 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.
Daniel
il 23 Feb 2011
2 Commenti
Walter Roberson
il 23 Feb 2011
I've used such things too, but they didn't have floating point conversions in the ones I had.
Walter Roberson
il 23 Feb 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.
Vedere anche
Categorie
Scopri di più su String in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!