以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]使用串口进行通讯  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=39076)

--  作者:tungwun
--  发布时间:2013/8/14 22:22:00
--  [求助]使用串口进行通讯
请问如何在TextBox读串十六进制资料?
--  作者:有点甜
--  发布时间:2013/8/14 22:36:00
--  
 呃,可以类似这样写。

Dim cnt As Integer = Ports("COM2").BytesToRead
If cnt > 0 Then \'缓冲区是否有数据
    Dim bys(cnt - 1) As Byte
    Ports("COM2").Read(bys,0,cnt)
    Dim str As String = ""
    For Each by As Byte In bys
       str += by.Tostring("X2")
    Next
    msgbox(str)
End If