VB6 Comm issue with Japanese regional settings
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: VB6 Comm issue with Japanese regional settings

Threaded View

  1. #1
    Join Date
    Feb 2014
    Posts
    2

    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 04:49 PM. Reason: removed contact info

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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center