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

📄 vbwenben.frm

📁 VB窗口界面 支持自发自收 二进制传输 毕业设计有用哦
💻 FRM
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Form1 
   Caption         =   "VB串行数据传送(文本)"
   ClientHeight    =   5040
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   8700
   LinkTopic       =   "Form1"
   ScaleHeight     =   5040
   ScaleWidth      =   8700
   StartUpPosition =   3  '窗口缺省
   Begin MSCommLib.MSComm Comm1 
      Left            =   8040
      Top             =   1080
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      DTREnable       =   -1  'True
   End
   Begin VB.CommandButton Comquit 
      Caption         =   "退出"
      Height          =   375
      Left            =   7560
      TabIndex        =   9
      Top             =   120
      Width           =   975
   End
   Begin VB.Frame Frame1 
      Caption         =   "通讯设置"
      Height          =   2775
      Left            =   4680
      TabIndex        =   8
      Top             =   1920
      Width           =   3735
      Begin VB.CommandButton Command4 
         Caption         =   "修改"
         Height          =   375
         Left            =   1200
         TabIndex        =   13
         Top             =   2160
         Width           =   1215
      End
      Begin VB.ComboBox Verify_combo 
         Height          =   300
         Left            =   2280
         TabIndex        =   12
         Text            =   "N,无校验"
         Top             =   1680
         Width           =   975
      End
      Begin VB.ComboBox Baud_combo 
         Height          =   300
         Left            =   2280
         TabIndex        =   11
         Text            =   "9600"
         Top             =   960
         Width           =   975
      End
      Begin VB.ComboBox Port_combo 
         Height          =   300
         Left            =   2280
         TabIndex        =   10
         Text            =   "1"
         Top             =   360
         Width           =   975
      End
      Begin VB.Label Label14 
         Caption         =   "Label14"
         Height          =   255
         Left            =   960
         TabIndex        =   23
         Top             =   1680
         Width           =   975
      End
      Begin VB.Label Label13 
         Caption         =   "Label13"
         Height          =   255
         Left            =   960
         TabIndex        =   22
         Top             =   960
         Width           =   735
      End
      Begin VB.Label Label12 
         Caption         =   "Label12"
         Height          =   255
         Left            =   960
         TabIndex        =   21
         Top             =   360
         Width           =   615
      End
      Begin VB.Label Label11 
         Caption         =   "校验方式"
         Height          =   255
         Left            =   120
         TabIndex        =   20
         Top             =   1680
         Width           =   735
      End
      Begin VB.Label Label10 
         Caption         =   "波特率"
         Height          =   255
         Left            =   240
         TabIndex        =   19
         Top             =   960
         Width           =   735
      End
      Begin VB.Label Label9 
         Caption         =   "串口号"
         Height          =   255
         Left            =   240
         TabIndex        =   18
         Top             =   360
         Width           =   735
      End
   End
   Begin VB.CommandButton ComClear 
      Caption         =   "清空接收数据区"
      Height          =   375
      Left            =   2880
      TabIndex        =   6
      Top             =   1440
      Width           =   1695
   End
   Begin VB.CommandButton ComSend 
      Caption         =   "发送"
      Height          =   375
      Left            =   2880
      TabIndex        =   5
      Top             =   960
      Width           =   1695
   End
   Begin VB.TextBox TextSend 
      Height          =   375
      Left            =   240
      TabIndex        =   3
      Text            =   "Text1"
      Top             =   960
      Width           =   2415
   End
   Begin VB.ListBox List1 
      Height          =   2760
      Left            =   240
      TabIndex        =   1
      Top             =   1920
      Width           =   3855
   End
   Begin VB.Label Label8 
      AutoSize        =   -1  'True
      Caption         =   "Label8"
      Height          =   180
      Left            =   6600
      TabIndex        =   17
      Top             =   1440
      Width           =   540
   End
   Begin VB.Label Label7 
      AutoSize        =   -1  'True
      Caption         =   "Label7"
      Height          =   180
      Left            =   6600
      TabIndex        =   16
      Top             =   1080
      Width           =   540
   End
   Begin VB.Label Label6 
      AutoSize        =   -1  'True
      Caption         =   "已接收数据个数:"
      Height          =   180
      Left            =   5160
      TabIndex        =   15
      Top             =   1440
      Width           =   1350
   End
   Begin VB.Label Label5 
      AutoSize        =   -1  'True
      Caption         =   "已发送数据个数:"
      Height          =   180
      Left            =   5160
      TabIndex        =   14
      Top             =   1080
      Width           =   1350
   End
   Begin VB.Label Label4 
      AutoSize        =   -1  'True
      Caption         =   "模拟接收到的数据"
      Height          =   180
      Left            =   240
      TabIndex        =   7
      Top             =   1680
      Width           =   1440
   End
   Begin VB.Label Label3 
      AutoSize        =   -1  'True
      Caption         =   "输入要发送的数据:"
      Height          =   180
      Left            =   240
      TabIndex        =   4
      Top             =   720
      Width           =   1530
   End
   Begin VB.Label Label2 
      AutoSize        =   -1  'True
      Caption         =   "张望 070120041"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   315
      Left            =   3000
      TabIndex        =   2
      Top             =   480
      Width           =   1770
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "VB串行数据传送实验(文本方式)"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   15.75
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   420
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   4815
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim Sj(300) As Integer
Dim Nrece As Integer

