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

📄 form1.frm

📁 通过串口接收单片机发给电脑的温度值,也可直接接收数据,可二次开发,源码全部上传,可自己修改
💻 FRM
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Begin VB.Form 接收温度值软件 
   Caption         =   "接收温度值软件"
   ClientHeight    =   5475
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   7755
   LinkTopic       =   "Form1"
   ScaleHeight     =   5475
   ScaleWidth      =   7755
   StartUpPosition =   3  '窗口缺省
   Begin VB.Frame 串口 
      Caption         =   "数据窗口"
      Height          =   3255
      Left            =   120
      TabIndex        =   12
      Top             =   2040
      Width           =   7455
      Begin VB.CommandButton Command1 
         Caption         =   "打开串口"
         Height          =   375
         Left            =   4560
         TabIndex        =   20
         Top             =   360
         Width           =   1215
      End
      Begin VB.TextBox txtValue 
         Height          =   375
         Left            =   3240
         MultiLine       =   -1  'True
         TabIndex        =   19
         Top             =   2520
         Width           =   2535
      End
      Begin VB.TextBox Text2 
         Height          =   375
         Left            =   240
         TabIndex        =   18
         Text            =   "01"
         Top             =   960
         Width           =   5535
      End
      Begin VB.CommandButton Command2 
         Caption         =   "发送数据"
         Enabled         =   0   'False
         Height          =   375
         Left            =   6120
         TabIndex        =   17
         Top             =   960
         Width           =   1215
      End
      Begin VB.CommandButton Command3 
         Caption         =   "关闭串口"
         CausesValidation=   0   'False
         Enabled         =   0   'False
         Height          =   375
         Left            =   6120
         TabIndex        =   16
         Top             =   360
         Width           =   1215
      End
      Begin VB.CommandButton Command6 
         Caption         =   "退出"
         Height          =   375
         Left            =   6120
         TabIndex        =   15
         Top             =   2520
         Width           =   1215
      End
      Begin VB.CommandButton Command7 
         Caption         =   "查询"
         Height          =   375
         Left            =   6120
         TabIndex        =   14
         Top             =   1920
         Width           =   1215
      End
      Begin VB.TextBox txtTime 
         Height          =   375
         Left            =   240
         TabIndex        =   13
         Top             =   2520
         Width           =   2535
      End
      Begin VB.Label Label1 
         Caption         =   "串口关闭..."
         Height          =   255
         Left            =   240
         TabIndex        =   24
         Top             =   480
         Width           =   3255
      End
      Begin VB.Label Label2 
         Caption         =   "接收数据..."
         Height          =   375
         Left            =   240
         TabIndex        =   23
         Top             =   1680
         Width           =   3015
      End
      Begin VB.Label Label8 
         Caption         =   "温度:"
         Height          =   255
         Left            =   3240
         TabIndex        =   22
         Top             =   2160
         Width           =   735
      End
      Begin VB.Label Label9 
         Caption         =   "时间:"
         Height          =   255
         Left            =   240
         TabIndex        =   21
         Top             =   2160
         Width           =   615
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "参数设置"
      Height          =   1575
      Left            =   120
      TabIndex        =   0
      Top             =   240
      Width           =   7455
      Begin VB.ComboBox Combo1 
         Height          =   300
         ItemData        =   "Form1.frx":0000
         Left            =   1080
         List            =   "Form1.frx":000A
         TabIndex        =   6
         Text            =   "COM1"
         Top             =   360
         Width           =   975
      End
      Begin VB.ComboBox Combo2 
         Height          =   300
         ItemData        =   "Form1.frx":001A
         Left            =   3600
         List            =   "Form1.frx":002D
         TabIndex        =   5
         Text            =   "2400"
         Top             =   360
         Width           =   1095
      End
      Begin VB.ComboBox Combo3 
         Height          =   300
         ItemData        =   "Form1.frx":0050
         Left            =   1080
         List            =   "Form1.frx":0060
         TabIndex        =   4
         Text            =   "8"
         Top             =   960
         Width           =   975
      End
      Begin VB.ComboBox Combo4 
         Height          =   300
         ItemData        =   "Form1.frx":0070
         Left            =   3600
         List            =   "Form1.frx":007D
         TabIndex        =   3
         Text            =   "N"
         Top             =   960
         Width           =   1095
      End
      Begin VB.ComboBox Combo5 
         Height          =   300
         ItemData        =   "Form1.frx":008A
         Left            =   6120
         List            =   "Form1.frx":0097
         TabIndex        =   2
         Text            =   "1"
         Top             =   960
         Width           =   1095
      End
      Begin VB.CommandButton Command4 
         Caption         =   "应用"
         Height          =   375
         Left            =   5760
         TabIndex        =   1
         Top             =   360
         Width           =   1455
      End
      Begin VB.Label Label3 
         Caption         =   "串口号:"
         Height          =   255
         Left            =   240
         TabIndex        =   11
         Top             =   480
         Width           =   735
      End
      Begin VB.Label Label4 
         Caption         =   "波特率:"
         Height          =   255
         Left            =   2640
         TabIndex        =   10
         Top             =   480
         Width           =   735
      End
      Begin VB.Label Label5 
         Caption         =   "数据位:"
         Height          =   255
         Left            =   240
         TabIndex        =   9
         Top             =   1080
         Width           =   735
      End
      Begin VB.Label Label6 
         Caption         =   "校验位:"
         Height          =   375
         Left            =   2640
         TabIndex        =   8
         Top             =   1080
         Width           =   735
      End
      Begin VB.Label Label7 
         Caption         =   "停止位:"
         Height          =   255
         Left            =   5160
         TabIndex        =   7
         Top             =   1080
         Width           =   855
      End
   End
   Begin MSAdodcLib.Adodc Adodc1 
      Height          =   330
      Left            =   6600
      Top             =   0
      Visible         =   0   'False
      Width           =   1200
      _ExtentX        =   2117
      _ExtentY        =   582
      ConnectMode     =   0
      CursorLocation  =   3
      IsolationLevel  =   -1
      ConnectionTimeout=   15
      CommandTimeout  =   30
      CursorType      =   3
      LockType        =   3
      CommandType     =   2
      CursorOptions   =   0
      CacheSize       =   50
      MaxRecords      =   0
      BOFAction       =   0
      EOFAction       =   0
      ConnectStringType=   1
      Appearance      =   1
      BackColor       =   -2147483643
      ForeColor       =   -2147483640
      Orientation     =   0
      Enabled         =   -1
      Connect         =   "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=alex.mdb;Persist Security Info=False"
      OLEDBString     =   "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=alex.mdb;Persist Security Info=False"
      OLEDBFile       =   ""
      DataSourceName  =   ""
      OtherAttributes =   ""
      UserName        =   ""
      Password        =   ""
      RecordSource    =   "TimeValue"
      Caption         =   "Adodc1"
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "宋体"
         Size            =   9
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      _Version        =   393216
   End
   Begin MSCommLib.MSComm MSComm1 
      Left            =   6000
      Top             =   0
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      DTREnable       =   -1  'True
      RThreshold      =   1
      BaudRate        =   2400
      SThreshold      =   1
   End
