以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  显示乱码  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=158858)

--  作者:lshshlxsh
--  发布时间:2020/12/4 17:09:00
--  显示乱码
请问老师 16进制的 输出显示乱码怎么办?
Dim cnt As Integer = Ports("COM5").BytesToRead
If cnt > 0 Then \'缓冲区是否有数据
    Dim Val(cnt - 1) As Byte
    Ports("COM5").Read(val,0,cnt)
    Dim s As String = Ports("COM5").GetString(val)
    If Forms("窗口1").Opened =True Then
        Dim ts As WinForm.Label = Forms("窗口1").Controls("Label1")
        ts.Text = s
    End If
End If


乱码  ???賫逢?嗇????????賫逢?唆????????賫逢?唆????????賫逢?嗇?????






以下为写入内容  编码  Encoding.UTF8


Ports.Add("COM5")
With Ports("COM5")
  .Close()
    .BaudRate = 230400
    .DataBits = 8
.Encoding = Encoding.UTF8
    .StopBits = StopBits.One
    .Parity = Parity.None
    .DtrEnable =True
    .RtsEnable =True
    .Open
End With

--  作者:有点蓝
--  发布时间:2020/12/4 17:24:00
--  
使用字节的方式收发:http://www.foxtable.com/webhelp/topics/1979.htm
--  作者:lshshlxsh
--  发布时间:2020/12/5 10:09:00
--  
谢谢老师,使用字节接收的。

加上     Dim str As String = BitConverter.ToString(rval).Replace("-", " ") 就可以了