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

📄 上位机.frm

📁 这段代码是关于用凌阳采集温度、并显示在数码管上的程序。
💻 FRM
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Form1 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "上位机"
   ClientHeight    =   5505
   ClientLeft      =   2490
   ClientTop       =   2385
   ClientWidth     =   7380
   ClipControls    =   0   'False
   DrawStyle       =   5  'Transparent
   BeginProperty Font 
      Name            =   "仿宋_GB2312"
      Size            =   9
      Charset         =   134
      Weight          =   700
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   5505
   ScaleWidth      =   7380
   Begin VB.CommandButton Command2 
      Caption         =   "停止采集"
      BeginProperty Font 
         Name            =   "仿宋_GB2312"
         Size            =   9
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   6000
      TabIndex        =   4
      Top             =   1920
      Width           =   1095
   End
   Begin VB.CommandButton Command1 
      Caption         =   "刷新"
      BeginProperty Font 
         Name            =   "仿宋_GB2312"
         Size            =   9
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   4440
      TabIndex        =   3
      Top             =   1920
      Width           =   1095
   End
   Begin VB.PictureBox Picture1 
      Align           =   2  'Align Bottom
      BackColor       =   &H00FFFFC0&
      DrawWidth       =   2
      FillColor       =   &H00FFFFFF&
      ForeColor       =   &H000000FF&
      Height          =   3135
      Left            =   0
      MousePointer    =   4  'Icon
      ScaleHeight     =   3075
      ScaleWidth      =   7320
      TabIndex        =   1
      ToolTipText     =   "温度曲线"
      Top             =   2370
      Width           =   7380
   End
   Begin VB.Timer Timer1 
      Interval        =   500
      Left            =   4680
      Top             =   360
   End
   Begin MSCommLib.MSComm MSComm1 
      Left            =   3360
      Top             =   360
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      CommPort        =   2
      DTREnable       =   -1  'True
      RThreshold      =   3
      InputMode       =   1
   End
   Begin VB.Label Label2 
      Caption         =   "在区间20到50摄氏度的范围内画温度波浪线"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   10.5
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   0
      TabIndex        =   2
      Top             =   2040
      Width           =   4335
   End
   Begin VB.Label Label1 
      Caption         =   "当前温度为:"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   21.75
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H000000FF&
      Height          =   615
      Left            =   840
      TabIndex        =   0
      Top             =   600
      Width           =   6375
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Const mm As Integer = 320

Dim temp() As Byte
Dim flag As Integer
Dim wd As Double
Dim buf As String
Dim t As Boolean
Dim x As Integer
Dim te(1 To mm) As Double



Private Sub Command1_Click()
 x = 1
       Picture1.Cls
       t = False
       
End Sub



Private Sub Form_GotFocus()
Picture1.Refresh

End Sub

Private Sub Form_Load()
MSComm1.PortOpen = True
Picture1.Scale (0, 101)-(280, 40)
Picture1.ForeColor = RGB(255, 0, 0)
t = False
x = 1
End Sub

Private Sub Form_Unload(Cancel As Integer)
MSComm1.PortOpen = False

End Sub

Private Sub MSComm1_OnComm()
Dim n As Integer
If MSComm1.CommEvent = comEvReceive Then
  temp = MSComm1.Input
  If Hex(temp(0)) <> Hex(255) Then
       Label1.Caption = "上位机没有收到温度数据!!!"
  Else
     For i = 0 To 255
       If Hex(temp(1)) = Hex(i) Then
            wd = i
            Exit For
       End If
    Next
    For i = 0 To 255
      If Hex(temp(2)) = Hex(i) Then
         wd = wd + i / 100
         Label1.Caption = "当前温度为: " + Str(wd) + " 摄氏度"
         te(x) = wd
         Exit For
      End If
    Next
    Picture1.Cls
    For n = 1 To x
      If n = 1 Then
         
         Picture1.PSet (n, te(n) * 2)
         t = True
      Else
         Picture1.Line -(n, te(n) * 2)
      End If
   Next
   If x > 280 Then
          x = 1
          Picture1.Cls
          t = False
   Else
          x = x + 1
   End If
   
End If
End If
End Sub


Private Sub Timer1_Timer()
Form1.Caption = Str(Year(Date)) + "年" + Str(Month(Date)) + "月" + Str(Day(Date)) + "日 " + Str(Time()) + " 时的温度:"
End Sub

⌨️ 快捷键说明

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