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

📄 form1.frm

📁 PC机与单片机的串口通信程序
💻 FRM
📖 第 1 页 / 共 2 页
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Form1 
   Caption         =   "串口通讯程序"
   ClientHeight    =   5550
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   7170
   Icon            =   "Form1.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   5550
   ScaleWidth      =   7170
   StartUpPosition =   2  '屏幕中心
   Begin VB.Timer Timer2 
      Left            =   4920
      Top             =   4800
   End
   Begin VB.Timer Timer1 
      Left            =   4920
      Top             =   4200
   End
   Begin VB.CommandButton MoreOption 
      Caption         =   "高级选项>>>"
      Height          =   375
      Left            =   3240
      TabIndex        =   28
      Top             =   4200
      Width           =   1215
   End
   Begin VB.CommandButton Reset 
      Caption         =   "重  置"
      Height          =   375
      Left            =   3240
      TabIndex        =   26
      Top             =   4680
      Width           =   1215
   End
   Begin VB.CommandButton Clearfile 
      Caption         =   "清数据文件"
      Height          =   375
      Left            =   5640
      TabIndex        =   25
      Top             =   4200
      Width           =   1215
   End
   Begin VB.Frame Frame3 
      Caption         =   "监视窗口"
      Height          =   2655
      Left            =   4440
      TabIndex        =   23
      Top             =   1320
      Width           =   2535
      Begin VB.Label Label8 
         Height          =   1575
         Left            =   120
         TabIndex        =   24
         Top             =   360
         Width           =   2295
      End
   End
   Begin VB.Frame Frame2 
      Caption         =   "参数设置"
      Height          =   2655
      Left            =   360
      TabIndex        =   16
      Top             =   1320
      Width           =   3975
      Begin VB.TextBox Text4 
         Height          =   375
         Left            =   2160
         MaxLength       =   1
         TabIndex        =   0
         Text            =   "2"
         Top             =   240
         Width           =   1215
      End
      Begin VB.TextBox Text1 
         Height          =   375
         Left            =   2160
         MaxLength       =   4
         TabIndex        =   1
         Text            =   "0100"
         Top             =   840
         Width           =   1215
      End
      Begin VB.TextBox Text2 
         Height          =   375
         Left            =   2160
         MaxLength       =   2
         TabIndex        =   2
         Text            =   "4"
         Top             =   1440
         Width           =   1215
      End
      Begin VB.TextBox Text3 
         BeginProperty DataFormat 
            Type            =   0
            Format          =   "0"
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   2052
            SubFormatType   =   0
         EndProperty
         Height          =   375
         Left            =   2160
         MaxLength       =   5
         TabIndex        =   3
         Text            =   "50"
         Top             =   2040
         Width           =   1215
      End
      Begin VB.Label Label11 
         Caption         =   "通道数"
         Height          =   255
         Left            =   120
         TabIndex        =   27
         Top             =   360
         Width           =   1095
      End
      Begin VB.Label Label5 
         Caption         =   "每次采集数据长度"
         Height          =   255
         Left            =   120
         TabIndex        =   22
         Top             =   960
         Width           =   1695
      End
      Begin VB.Label Label6 
         Caption         =   "数字滤波长度"
         Height          =   255
         Left            =   120
         TabIndex        =   21
         Top             =   1440
         Width           =   1695
      End
      Begin VB.Label Label7 
         Caption         =   "采集数据延时长度"
         Height          =   255
         Left            =   120
         TabIndex        =   20
         Top             =   2040
         Width           =   1695
      End
      Begin VB.Label Label9 
         Caption         =   "H"
         Height          =   375
         Left            =   3480
         TabIndex        =   19
         Top             =   960
         Width           =   255
      End
      Begin VB.Label Label10 
         Caption         =   "H"
         Height          =   375
         Left            =   3480
         TabIndex        =   18
         Top             =   1560
         Width           =   255
      End
      Begin VB.Label Label12 
         Caption         =   "mS"
         Height          =   255
         Left            =   3480
         TabIndex        =   17
         Top             =   2160
         Width           =   375
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "选择端口"
      Height          =   855
      Left            =   360
      TabIndex        =   13
      Top             =   240
      Width           =   2055
      Begin VB.OptionButton Option2 
         Caption         =   "COM2"
         Height          =   255
         Left            =   1080
         TabIndex        =   15
         Top             =   360
         Width           =   855
      End
      Begin VB.OptionButton Option1 
         Caption         =   "COM1"
         Height          =   255
         Left            =   120
         TabIndex        =   14
         Top             =   360
         Value           =   -1  'True
         Width           =   975
      End
   End
   Begin VB.CommandButton SetPrefer 
      Caption         =   "设置参数"
      Height          =   375
      Left            =   1800
      TabIndex        =   5
      Top             =   4200
      Width           =   1215
   End
   Begin VB.CommandButton ShakeHand 
      Caption         =   "握  手"
      Height          =   375
      Left            =   360
      TabIndex        =   4
      Top             =   4200
      Width           =   1215
   End
   Begin VB.CommandButton Stop 
      Caption         =   "停  止"
      Height          =   375
      Left            =   1800
      TabIndex        =   7
      Top             =   4680
      Width           =   1215
   End
   Begin VB.CommandButton Start 
      Caption         =   "开  始"
      Height          =   375
      Left            =   360
      TabIndex        =   6
      Top             =   4680
      Width           =   1215
   End
   Begin MSCommLib.MSComm Comm1 
      Left            =   6600
      Top             =   120
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      DTREnable       =   -1  'True
      InputMode       =   1
   End
   Begin VB.CommandButton Quit 
      Caption         =   "退出程序"
      Height          =   375
      Left            =   5640
      TabIndex        =   9
      Top             =   4680
      Width           =   1215
   End
   Begin VB.Label Label4 
      Height          =   255
      Left            =   4200
      TabIndex        =   12
      Top             =   840
      Width           =   2415
   End
   Begin VB.Label Label3 
      Caption         =   "系统设置:"
      Height          =   255
      Left            =   2880
      TabIndex        =   11
      Top             =   840
      Width           =   975
   End
   Begin VB.Label Label2 
      Height          =   255
      Left            =   4200
      TabIndex        =   10
      Top             =   360
      Width           =   2415
   End
   Begin VB.Label Label1 
      Caption         =   "当前状态:"
      Height          =   255
      Left            =   2880
      TabIndex        =   8
      Top             =   360
      Width           =   975
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public Option_Num As Integer
Public Option_Content As Integer
Dim Time_Len As Integer
Dim DataLen1 As Integer
Dim OKLabel As Boolean
Dim GetData As Boolean
Dim Stoplabel As Boolean
Dim RuningState As Boolean
Dim Tnum() As Integer
Dim Rounds As Integer

