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

📄 form1.frm

📁 vb6.0做的RS232做数字输入的串口编程例子
💻 FRM
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   3255
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   6810
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   ScaleHeight     =   3255
   ScaleWidth      =   6810
   StartUpPosition =   3  'Windows Default
   Begin MSCommLib.MSComm MSComm1 
      Left            =   180
      Top             =   1035
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      CommPort        =   2
      DTREnable       =   -1  'True
   End
   Begin VB.CommandButton cmdEnd 
      Caption         =   "结束系统"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   840
      Left            =   3750
      TabIndex        =   5
      Top             =   1590
      Width           =   1620
   End
   Begin VB.CommandButton cmdStart 
      Caption         =   "激活检测"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   840
      Left            =   1140
      TabIndex        =   4
      Top             =   1590
      Width           =   1620
   End
   Begin VB.Timer Timer1 
      Enabled         =   0   'False
      Interval        =   100
      Left            =   210
      Top             =   465
   End
   Begin VB.Label lblMsg 
      BackColor       =   &H0080FFFF&
      BorderStyle     =   1  'Fixed Single
      Caption         =   "Label2"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   360
      Left            =   90
      TabIndex        =   6
      Top             =   2775
      Width           =   6735
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "RI"
      BeginProperty Font 
         Name            =   "PMingLiU"
         Size            =   12
         Charset         =   136
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   240
      Index           =   3
      Left            =   5160
      TabIndex        =   3
      Top             =   120
      Width           =   225
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "DSR"
      BeginProperty Font 
         Name            =   "PMingLiU"
         Size            =   12
         Charset         =   136
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   240
      Index           =   2
      Left            =   3800
      TabIndex        =   2
      Top             =   135
      Width           =   435
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "CTS"
      BeginProperty Font 
         Name            =   "PMingLiU"
         Size            =   12
         Charset         =   136
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   240
      Index           =   1
      Left            =   2470
      TabIndex        =   1
      Top             =   120
      Width           =   405
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "DCD"
      BeginProperty Font 
         Name            =   "PMingLiU"
         Size            =   12
         Charset         =   136
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   240
      Index           =   0
      Left            =   1065
      TabIndex        =   0
      Top             =   120
      Width           =   480
   End
   Begin VB.Shape spRI 
      FillColor       =   &H00FFFFFF&
      FillStyle       =   0  'Solid
      Height          =   645
      Left            =   4980
      Shape           =   3  'Circle
      Top             =   465
      Width           =   675
   End
   Begin VB.Shape spDSR 
      FillColor       =   &H00FFFFFF&
      FillStyle       =   0  'Solid
      Height          =   645
      Left            =   3655
      Shape           =   3  'Circle
      Top             =   465
      Width           =   675
   End
   Begin VB.Shape spCTS 
      FillColor       =   &H00FFFFFF&
      FillStyle       =   0  'Solid
      Height          =   645
      Left            =   2330
      Shape           =   3  'Circle
      Top             =   465
      Width           =   675
   End
   Begin VB.Shape spDCD 
      FillColor       =   &H00FFFFFF&
      FillStyle       =   0  'Solid
      Height          =   645
      Left            =   1005
      Shape           =   3  'Circle
      Top             =   465
      Width           =   675
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
''''''''''''''''''''''''''''''''''''''
'使用按钮控件
'关闭通信端口
'结束系统
''''''''''''''''''''''''''''''''''''''
Private Sub cmdEnd_Click()
  MSComm1.PortOpen = False
  End
End Sub

''''''''''''''''''''''''''''''''''''''
'命令按钮控件的鼠标移动事件
'提示一个信息以便于使用者了解
'将信息显示指示到Label控件
''''''''''''''''''''''''''''''''''''''
Private Sub cmdEnd_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  lblMsg.Caption = "按下此键可结束本系统!"
End Sub

''''''''''''''''''''''''''''''''''''''
'命令按钮控件
'用以将定时器的激活/关闭作一个切换
''''''''''''''''''''''''''''''''''''''
Private Sub cmdStart_Click()
  Timer1.Enabled = Not Timer1.Enabled '定时器的开关
  If Timer1.Enabled Then '改变显示的标题
    cmdStart.Caption = "停止检测"
  Else
    cmdStart.Caption = "激活检测"
  End If
End Sub

''''''''''''''''''''''''''''''''''''''
'命令按钮控件的鼠标移动事件
'提示一个信息以便于使用者了解
'将信息显示指示到Label控件
''''''''''''''''''''''''''''''''''''''
Private Sub cmdStart_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  If Timer1.Enabled Then
    lblMsg.Caption = "按下此键便可终止检测的工作!"
  Else
    lblMsg.Caption = "按下此键便可开始检测的工作!"
  End If
End Sub

''''''''''''''''''''''''''''''''''''''
'窗体加载事件
'打开串行通信端口
''''''''''''''''''''''''''''''''''''''
Private Sub Form_Load()
    MSComm1.PortOpen = True
End Sub

''''''''''''''''''''''''''''''''''''''
'定时器控件的Timer事件
'每隔一个固定的时间会激活一次事件程序内的程序代码
'在此则是检查电压状态,并响应到Shape的填满颜色
''''''''''''''''''''''''''''''''''''''
Private Sub Timer1_Timer()
    If MSComm1.CDHolding Then               '检测DCD脚位电位

⌨️ 快捷键说明

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