⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmsendrecvdata.frm

📁 vb写的串口调试助手
💻 FRM
字号:
VERSION 5.00
Begin VB.Form frmSendRecvData 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "设置帧数据"
   ClientHeight    =   4275
   ClientLeft      =   2760
   ClientTop       =   3750
   ClientWidth     =   6705
   BeginProperty Font 
      Name            =   "宋体"
      Size            =   10.5
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   ForeColor       =   &H00FF0000&
   Icon            =   "frmSendRecvData.frx":0000
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   4275
   ScaleWidth      =   6705
   ShowInTaskbar   =   0   'False
   StartUpPosition =   1  'CenterOwner
   Begin VB.CommandButton cmdClear 
      Caption         =   "清空"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   10.5
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   4260
      TabIndex        =   5
      Top             =   3780
      Width           =   615
   End
   Begin VB.CommandButton cmdSet0T255k1 
      Caption         =   "0-255/1k"
      Height          =   375
      Left            =   3120
      TabIndex        =   4
      Top             =   3780
      Width           =   1035
   End
   Begin VB.CommandButton cmdSetEB90 
      Caption         =   "EB90..."
      Height          =   375
      Left            =   2100
      TabIndex        =   3
      Top             =   3780
      Width           =   915
   End
   Begin VB.CommandButton cmdSetaTZ 
      Caption         =   "A-Z..a-z"
      Height          =   375
      Left            =   960
      TabIndex        =   2
      Top             =   3780
      Width           =   1035
   End
   Begin VB.CommandButton cmdSet0T255 
      Caption         =   "0-255"
      Height          =   375
      Left            =   120
      TabIndex        =   1
      Top             =   3780
      Width           =   735
   End
   Begin VB.Frame Frame1 
      Caption         =   "发送帧数据(16进制、空格分隔、最多2048字节)"
      ForeColor       =   &H00C00000&
      Height          =   3435
      Left            =   120
      TabIndex        =   8
      Top             =   180
      Width           =   6495
      Begin VB.TextBox txtDataBuffer 
         Height          =   3015
         Left            =   120
         MaxLength       =   6400
         MultiLine       =   -1  'True
         ScrollBars      =   2  'Vertical
         TabIndex        =   0
         Text            =   "frmSendRecvData.frx":0ECA
         Top             =   300
         Width           =   6255
      End
   End
   Begin VB.CommandButton CancelButton 
      Caption         =   "取消"
      Default         =   -1  'True
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   10.5
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   6000
      TabIndex        =   7
      Top             =   3780
      Width           =   615
   End
   Begin VB.CommandButton OKButton 
      Caption         =   "确定"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   10.5
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   5280
      TabIndex        =   6
      Top             =   3780
      Width           =   615
   End
End
Attribute VB_Name = "frmSendRecvData"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Option Explicit

Sub vDispSendRecvData(strMode As String)
    Dim count As Integer
    
    txtDataBuffer.Text = ""
    
    If InStr(strMode, "发送") > 0 Then
        If iTotalSendBytes > 0 Then
            For count = 0 To iTotalSendBytes - 1
                txtDataBuffer.Text = txtDataBuffer.Text + ConvertByteToHex(bSendBuffer(count)) + " "
            Next count
        End If
    Else
        If iTotalRecvCmpBytes > 0 Then
            For count = 0 To iTotalRecvCmpBytes - 1
                txtDataBuffer.Text = txtDataBuffer.Text + ConvertByteToHex(bRecvCmpBuffer(count)) + " "
            Next count
        End If
    End If
End Sub

Private Sub CancelButton_Click()
    Unload Me
End Sub


Private Sub cmdClear_Click()
    txtDataBuffer.Text = ""
End Sub

Private Sub cmdSet0T255_Click()
    Dim i As Integer
    
    txtDataBuffer.Text = ""
    For i = 0 To 255
        txtDataBuffer.Text = txtDataBuffer.Text + ConvertByteToHex(i And &HFF) + " "
    Next i
End Sub

Private Sub cmdSet0T255k1_Click()
    Dim i As Integer
    
    txtDataBuffer.Text = ""
    For i = 0 To 1023
        txtDataBuffer.Text = txtDataBuffer.Text + ConvertByteToHex(i And &HFF) + " "
    Next i
