Dutch2 Member Licensed User Longtime User Sep 14, 2011 #1 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: Code: Copy 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: Sep 14, 2011
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: Code: Copy 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.
Erel B4X founder Staff member Licensed User Longtime User Sep 18, 2011 #2 You can use BytesToString to convert an array of bytes to string. Upvote 0
agraham Expert Licensed User Longtime User Sep 18, 2011 #3 Java byte values are treated as -128 to 127. If you want 0 to 256 see my post here. Upvote 0
Dutch2 Member Licensed User Longtime User Sep 18, 2011 #4 Thanks agraham, that makes a lot of sense. I made it work with RandomAccessFile but it clearly is a work-around: Code: Copy 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
Thanks agraham, that makes a lot of sense. I made it work with RandomAccessFile but it clearly is a work-around: Code: Copy 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.