Sub Port_init()
Dim Port_no As Integer
Dim Baud_rate As String
Dim Verify As String    '
Dim Temp As String      '
On Error GoTo Port_error '
Nrece = 0
If Comm1.PortOpen = True Then Comm1.PortOpen = False

Open "G:\ComSet.TXT" For Input As #1
Input #1, Port_no
Label12.Caption = Port_no

Input #1, Baud_rate
Label13.Caption = Baud_rate

Line Input #1, Verify
Label14.Caption = Verify

Comm1.CommPort = Port_no
Temp = Baud_rate & "," & Left(Verify, 1) + ",8,1"
Comm1.Settings = Temp
Close #1
If Comm1.PortOpen = False Then Comm1.PortOpen = True
Exit Sub

Port_error:
If Comm1.PortOpen = True Then Comm1.PortOpen = False
MsgBox ("选择的串口通讯错误!")
Command4.Caption = "确认"
Port_combo.Enabled = True
Baud_combo.Enabled = True
Verify_combo.Enabled = True

End Sub


Sub Comset()
Label12.Caption = Port_combo.Text
Label13.Caption = Baud_combo.Text
Label14.Caption = Verify_combo.Text
Open "G:\ComSet.txt" For Output As #1
Print #1, Label12.Caption
Print #1, Label13.Caption
Print #1, Label14.Caption
Close #1

Call Port_init

End Sub
Sub Delay(Ti)
Dim T1, De
T1 = Timer
Do While Timer - T1 < Ti
De = DoEvents()
Loop
End Sub

Private Sub ComClear_Click()
Nrece = 0
Label8.Caption = Nrece
List1.Clear
End Sub

Private Sub Command4_Click()
If Command4.Caption = "修改" Then
   Command4.Caption = "确认"
   Port_combo.Enabled = True
   Baud_combo.Enabled = True
   Verify_combo.Enabled = True
Else
   Command4.Caption = "修改"
   Port_combo.Enabled = False
   Baud_combo.Enabled = False
   Verify_combo.Enabled = False
   Call Comset
End If
End Sub



Private Sub ComSend_Click()
Dim N As Integer, I As Integer
Frame1.Enabled = False
N = Len(TextSend.Text)
For I = 1 To N
Comm1.Output = Mid(TextSend.Text, I, 1)
Call Delay(0.01)
Next I
Frame1.Enabled = True
End Sub

Private Sub Comm1_OnComm()
Dim Buf$

 Select Case Comm1.CommEvent
    Case comEvReceive
      Do While (Comm1.InBufferCount > 0)
           Buf = Comm1.Input
            Nrece = Nrece + 1
            If Nrece > 256 Then
               Nrece = 1
               List1.Clear
            End If
            Label8.Caption = Nrece
            Sj(Nrece) = Val(Buf)
            List1.AddItem Buf
      Loop
 End Select
Form1.Refresh
End Sub
Private Sub Comquit_Click()
End
End Sub

Private Sub Form_Load()
Call Port_init
End Sub

⌨️ 快捷键说明

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