Bluetooth - AsyncStreams

Lorna

New Member
Licensed User
Longtime User
Hello

We are using the Serial Tutorial example that uses AsyncStreams to received data via Bluetooth.

It is working fine but the data I’m receiving contains special ASCII characters which are not being received properly by my application – they are being received as 2 bytes instead of one.

I have changed the encoding from UTF8 to ISO-8859-1 but it has not fixed the issue

B4X:
Dim SaveStr As String
Dim LorStr As String
----------------------
Sub AStream_NewData (Buffer() As Byte)
LorStr = BytesToString(Buffer, 0, Buffer.Length, "ISO-8859-1")
SaveStr = SaveStr & LorStr         ' Concatenate string
Save_file(SaveStr)            ' Save to txt file
End Sub

Any help would be greatly appreciated.

Regards,
Lorna
 

raphael75

Active Member
Licensed User
Longtime User
Which ASCII characters are not received properly?
Do you see the same problem when the received text is shown on the screen, or is it only in the saved txt file?
 
Upvote 0

Lorna

New Member
Licensed User
Longtime User
Hi guys,

Thanks for the replies.

The data we are sending is encrypted and includes characters between decimal 0 & 255.

I can’t upload the data in a .txt file as Notepad can’t display all of the characters.

However I can list the character decimal that we are sending compared to what is being recorded using a Hex editor:


Byte Actual Received
1 0 0
2 202 195
3 0 138
4 0 0
5 20 0
6 139 20
7 17 194
8 49 139
17
49


The bytes listed above are a header in the data which is 8 bytes of information but when it is received via Bluetooth to any of the Android devices we have tested the header section contains extra bytes.

I'm terrible at explaining things so I apologise if this is just gibberish.

Regards,
Lorna
 
Upvote 0
Top