发表于:2004-11-15 09:27:00
楼主
请问在VB中,怎样把从MSComm控件接收到的下位机二进制数据以十六进制正确显示在Label或Text中,我用如下的代码接收并显示,但都是乱码。(MSComm的InputMode属性是1-comInputModeBinary)
'定时接收子程序
Private Sub Tmrcomm_Timer()
Tmrcomm.Enabled = False
Dim Rx_buff() As Byte
Dim okstring As String
Dim ReceivedLen As Integer
If MSComm1.InBufferCount > 0 Then
ReceivedLen = MSComm1.InBufferCount
Rx_buff = MSComm1.Input
okstring = StrConv(Rx_buff, vbUnicode)
End If
Label1.Caption = okstring
End Sub