End
Attribute VB_Name = "接收温度值软件"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

  Dim conn As New ADODB.Connection
  Dim rs As New ADODB.Recordset
  
  Private Sub insert()
  conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=alex.mdb;Persist Security Info=False"
  conn.Open
  Dim str As String
  str = "insert into TimeValue(TheTime,TheValue) values('" & txtTime.Text & "','" & txtValue.Text & "')"
  conn.Execute str
  conn.Close
  End Sub


Private Sub Command1_Click()
Command1.Enabled = False
Command3.Enabled = True
Command2.Enabled = True
MSComm1.PortOpen = True
Label1.Caption = "串口已打开,等待发送..."
End Sub


Private Sub Command2_Click()
MSComm1.Output = Text2.Text
End Sub

Private Sub Command3_Click()
Command1.Enabled = True
Command3.Enabled = False
Command2.Enabled = False
    MSComm1.PortOpen = False
    Label1.Caption = "串口关闭..."

End Sub

Private Sub Command4_Click()
If MSComm1.PortOpen = True Then
         MSComm1.PortOpen = False

          If Combo1.Text = "COM1" Then
         MSComm1.CommPort = 1
         Else
          MSComm1.CommPort = 2
         End If
          MSComm1.Settings = Combo2.Text & "," & Combo4.Text & "," & Combo3.Text & "," & Combo5.Text

    MSComm1.PortOpen = True

Else
        
        If Combo1.Text = "COM1" Then
         MSComm1.CommPort = 1
         Else
          MSComm1.CommPort = 2
         End If
          MSComm1.Settings = Combo2.Text & "," & Combo4.Text & "," & Combo3.Text & "," & Combo5.Text
End If
End Sub

Private Sub Command5_Click()
txtWendu.Text = ""
txtTime = Now()
End Sub

Private Sub Command6_Click()
If MSComm1.PortOpen = True Then
   MSComm1.PortOpen = False
End If
Unload Me
End Sub

Private Sub Command7_Click()

Form2.Show

End Sub


Private Sub Form_Unload(Cancel As Integer)
If MSComm1.PortOpen = True Then
   MSComm1.PortOpen = False
End If
End Sub

Private Sub MSComm1_OnComm()
txtValue = MSComm1.Input
txtTime = Now
Call insert
End Sub

⌨️ 快捷键说明

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