Reading signed data from RS232
Mostra commenti meno recenti
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?
Risposte (2)
Chirag Gupta
il 19 Apr 2011
0 voti
Instead of using fread, try using fscanf where you can specify the format.
Ankit Desai
il 20 Apr 2011
0 voti
You can provide the precision that you want to use with fread.
-Ankit
1 Commento
Walter Roberson
il 20 Apr 2011
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.
Categorie
Scopri di più su Low-Level File I/O in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!