Reading signed data from RS232

조회 수: 4 (최근 30일)
VQ
VQ 2011년 4월 19일
Hi,
I want to read 256 signed numbers from RS232. In Hyperterminal I see:
-54
-54
-54
-52
-55 . . . But when I read it in Matlab I saw something like that:
out=fread(s)
45 53 52 13 13 10 45 . . .
And if I convert "out" to char (val=char(out)) I haven't got 256 numbers, I have 45...I know that this problem is due to conversion into ASCII characters..
Can anybody give me a solution to read correctly the data?

답변 (2개)

Chirag Gupta
Chirag Gupta 2011년 4월 19일
Instead of using fread, try using fscanf where you can specify the format.

Ankit Desai
Ankit Desai 2011년 4월 20일
You can provide the precision that you want to use with fread.
The online documentation should provide more details.
-Ankit
  댓글 수: 1
Walter Roberson
Walter Roberson 2011년 4월 20일
Ankit, if you examine char([45 53 52]) you will find it is '-54' so the problem is not the precision the variables are written at, but rather that the data is being ASCII encoded and needs to be converted back to numeric form.

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

카테고리

Help CenterFile Exchange에서 Workspace Variables and MAT-Files에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by