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

📄 form1.frm

📁 人机交互软件片断
💻 FRM
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Form1 
   Caption         =   "数据采集"
   ClientHeight    =   5145
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   8835
   LinkTopic       =   "Form1"
   ScaleHeight     =   5145
   ScaleWidth      =   8835
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command4 
      Caption         =   "数据发送"
      Height          =   615
      Left            =   6000
      TabIndex        =   7
      Top             =   1560
      Width           =   1695
   End
   Begin VB.Frame Frame2 
      Caption         =   "发送数据"
      Height          =   2295
      Left            =   120
      TabIndex        =   5
      Top             =   120
      Width           =   5055
      Begin VB.TextBox Text2 
         Height          =   1695
         Left            =   120
         TabIndex        =   6
         Top             =   360
         Width           =   4575
      End
   End
   Begin VB.CommandButton Command3 
      Caption         =   "结束"
      Height          =   615
      Left            =   6000
      TabIndex        =   4
      Top             =   3600
      Width           =   1695
   End
   Begin MSCommLib.MSComm MSComm1 
      Left            =   5400
      Top             =   1800
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      DTREnable       =   -1  'True
   End
   Begin VB.CommandButton Command2 
      Caption         =   "数据采集"
      Height          =   615
      Left            =   6000
      TabIndex        =   3
      Top             =   2520
      Width           =   1695
   End
   Begin VB.Frame Frame1 
      Caption         =   "接受数据"
      Height          =   2295
      Left            =   120
      TabIndex        =   1
      Top             =   2640
      Width           =   5055
      Begin VB.TextBox Text1 
         Height          =   1815
         Left            =   240
         TabIndex        =   2
         Top             =   360
         Width           =   4575
      End
   End
   Begin VB.CommandButton Command1 
      Caption         =   "开始"
      Height          =   615
      Left            =   6000
      TabIndex        =   0
      Top             =   600
      Width           =   1695
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim jieshiou As Byte
Dim PortValue As Integer
Private Sub Command1_Click()

With MSComm1
           .CommPort = PortValue              '使用COM1
           .Settings = "9600,N,8,1"       '设置通信口参数
           .InBufferSize = 40
             '设置MSComm1接收缓冲区为40字节
           .OutBufferSize = 1
          
           .InputMode = comInputModeText
           
           '设置接收数据模式为二进制形式
           .InputLen = 1
           '设置Input 一次从接收缓冲读取字节数为1
           .SThreshold = 1
           '设置Output 一次从发送缓冲读取字节数为1
          ' .InBufferCount = 0  '清除接收缓冲区
           '.OutBufferCount = 0     '清除发送缓冲区
           .RThreshold = 1
           On Error Resume Next
        
           If .PortOpen = False Then
                  '判断通信口是否打开
                  
                  .PortOpen = True '打开通信
                  If Err Then        '错误处理
                     msg = MsgBox(" 串口 COM" & PortValue & " 无效! ", vbOKOnly, "警告")
                     Exit Sub
                  End If
           End If
End With
MsgBox "端口已打开"
End Sub

Private Sub Command2_Click()
Dim buffer$

         
          
       With MSComm1
            
             
                      buffer = .Input
                      
                      jieshou = buffer
                      Text1.Text = Text1.Text + Trim(buffer)
           
           
           
       End With
End Sub

Private Sub Command3_Click()
MSComm1.PortOpen = False
MsgBox "端口已关闭"
 Unload Me
 
End Sub

Private Sub Command4_Click()
MSComm1.Output = Trim(Text2.Text)
End Sub

Private Sub Form_Load()
PortValue = 1
End Sub

⌨️ 快捷键说明

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