End Sub

Private Sub cmdSetaTZ_Click()
    Dim i As Integer
    
    txtDataBuffer.Text = ""
    For i = Asc("A") To Asc("Z")
        txtDataBuffer.Text = txtDataBuffer.Text + ConvertByteToHex(i And &HFF) + " "
    Next i
    
    For i = Asc("a") To Asc("z")
        txtDataBuffer.Text = txtDataBuffer.Text + ConvertByteToHex(i And &HFF) + " "
    Next i
End Sub

Private Sub cmdSetEB90_Click()
    txtDataBuffer.Text = "EB 90 EB 90 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 5A A5 55 AA"
End Sub

Private Sub OKButton_Click()
    Dim byteArray(0 To cnMaxFrameByteSize) As Byte
    Dim count As Integer, lastComChar As Integer, tempString As String, midStr As String

    tempString = Trim(txtDataBuffer.Text)

    lastComChar = InStr(tempString, " ")

    count = 0
    
    If tempString <> "" Then ' 有内容
        If lastComChar = 0 Then ' 只有一个字节
            tempString = Mid(tempString, 1, 3) ' 防止溢出
            byteArray(0) = CByte(Val("&H" + tempString) And &HFF)
            count = 1 ' 实际字节数
        Else
            Do While lastComChar > 0
                midStr = Mid(tempString, 1, lastComChar - 1)
                ' tempString = mid(tempString, 1, 3) ' 防止溢出
                midStr = Mid(midStr, 1, 3) ' 防止溢出

                byteArray(count) = CByte(Val("&H" + Trim(midStr)) And &HFF)
                tempString = Trim(Mid(tempString, lastComChar + 1))

                count = count + 1
                If count >= cnMaxFrameByteSize Then Exit Do ' 每帧最多cnMaxFrameByteSize字节

                lastComChar = InStr(tempString, " ")
            Loop

            tempString = Mid(tempString, 1, 3) ' 防止溢出
            byteArray(count) = CByte(Val("&H" + Trim(tempString)) And &HFF) ' 最后一个字节其后可能没有逗号
            
            count = count + 1 ' 实际字节数
        End If
    End If

    If InStr(Frame1.Caption, "发送") > 0 Then
        iTotalSendBytes = count ' 发送缓冲有效字节数
        
        ApexCommAnalyse.lblSendDataBytes.Caption = iTotalSendBytes & "字节" ' 发送帧数据字节数
        
        strSendBytesHexString = "" ' 发送内容的HEX显示内容
        
        If iTotalSendBytes > 0 Then
            ReDim bSendBuffer(0 To iTotalSendBytes - 1)
            For count = 0 To iTotalSendBytes - 1
                bSendBuffer(count) = byteArray(count)
                strSendBytesHexString = strSendBytesHexString + ConvertByteToHex(bSendBuffer(count)) + " "  ' 发送内容的HEX显示内容
            Next count
            strSendBytesHexString = Trim(strSendBytesHexString) + vbCrLf
        End If
    Else
        iTotalRecvCmpBytes = count ' 接收比较缓冲有效字节数

        ApexCommAnalyse.lblRecvCmpDataBytes.Caption = iTotalRecvCmpBytes & "字节" ' 接收帧数据字节数
        
        If iTotalRecvCmpBytes > 0 Then
            ReDim bRecvCmpBuffer(0 To iTotalRecvCmpBytes - 1)
            For count = 0 To iTotalRecvCmpBytes - 1
                bRecvCmpBuffer(count) = byteArray(count)
            Next count
        End If
    End If

    Unload Me
End Sub

Private Sub txtDataBuffer_KeyPress(KeyAscii As Integer)
    ' 只能输入16进制数, 空格, BACKSPACE
    If KeyAscii = 8 Or KeyAscii = 32 Or _
       (KeyAscii >= Asc("0") And KeyAscii <= Asc("9")) Or _
       (KeyAscii >= Asc("a") And KeyAscii <= Asc("f")) Or _
       (KeyAscii >= Asc("A") And KeyAscii <= Asc("F")) Then
    Else
        KeyAscii = 0
    End If
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -