📄 form1.frm
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 5610
ClientLeft = 165
ClientTop = 855
ClientWidth = 10950
LinkTopic = "Form1"
ScaleHeight = 5610
ScaleWidth = 10950
StartUpPosition = 3 '窗口缺省
Begin VB.Timer Timer1
Enabled = 0 'False
Interval = 50
Left = 4920
Top = 5160
End
Begin VB.CommandButton Command2
Caption = "画图"
Height = 375
Left = 0
TabIndex = 3
Top = 5040
Width = 1815
End
Begin VB.PictureBox Picture1
Height = 5055
Left = -120
ScaleHeight = 4995
ScaleWidth = 7755
TabIndex = 2
Top = 0
Visible = 0 'False
Width = 7815
End
Begin VB.TextBox Text1
Height = 1935
Left = 120
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 1
Top = 120
Width = 4695
End
Begin VB.CommandButton Command1
Caption = "接收所有数据"
Height = 375
Left = 2880
TabIndex = 0
Top = 5040
Width = 1455
End
Begin MSCommLib.MSComm MSComm1
Left = 0
Top = 4080
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
CommPort = 2
DTREnable = -1 'True
RThreshold = 1
End
Begin VB.Label Label2
Height = 495
Left = 7920
TabIndex = 5
Top = 1920
Width = 2775
End
Begin VB.Label Label1
Height = 495
Left = 7920
TabIndex = 4
Top = 360
Width = 2895
End
Begin VB.Menu file
Caption = "文件"
End
Begin VB.Menu help
Caption = "帮助"
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim index As Single
Dim wendu(5000) As Single
Dim ww As Single
Dim pingjun As Single
Private Function PrintWord(X, Y, Word As String)
With Picture1
.CurrentX = X
.CurrentY = Y
.ForeColor = RGB(0, 0, 255)
End With
Picture1.Print Word
End Function
Private Sub Command1_Click()
Dim data(5) As Byte
data(0) = &HAA
data(1) = &H55
data(2) = &H1
data(3) = &H1
data(4) = &H1
data(5) = &H0
MSComm1.OutBufferCount = 0
MSComm1.Output = data
End Sub
Private Sub Command2_Click()
Dim he As Single
Dim hee As Single
hee = index + 1
he = 0
For i = 0 To index
he = he + wendu(i)
Next i
pingjun = he / hee
Label1.Caption = "平均温度为:" + Str(pingjun) + " 摄氏度"
Picture1.Visible = True
Picture1.DrawWidth = 1 '设置线条宽度
Picture1.Cls
'设定用户坐标系,坐标原点在Picture1中心
Picture1.Scale (-0.075 * hee, 20)-(hee, -2)
Picture1.Line (0, 0)-(hee, 0), RGB(0, 0, 255)
Picture1.Line (hee, 0)-(0.95 * hee, 0.5), RGB(0, 0, 255)
Picture1.Line (hee, 0)-(0.95 * hee, -0.5), RGB(0, 0, 255)
Picture1.ForeColor = RGB(0, 0, 255)
Picture1.Print "X/数"
'画 X 轴
Picture1.Line (0, 0)-(0, 20), RGB(0, 0, 255)
Picture1.Line -(0.5, 19.5), RGB(0, 0, 255)
Picture1.Line (0, 20)-(-0.5, 19.5), RGB(0, 0, 255)
wor = PrintWord(1, 19.5, "Y/摄氏度")
'画 Y 轴
For l = 0 To hee
Picture1.Line (l, 0)-(l, 0.14)
Next l
For lin = 1 To 20
'wor = PrintWord(lin - 0.5, -0.5, Str(lin))
Picture1.Line (0, lin)-(-0.005 * index, lin)
If lin <> 0 Then
End If
Next lin
wor = PrintWord(-0.025 * hee, -0.025 * 10, "原点(0," + Str(CInt(pingjun) - 5) + ")")
Dim shu As Single
shu = CInt(pingjun) - 5
Dim ke As Single
ke = 2
For m = 1 To 9
wor = PrintWord(0 - 0.055 * hee, ke + 0.3, Str(shu + m))
ke = ke + 2
Next m
Timer1.Enabled = True
Picture1.DrawWidth = 2
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
index = 100
ww = 1
For i = 0 To index
If (i Mod 2 = 1) Then
wendu(i) = 26 + i / 100
Else
wendu(i) = 26 - i / 100
End If
Next i
MSComm1.PortOpen = True
MSComm1.InputMode = comInputModeBinary
End Sub
Private Sub MSComm1_OnComm()
Dim data2 As Variant
Dim data3 As Byte
Select Case MSComm1.CommEvent
Case comEvReceive
Dim tmp As Variant
Dim arr() As Byte
Dim str1 As String
Dim tem As Single
Dim tem1 As Single
tmp = MSComm1.Input
arr = tmp
index = UBound(arr)
For i = 0 To index
str1 = Hex(arr(i))
tem = Val(str1)
tem1 = tem * 0.0625
wendu(i) = tem1
Text1.Text = Text1.Text + " " + str1
Next i
End Select
End Sub
Private Sub Timer1_Timer()
If ww > index Then
ww = 1
Timer1.Enabled = False
Else
Picture1.Line (ww - 1, wendu(ww - 1) - CInt(pingjun) + 10)-(ww, wendu(ww) - CInt(pingjun) + 10)
ww = ww + 1
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -