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

📄 formok.frm

📁 一个简单的VB串口收发程序
💻 FRM
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MsComm32.ocx"
Begin VB.Form Form1 
   Caption         =   "RS232_VB"
   ClientHeight    =   4005
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   4005
   ScaleWidth      =   4680
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Button_RECV 
      Caption         =   "接收数据"
      Height          =   495
      Left            =   480
      TabIndex        =   7
      Top             =   3000
      Width           =   1455
   End
   Begin VB.Timer Timer1 
      Left            =   3840
      Top             =   240
   End
   Begin MSCommLib.MSComm MSComm 
      Left            =   3840
      Top             =   840
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      DTREnable       =   -1  'True
   End
   Begin VB.CommandButton Button_RECV_C 
      Caption         =   "清空接收文本框"
      Height          =   495
      Left            =   2400
      TabIndex        =   6
      Top             =   3000
      Width           =   1455
   End
   Begin VB.TextBox Text_RECV 
      Height          =   375
      Left            =   2040
      TabIndex        =   5
      Text            =   "Text2"
      Top             =   2160
      Width           =   1575
   End
   Begin VB.CommandButton Button_SEND_C 
      Caption         =   "清空发送数据"
      Height          =   495
      Left            =   2040
      TabIndex        =   3
      Top             =   1320
      Width           =   1695
   End
   Begin VB.CommandButton Button_SEND 
      Caption         =   "发送数据"
      CausesValidation=   0   'False
      Height          =   495
      Left            =   480
      TabIndex        =   2
      Top             =   1320
      Width           =   1335
   End
   Begin VB.TextBox Text_SEND 
      Height          =   375
      Left            =   1560
      TabIndex        =   1
      Text            =   "Text1"
      Top             =   360
      Width           =   1815
   End
   Begin VB.Label Label2 
      Caption         =   "接收数据"
      Height          =   255
      Left            =   600
      TabIndex        =   4
      Top             =   2280
      Width           =   855
   End
   Begin VB.Label Label1 
      Caption         =   "发送数据"
      Height          =   255
      Left            =   360
      TabIndex        =   0
      Top             =   480
      Width           =   855
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Button_RECV_C_Click()
Text_RECV.Text = ""
Text_SEND.SetFocus
End Sub

Private Sub Button_RECG_C_Click()

End Sub

Private Sub Button_SEND_C_Click()
Text_SEND.Text = ""
Text_SEND.SetFocus
End Sub

Private Sub Button_SEND_Click()

Dim x As String

If Text_SEND.Text = "" Then
 x = MsgBox("发送数据不能空", 16)
 Exit Sub
 End If
 If Not MSComm.PortOpen = True Then
 End If
   MSComm.Output = Text_SEND.Text + Chr$(13)
   For i = 1 To 20000000
   Next
End Sub

Private Sub Command1_Click()

End Sub

Private Sub Form_Load()
MSComm.CommPort = 1
MSComm.Settings = "2400,N,8,1"
MSComm.InputLen = 0
MSComm.InBufferSize = 1024
MSComm.OutBufferSize = 512
MSComm.PortOpen = True
MSComm.SThreshold = 0
MSComm.RThreshold = 1
MSComm.InBufferCount = 0
MSComm.OutBufferCount = 0
Me.Caption = Now()


Text_SEND.Text = ""
Text_RECV.Text = ""
End Sub


Private Sub Label1_Click()
Me.Caption = Now()
End Sub

Private Sub MSComm_OnComm()
  Select Case MSComm.CommEvent
       Case comEventOverrun
            Text_SEND.Text = ""
            Text_RECV.Text = ""
            Text_SEND.SetFocus
            Exit Sub
       Case comEventRxOver
            Text_SEND.Text = ""
            Text_RECV.Text = ""
            Text_SEND.SetFocus
            Exit Sub
       Case comEventTxFull
            Text_SEND.Text = ""
            Text_RECV.Text = ""
            Text_SEND.SetFocus
            Exit Sub
       Case comEvReceive
            Dim str As String
            str = MSComm.Input
            Text_RECV.Text = Text_RECV.Text + str
   End Select
End Sub

Private Sub Timer1_Timer()
Me.Caption = Now()
End Sub

⌨️ 快捷键说明

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