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

📄 pc&pc.frm

📁 PC机与PC机串口通信,PC机与PC机串口通信,
💻 FRM
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form COMForm 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "PC机与PC机串口通信"
   ClientHeight    =   2985
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   6330
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   2985
   ScaleWidth      =   6330
   ShowInTaskbar   =   0   'False
   StartUpPosition =   3  '窗口缺省
   Begin MSCommLib.MSComm MSComm1 
      Left            =   5670
      Top             =   2310
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      DTREnable       =   -1  'True
   End
   Begin VB.Timer Timer1 
      Enabled         =   0   'False
      Interval        =   500
      Left            =   4830
      Top             =   2415
   End
   Begin VB.CommandButton Cmdquit 
      Caption         =   "关闭程序"
      Height          =   330
      Left            =   2640
      TabIndex        =   5
      Top             =   2520
      Width           =   1035
   End
   Begin VB.CommandButton Cmdauto 
      Caption         =   "自动接收"
      Height          =   330
      Left            =   2640
      TabIndex        =   4
      Top             =   1995
      Width           =   1035
   End
   Begin VB.CommandButton CmdReceive 
      Caption         =   "接收字符"
      Height          =   330
      Left            =   4515
      TabIndex        =   3
      Top             =   1995
      Width           =   1035
   End
   Begin VB.CommandButton Cmdsend 
      Caption         =   "发送字符"
      Height          =   330
      Left            =   930
      TabIndex        =   2
      Top             =   1995
      Width           =   1035
   End
   Begin VB.TextBox TextReceive 
      Height          =   1320
      Left            =   3270
      MultiLine       =   -1  'True
      ScrollBars      =   2  'Vertical
      TabIndex        =   1
      Top             =   420
      Width           =   3015
   End
   Begin VB.TextBox Textsend 
      Height          =   1320
      Left            =   30
      MultiLine       =   -1  'True
      ScrollBars      =   2  'Vertical
      TabIndex        =   0
      Top             =   450
      Width           =   3015
   End
   Begin VB.Label Label2 
      BackStyle       =   0  'Transparent
      Caption         =   "显示接收字符区:"
      Height          =   195
      Left            =   3300
      TabIndex        =   7
      Top             =   180
      Width           =   2415
   End
   Begin VB.Label Label1 
      BackStyle       =   0  'Transparent
      Caption         =   "输入发送字符区:"
      Height          =   195
      Left            =   60
      TabIndex        =   6
      Top             =   180
      Width           =   1695
   End
End
Attribute VB_Name = "COMForm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'串口初始化
Private Sub Form_Load()
  MSComm1.CommPort = 1                 '设置通信端口号为COM1
  MSComm1.Settings = "9600,n,8,1"      '设置串口参数
  MSComm1.InputMode = 0                '接收文本型数据
End Sub
'打开通信端口
'把字符通过串口发送出去
Private Sub Cmdsend_Click()
  If MSComm1.PortOpen = False Then MSComm1.PortOpen = True
  MSComm1.Output = Trim(Textsend.Text)
End Sub
Private Sub CmdReceive_Click()
  Dim buf$
  Timer1.Enabled = False
  buf = Trim(MSComm1.Input)      '将缓冲区内的数据读入buf变量中
  If Len(buf) = 0 Then           '判断缓冲区内是否存在数据
    TextReceive.Text = ""
  Else
    TextReceive.Text = buf
  End If
End Sub
'启动定时器
'进入自动接收模式
Private Sub Cmdauto_Click()
  Timer1.Enabled = True
End Sub
'定时自动从输入缓冲区读取字符
Private Sub Timer1_Timer()
  If MSComm1.InBufferCount > 0 Then
    TextReceive.Text = TextReceive.Text + MSComm1.Input
  End If
End Sub
'关闭通信端口,停止程序运行
Private Sub Cmdquit_Click()
  MSComm1.PortOpen = False
  End
End Sub


⌨️ 快捷键说明

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