-
February 12th, 2014, 05:02 PM
#1
VB6 Comm issue with Japanese regional settings
Having a problem with serial communications when reading COM port or Winsock when computer is set to Japanese regional settings. We need setting to properly display Japanese text. When region is English COM data is correct. Below is code example of reading COM when input mode is Binary:
'----- RS232 communications. Responce data from board
'----- Format is 9600bps, No Parity, 8 data bits, 1 Stop bit EOT/ACK/NAK Terminator
'------------------------------------------------------------------------------------
Code:
Private Sub com0MICSerial_OnComm()
Dim i%
Dim StringRec As Variant
Dim h As Integer
Select Case com0MICSerial.CommEvent
'----- READ serial input string
Case comEvReceive
StringRec = com0MICSerial.Input '--- read in raw data (comInputModeBinary) StringRec is variant
For h = 0 To UBound(StringRec)
MICstring = MICstring & Chr$(CByte(StringRec(h))) '--- converted to string
Next h
Do Until Left$(MICstring, 1) = Chr$(1) Or Left$(MICstring, 1) = Chr$(6) Or Left$(MICstring, 1) = Chr$(21) Or Len(MICstring) = 0
MICstring = Mid$(MICstring, 2)
Loop
lbl0Received.Caption = ""
For i% = 1 To Len(MICstring) '----- print string to screen in hex
lbl0Received.Caption = lbl0Received.Caption & Hex$(Asc(Mid$(MICstring, i, 1))) & " "
Next
Here is winsock code:
--------------------------------------------------------------------
Code:
'----- get data and display
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim InputBytes() As Byte
Dim h As Integer
Winsock1.GetData InputBytes, CInt(vbByte)
For h = 0 To UBound(InputBytes)
MICstring = MICstring & Chr$(InputBytes(h)) '----converted to string
Next h
lbl0Received.Caption = ""
For i% = 1 To Len(MICstring)
lbl0Received.Caption = lbl0Received.Caption & Hex$(Asc(Mid$(MICstring, i, 1))) & " "
Next
This will read in a data string with control chrs. total string is 46 bytes with header and eot
We display on vb text windows in hex format for viewing. when byte data value reaches 128, 0 value is displayed
It seems like a 2byte UTF-8 situation when reading with Japanese. It seems the byte comes in OK but not when converted to string
Example: soh, D, gs, data.......... eot
All is OK when computer is English regional settings. Does anyone have solution for this problem
Thanks,
Can call or email .... [contact info removed]
Walt
Last edited by DataMiser; February 14th, 2014 at 05:49 PM.
Reason: removed contact info
-
February 12th, 2014, 05:02 PM
#2
Re: VB6 Comm issue with Japanese regional settings
-
February 12th, 2014, 11:17 PM
#3
Re: VB6 Comm issue with Japanese regional settings
Don't put contact info into posts. Spam Bots troll us every night. We can send you a PM (but most won't). Just wait for an answer
Also, use code tags [/Code]
-
February 14th, 2014, 05:50 PM
#4
Re: VB6 Comm issue with Japanese regional settings
My question would be where is the data coming from and what format was/is it in. VB6 doesn't work that well with unicode
Always use [code][/code] tags when posting code.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|