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

📄 frmmain.frm

📁 监控类的开发
💻 FRM
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form frmMain 
   Caption         =   "串口数据收发测试"
   ClientHeight    =   2415
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   4680
   Icon            =   "frmMain.frx":0000
   LinkTopic       =   "Form1"
   ScaleHeight     =   2415
   ScaleWidth      =   4680
   StartUpPosition =   2  'CenterScreen
   Begin VB.Timer timer_COMM 
      Enabled         =   0   'False
      Interval        =   500
      Left            =   840
      Top             =   1320
   End
   Begin VB.CommandButton cmdClose 
      Caption         =   "关闭"
      Enabled         =   0   'False
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   1920
      TabIndex        =   6
      Top             =   1800
      Width           =   855
   End
   Begin VB.CommandButton cmdOpen 
      Caption         =   "打开"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   960
      TabIndex        =   5
      Top             =   1800
      Width           =   855
   End
   Begin MSCommLib.MSComm MSComm1 
      Left            =   240
      Top             =   1680
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      DTREnable       =   -1  'True
      RThreshold      =   1
   End
   Begin VB.TextBox txtSend 
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   960
      TabIndex        =   2
      Top             =   1080
      Width           =   3495
   End
   Begin VB.CommandButton cmdSend 
      Caption         =   "发送"
      Enabled         =   0   'False
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   3600
      TabIndex        =   1
      Top             =   1800
      Width           =   855
   End
   Begin VB.TextBox txtReceive 
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   960
      TabIndex        =   0
      Top             =   360
      Width           =   3495
   End
   Begin VB.Label Label2 
      Caption         =   "接收"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   240
      TabIndex        =   4
      Top             =   480
      Width           =   495
   End
   Begin VB.Label Label1 
      Caption         =   "发送"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   240
      TabIndex        =   3
      Top             =   1320
      Width           =   495
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim bStartComm As Boolean
Dim strInputAll As String

Private Sub cmdClose_Click()
    MSComm1.PortOpen = False
    cmdClose.Enabled = False
    cmdOpen.Enabled = True
    cmdSend.Enabled = False
End Sub

Private Sub cmdOpen_Click()
    MSComm1.PortOpen = True
    cmdOpen.Enabled = False
    cmdClose.Enabled = True
    cmdSend.Enabled = True
End Sub

Private Sub cmdSend_Click()
    MSComm1.Output = txtSend.Text
End Sub

Private Sub MSComm1_OnComm()
    Dim strInBuffer As String
      
    Select Case MSComm1.CommEvent
        'Events
        Case comEvReceive
            strInBuffer = MSComm1.Input
            If bStartComm = False Then
                bStartComm = True
                strInputAll = ""
            End If
            strInputAll = strInputAll + strInBuffer
            If bStartComm = True Then
                timer_COMM.Enabled = False
                timer_COMM.Enabled = True
            End If
        Case comEvSend
        Case comEvCTS
        Case comEvDSR
        Case comEvCD
        Case comEvRing
                
        ' Errors
        Case comEventBreak
        Case comEventCDTO
        Case comEventCTSTO
        Case comEventDSRTO
        Case comEventFrame
        Case comEventOverrun
        Case comEventRxOver
        Case comEventRxParity
        Case comEventTxFull
        Case comEventDCB
    End Select
End Sub

Private Sub timer_COMM_Timer()
    timer_COMM.Enabled = False
    bStartComm = False
    txtReceive.Text = strInputAll
End Sub

⌨️ 快捷键说明

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