How to change ASCII code into decimal using simulink block

The data I get from serial port are in form of ASCII And I want to get a decimal form. Please show me an example using Simulink block to change ASCII into decimal. Thanks a lot. ^_^

댓글 수: 3

Which block are you using to receive the data? The ones I find only deal with bytes in numeric form, which goes along with the fact that native Simulink signals cannot be character type.
I am using the block "Serial Receive" Data type is "Unit8" http://uk.mathworks.com/help/instrument/serialreceive.html?s_tid=srchtitle
The data I receive is from an encoder. The voltage indicates the angle. Then I use Simulink to receive this voltage value. I think this value is in form of ASCII, and I just want the numeric ones(48-57)and I am trying to change all the data into a useful decimal. Thank you so much for your help. (^_^)

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

답변 (1개)

Walter Roberson
Walter Roberson 2016년 1월 25일
In the (unusual) case where the input is a stream of ASCII digits that are all independent from each other, then
input_byte - '0'
converts the ASCII to the corresponding decimal digit.
Or since you are doing it in Simulink, subtract 48.
I say this is unusual because typically when values are encoded as ASCII digits, multiple digits are used to transfer decimal values, either fixed width or space delimited or comma delimited or CR or NL or CR/NL delimited.

댓글 수: 1

Thank you so much for your answer. You are so nice (^_^)
If the value of ASCII digits are multiple digits. Then how to change ASCII digits into a multiple decimal values.

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

카테고리

도움말 센터File Exchange에서 Simulink에 대해 자세히 알아보기

제품

질문:

2016년 1월 24일

댓글:

2016년 1월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by