我选取了串口调试工具里最基本的功能。是否按十六进制如果有不明白的,去用一下一个叫串口调试助手的工具就明白了。另外在后面加几个算法。压缩BCD转成16进制。以及asc码转成16进制
'打开/关闭串口
Private Sub Command1_Click()   '打开关闭串口
On Error GoTo CommErr '出错的话转向错误描述
If Command1.Caption = "打开串口" Then
    MSComm1.CommPort = Combo1.Text
    MSComm1.Settings = "9600,n,8,1"
    MSComm1.RThreshold = 1
    If MSComm1.PortOpen = False Then
        MSComm1.PortOpen = True
        MSComm1.InputMode = comInputModeBinary
        MSComm1.InBufferCount = 0 '清除发送缓冲区数据        MSComm1.OutBufferCount = 0 '清除接收缓冲区数据
        Shape1.BackColor = &HFF&    '打开后,shape控件显示为红色,表示串口打开
        Command1.Caption = "关闭串口" '按钮caption改变成关闭串口
        Combo1.Enabled = False      '串口号选择框变成不可用
    Else
        MsgBox "不能打开串口,该串口可能被使用", vbOKOnly, "错误"
    End If
Else '这个是点关闭的时候,跟上面对照看
    Command1.Caption = "打开串口"
    MSComm1.PortOpen = False
    Combo1.Enabled = True
    Command5.Enabled = False
    Shape1.BackColor = &H0&
End IfExit Sub
CommErr:
    Select Case Err.Number
    Case 8002
        MsgBox "不能打开串口,计算机上没有该端口", vbOKOnly, "错误"
    Case 8005
        MsgBox "不能打开串口,该串口可能被使用", vbOKOnly, "错误"
    Case Else
             
    End Select
End Sub
'发送数据
Private Sub Command2_Click()
    Dim SendData As String
    Dim buf() As Byte
    Dim m, n, p As Long
    Dim i, j, k As Long, cs
On Error GoTo DoErr
    SendData = Trim(Text2.Text)  '将要发送的文本框内的空格去除,并且赋给SENDDATA
    If MSComm1.PortOpen = False Then
        MsgBox "请打开串口", vbOKOnly, "错误"
        Exit Sub
    End If
    If Len(SendData) = 0 Then  '如果文本框内没有数据
        MsgBox "请输入数据", vbOKOnly, "错误"
        Exit Sub
    End If
    If Check2.Value = 0 Then  '如果没有选择是否以16进制发送
        p = Len(SendData)
        ReDim buf(p - 1) As Byte
        For i = 1 To p
            buf(i - 1) = Asc(Mid(SendData, i, 1)) '将每个字符以ASC码发送
        Next i
    Else    '如果选择以16进制发送
        SendData = Replace(SendData, " ", "")
        SendData = Replace(SendData, vbCrLf, "")
        p = Len(SendData) \ 2 - 1
        ReDim buf(p) As Byte
        For i = 0 To p
            buf(i) = CLng("&H" & Mid(SendData, i * 2 + 1, 2))'以16进制数发送
        Next i
    End If    '通过串口发送数据
    MSComm1.InputMode = comInputModeBinary
    MSComm1.Output = buf()
    Exit Sub'出错处理
DoErr:
    If Err.Number = 13 Then
        MsgBox "数据格式不对", vbOKOnly, "错误"
    Else
        MsgBox Err.Description
    End IfEnd Sub
数据接收
Private Sub ProcGetData()   '数据接收
    Dim Buffer() As Byte '定义一个接收数组 注意类型
    Dim i As Long
    Dim stem2, sTem1 As String    Buffer = MSComm1.Input
    stem2 = ""
    sTem1 = ""
       For i = 0 To UBound(Buffer())'这个大家应该清楚吧,最高位,也就是收到的数据的长度赋值给I
       ReDim stem(UBound(Buffer)) As String
       stem2 = stem2 & Right("00" & Hex(Buffer(i)), 2) '缓存里每两位取出来,并且以“十六进制”的形式加进stem2
       sTem1 = sTem1 & Chr(Buffer(i)) '每个字符以字符串的形式加进STEM1
        Next i       '如果不选择以16进制显示,则将stem1显示出来。选择以16进制显示,则将STEM2显示出来
       If Check1.Value = 0 Then
           Text1.Text = Text1.Text & sTem1
           Else
           Text1.Text = Text1.Text & stem2
        End If        
End Sub
相信这两个是比较实用的,我当时写的时候绕了弯路,写出来供需要的人参考一下
压缩BCD
buf(i) = CLng("&h" & Mid(SimId, i * 2 - 1, 2))     SIMID为从文本框得到的数据赋值
asc码
buf(i) = Asc(Mid(SimId, i, 1))