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

📄 form1.frm

📁 与单片机接通,实时获得室内温度和湿度数据的程序.
💻 FRM
字号:
VERSION 5.00
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   5145
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   7665
   LinkMode        =   1  'Source
   LinkTopic       =   "vb"
   ScaleHeight     =   5145
   ScaleWidth      =   7665
   StartUpPosition =   3  '窗口缺省
   Begin VB.TextBox port 
      Height          =   270
      Left            =   600
      TabIndex        =   9
      Top             =   1440
      Width           =   975
   End
   Begin VB.TextBox ip 
      Height          =   270
      Left            =   600
      TabIndex        =   7
      Top             =   720
      Width           =   1695
   End
   Begin VB.TextBox Text3 
      Height          =   375
      Left            =   480
      TabIndex        =   3
      Top             =   3720
      Width           =   2775
   End
   Begin MSWinsockLib.Winsock ws 
      Left            =   3720
      Top             =   480
      _ExtentX        =   741
      _ExtentY        =   741
      _Version        =   393216
   End
   Begin VB.CommandButton Command1 
      Caption         =   "连接"
      Height          =   615
      Left            =   4560
      TabIndex        =   2
      Top             =   1080
      Width           =   1815
   End
   Begin VB.TextBox Text2 
      Height          =   375
      Left            =   4560
      LinkItem        =   "Text2"
      TabIndex        =   1
      Top             =   3600
      Width           =   735
   End
   Begin VB.TextBox Text1 
      Height          =   375
      Left            =   4560
      LinkItem        =   "Text1"
      TabIndex        =   0
      Top             =   2640
      Width           =   735
   End
   Begin VB.Label Label5 
      Caption         =   "port"
      Height          =   375
      Left            =   600
      TabIndex        =   10
      Top             =   1200
      Width           =   615
   End
   Begin VB.Label Label4 
      Caption         =   "ip"
      Height          =   375
      Left            =   600
      TabIndex        =   8
      Top             =   480
      Width           =   615
   End
   Begin VB.Label Label3 
      Caption         =   "返回数据"
      Height          =   495
      Left            =   480
      TabIndex        =   6
      Top             =   3480
      Width           =   735
   End
   Begin VB.Label Label2 
      Caption         =   "湿度"
      Height          =   375
      Left            =   4560
      TabIndex        =   5
      Top             =   3240
      Width           =   855
   End
   Begin VB.Label Label1 
      Caption         =   "温度"
      Height          =   255
      Left            =   4560
      TabIndex        =   4
      Top             =   2280
      Width           =   1095
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
If ws.State <> 0 Then ws.Close
ws.RemoteHost = ip.Text
ws.RemotePort = port.Text
ws.Connect
timedelay 100
Do
 DoEvents
 Loop Until ws.State = sckConnected
 Me.Caption = "已经联机"
Text3.Text = True

timedelay 100

ws.SendData ":000450000008A4" & Chr(13) & Chr(10)
timedelay 100


End Sub

Private Sub ws_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
Dim WH As String
Dim WL As String
Dim TH As String
Dim TL As String
Dim a
Dim b
Dim c
Dim d
ws.GetData strData

Text3.Text = strData
TH = Mid(strData, 12, 2)
TL = Mid(strData, 14, 2)
WH = Mid(strData, 16, 2)
WL = Mid(strData, 18, 2)
a = "&H" + TH
b = "&H" + TL
c = "&H" + WH
d = "&H" + WL
Text1.Text = (Val(a And &O7) * 256 + Val(b)) * 0.0625
Text2.Text = (Val(c) * 256 + Val(d)) / 10


 timedelay 100
ws.Close
timedelay 100

Text3.Text = strData



 
End Sub

⌨️ 快捷键说明

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