Private Sub Comm1_OnComm()
    Dim OutByte() As Byte
    Dim InByte() As Byte
    Dim inBuffLen As Integer
    Dim FileName As String
    Dim Sum As Long
   
    Dim Temp2() As Byte
    
    inBuffLen = Comm1.InputLen
    ReDim InByte(0 To inBuffLen) As Byte
    InByte = Comm1.Input
    Comm1.OutBufferCount = 0

    If GetData = True Then
        Label8.Caption = ""
        FileName = "data" & CStr(InByte(0)) & ".txt"
        Sum = 0
        Label2.Caption = "正在接收通道" & CStr(InByte(0)) & "的数据!"
        For i = 3 To inBuffLen - 2
            Sum = Sum + InByte(i)
        Next i
        Sum = Sum Mod 256
        ReDim OutByte(0 To 0) As Byte
        If Sum = InByte(inBuffLen - 1) Then
            Label8.Caption = ""
            For i = 0 To Rounds - 1
                If i = InByte(0) Then
                    Tnum(i) = Tnum(i) + 1
                End If
            Label8.Caption = Label8.Caption & "通道" & CStr(i) & "接收到数据:" & CStr(Tnum(i)) & "帧" & Chr(13)
            Next i
            OutByte(0) = &H0
            Comm1.Output = OutByte
            Open FileName For Append As #1
            Print #1, Hex(InByte(0)), Hex(InByte(2)); Hex(InByte(1))
            Label2.Caption = "正在写文件:" & FileName
            For i = 3 To inBuffLen - 1
                Print #1, Hex(InByte(i)); " ";
            Next i
            Print #1, " "
            Close 1
            
            If InByte(0) = Rounds - 1 Then
                If Option_Num = 2 And Tnum(0) = Option_Content Then
                    ReDim OutByte(0 To 1) As Byte

⌨️ 快捷键说明

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