Serial Encoding Code Page 850 ?

woodpecker

Member
Licensed User
Longtime User
Hi folks,

Trying to use code page 850 for serial comms, in b4ppc it was encoding = "850", what's the equivalent in b4android?

I cannot find a list of charsets that serial supports,

I have tried:-

Initialize2(Serial1.InputStream,"850") - Unsupported error
Initialize2(Serial1.InputStream,"CP-850") - Unsupported error

Initialize2(Serial1.InputStream,"ISO-8859-1") - Works but wrong characters
Initialize2(Serial1.InputStream,"WINDOWS-1252") - Works but wrong characters

:sign0085:
 

agraham

Expert
Licensed User
Longtime User
If necessary you can get a list of supported encoding strings you can use with the SupportedEncodings method in my ByteConverter library. In fact the ByteConverterDemo displays these for you.

Unfotunately there doesn't seem to be any support for code page 850. If you need the various graphic characters of 850 then you will have to build an array with the correct Unicode characters and build your own strings with Stringbuilder by indexing into that array with each byte received.

Code page 850 - Wikipedia, the free encyclopedia gives the Unicode code point values that you need. They are in hex format but Basic4android does support the 0xffff format for numeric literals so you can use them directly without having to convert them to decimal.
 
Upvote 0

alibaba

Member
Licensed User
Longtime User
My Solution for this Problem is to use WINDOWS-1252 with this function:


B4X:
Buffer_MSG = IBM850UMLAUTS(BytesToString(Buffer, 0, Buffer.Length, "WINDOWS-1252"))

Sub IBM850UMLAUTS(S As String)
'ÄäÖöÜüß
'Ž„™”šá
  S = StringReplaceAll(S,"Ž","Ä")
  S = StringReplaceAll(S,"„","ä")
  S = StringReplaceAll(S,"™","Ö")
  S = StringReplaceAll(S,"”","ö")
  S = StringReplaceAll(S,"š","Ü")
  S = StringReplaceAll(S,"","ü")
  S = StringReplaceAll(S,"á","ß")
  Return S
End Sub

'Delphi StringReplaceAll
Sub StringReplaceAll(S As String, SS As String, SR As String)
  Do While S.IndexOf(SS) <> -1
     S = S.SubString2(0,S.IndexOf(SS)) & SR & S.SubString2(S.IndexOf(SS)+SS.Length, S.Length)
  Loop
  Return S
End Sub
 
Last edited:
Upvote 0
Top