Serial Lib / BytesToString and IBM850 umlauts

alibaba

Member
Licensed User
Longtime User
Hello !

I get from an BT Serial Port Module the Data in IBM850 Codec,
this is not changeable:

ß
00DF
225

ä
00E4
132

ö
00F6
148

ü
00FC
129

Ä
00C4
142

Ö
00D6
153

Ü
00DC
154

Sub BT_AStream_NewData (Buffer() As Byte)

Dim Buffer_MSG As String
Buffer_MSG = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
or
Buffer_MSG = BytesToString(Buffer, 0, Buffer.Length, "ASCII")

IBM850 not available ?

I get always the replacement character � U+FFFD

In basic4pcc it goes:
buffer() = Serial1.InputArray
sSerial = sSerial & bit850.BytesToString(buffer(),0,ArrayLen(buffer()) )

but in b4a is no serial InputArray available

How i can get the ßäöüÄÜÖ

Any Suggestion ?

Thanks.

Best regards
Albert
 

glook

Member
Licensed User
Longtime User
Have you tried this:-

Buffer_MSG = BytesToString(Buffer, 0, Buffer.Length, "iso-8859-1")


I haven't used it with BytesToString, but the iso-8859-1 character set works fine for TextReader - enables all European accent letters.


Edit:- Klaus beat me to it !
 
Last edited:
Upvote 0

alibaba

Member
Licensed User
Longtime User
With iso-8859-1 i get
ß = á
öäüÖÄÜ = a rectangle

Maybe the sending Codepage is 437...

Any Suggestion ?

Thanks.

Best regards
Albert
 
Upvote 0

glook

Member
Licensed User
Longtime User
Albert - yes, you are right that this still not the correct coding.

I just compared the code tables. It does look like the incoming stream is IBM850 or somthing very similar and the numeric codes do not match iso-8859-1. The result you are getting does make sense though!

ß = 225 = á (should be 223)
ö = 148 = ” (should be 246)
ä = 132 = … (should be 228)
ü = 129 = (should be 252)
.... and so on.

So you need to specify another character set, but so far I have not found the correct one for Android, or if there is one. It looks like an Android thing, rather than B4A. Perhaps someone else knows?

Failing all else, you might need to do your own translation at character level, which may not be too hard.
 
Upvote 0

alibaba

Member
Licensed User
Longtime User
the correct coding is ibm850 but is not available
also i played arround and this is my solution:

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

i take windows-1252 encoding that gives me for all the umlauts another char
and then i change it to the correct

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

Thanks

regards

Albert
 
Upvote 0
Top