ASCII String with SCI Transmit

조회 수: 2 (최근 30일)
Daniel
Daniel 2011년 2월 22일
댓글: Kamal Joshi 2015년 11월 26일
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
Walter Roberson
Walter Roberson 2011년 2월 22일
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 2015년 11월 26일
Were you able to figure out how to do this within matlab ?

댓글을 달려면 로그인하십시오.

채택된 답변

Daniel
Daniel 2011년 2월 24일
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
Walter Roberson
Walter Roberson 2011년 2월 24일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (5개)

Doug Eastman
Doug Eastman 2011년 2월 22일
If you have xPC Target you can use the ASCII Encode/Decode Block.
  댓글 수: 1
Walter Roberson
Walter Roberson 2011년 2월 22일
Daniel does not have an xPC target.

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2011년 2월 22일
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
Walter Roberson
Walter Roberson 2011년 2월 22일
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
Daniel 2011년 2월 22일
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
Walter Roberson
Walter Roberson 2011년 2월 22일
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 2011년 2월 23일
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
Daniel 2011년 2월 22일
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
Walter Roberson
Walter Roberson 2011년 2월 22일
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
Daniel 2011년 2월 23일
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
Walter Roberson
Walter Roberson 2011년 2월 23일
I've used such things too, but they didn't have floating point conversions in the ones I had.
Walter Roberson
Walter Roberson 2011년 2월 23일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 String에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by