TextReader Char to Int

Dutch2

Member
Licensed User
Longtime User
I'm using the SerialExample to connect to a custom Bluetooth device and read some data.

In the Timer tick I am able to read the data from the port:

B4X:
         Dim Buffer(20) As Char
         Dim Count As Int
         Count = TextReader1.Read(Buffer,0,19)

The data sent by the device is unsigned 0...255. How do I extract this data from the Buffer?

If I use Asc(Buffer(x)) I get the correct value when the data is under 128, above that I get 65533 no matter what the value is.

The serial example is great, it just has been a long time since I've programmed in Basic

Thanks in advance,

D2.
 
Last edited:

Dutch2

Member
Licensed User
Longtime User
Thanks agraham, that makes a lot of sense.

I made it work with RandomAccessFile but it clearly is a work-around:

B4X:
Sub AStreams_NewData (Buffer() As Byte)
   Dim Scan As Int
   Dim Transform As RandomAccessFile
   Dim Data(50) As Int
   Transform.Initialize3(Buffer,True)
   For Scan = 1 To Buffer.Length - 1               
           Data(Scan) = Transform.ReadUnsignedByte(Scan)
        Next
End Sub

Thanks,

D2.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…