Convert and print chinese idioms

Convert and print chinese idioms

Postby Maurizio » Fri Jul 08, 2022 3:01 pm

Hello
I have to print Chinese idioms via socket with ESC / POS , as examples

Code: Select all  Expand view
#include "FiveWin.ch"
#include "hbsocket.ch"
#define ADDRESS                     "192.168.0.139"
#define PORT                        9100
#define EOT                         ( Chr( 4 ) )

//----------------------------------------------------------------------------//

function Main()
  local hSocket ,c1 := ''
 
   FW_SetUnicode( .T. )
   c1 := '"中国版"'
   
   if empty( hSocket := hb_socketOpen() )
        ? "socket create error " + hb_ntos( hb_socketGetError() )
   endif
   if !hb_socketConnect( hSocket, { HB_SOCKET_AF_INET, hb_socketResolveAddr( ADDRESS ), PORT } )
        ? "socket connect error " + hb_ntos( hb_socketGetError() )
   endif
   
   MsgInfo(c1)

   hb_socketSend( hSocket,c1  +  chr(10)+chr(13))  
 
   hb_socketShutdown( hSocket )
   hb_socketClose( hSocket )
 
return nil


the message on the screen is correct ,but the printed result is wrong (other idioms ) :( .

I compared with sockserv.prg (from fwh \ samples folder)
the transmission and reception of the program in FW and a program that correctly prints and analyzes the strings character by character with asc ()

this is the result :

Correct
---------------
214
208
185
250
176
230


With FW error
--------------------
228
184
173
229
155
189
231
137
136


I think you have to use a conversion program. Can someone help me ?

Maurizio
Last edited by Maurizio on Mon Jul 11, 2022 7:02 am, edited 2 times in total.
User avatar
Maurizio
 
Posts: 796
Joined: Mon Oct 10, 2005 1:29 pm

Re: Convert and print chinese idioms

Postby Antonio Linares » Sat Jul 09, 2022 5:48 pm

Dear Maurizio,

I have asked Mr. Rao to review your code as he is our expert in unicode

Lets wait for his comments

many thanks
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Convert and print chinese idioms

Postby nageswaragunupudi » Fri Jul 22, 2022 6:15 pm

FWH supports the most popular UTF8 encoding of Unicode and also uses UTF16BE encoding for communication with Windows OS.

This is a Chinese word with 3 characters is represented by 9 bytes, 228,184,173,229,155,189,231,137,136 when encoded in UTF8 and 6 bytes in UTF16BE, 45,78,253,86,72,114

Unicode UTF8 encoding is not directly accepted by your hardware.

I could not figure out what encoding of Unicode produces the byte stream you found to be working.

Even long before Unicode (1987), East Asian languages like Chinese, Korean, Japanese had their own encoding systems which are still being used in those countries. Examples "Big 5" for Traditional Chinese, "GB2312" for Simplified Chinese, etc.

Without knowing more about the equipment, its manual and api documentation, it is difficult to know what encoding it accepts.

In any case, I like to test UTF8 encoding once again with prefix of BOM (byte order mark). I am not sure it works, but nothing wrong in trying once.

Try to send this byte stream:
Code: Select all  Expand view

Chr( 239 )+Chr( 187)+Chr( 191 )+Chr( 228 )+Chr( 184 )+Chr( 173 )+Chr( 229 )+Chr( 155 )+Chr( 189 )+Chr( 231 )+Chr( 137 )+Chr( 136 )+Chr( 0 )+Chr( 13 )+Chr( 10 )
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10248
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Convert and print chinese idioms

Postby Maurizio » Mon Jul 25, 2022 9:06 am

Thanks RAO

unfortunately your string doesn't work :(

Summary :
c1 := '中国版'
cA := Chr( 239 )+Chr( 187)+Chr( 191 )+Chr( 228 )+Chr( 184 )+Chr( 173 )+Chr( 229 )+Chr( 155 )+Chr( 189 )+Chr( 231 )+Chr( 137 )+Chr( 136 )+Chr( 0 )+Chr( 13 )+Chr( 10 )
cB := Chr( 214 )+Chr( 208)+Chr( 185 )+Chr( 250 )+Chr( 176 )+Chr( 230 )

c1 and cA does not works
cB works

the problem is how transform '中国版' in Chr( 214 )+Chr( 208)+Chr( 185 )+Chr( 250 )+Chr( 176 )+Chr( 230 )

Regads MAurizio
User avatar
Maurizio
 
Posts: 796
Joined: Mon Oct 10, 2005 1:29 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 88 guests