?? 溫度曲線.frm
字號:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form TempForm
Caption = "溫度曲線"
ClientHeight = 8295
ClientLeft = 60
ClientTop = 450
ClientWidth = 11085
LinkTopic = "Form1"
ScaleHeight = 8295
ScaleMode = 0 'User
ScaleWidth = 11088.96
StartUpPosition = 3 '窗口缺省
Begin MSCommLib.MSComm MSComm_Temp
Left = 9697
Top = 120
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DTREnable = -1 'True
End
Begin VB.ComboBox Combo_Com
Height = 300
Left = 4498
TabIndex = 3
Text = "COM1"
Top = 240
Width = 2199
End
Begin VB.Timer Timer1
Interval = 1000
Left = 10396
Top = 240
End
Begin VB.CommandButton Comm_open
Caption = "打開串口"
Height = 375
Left = 7197
TabIndex = 1
Top = 240
Width = 1350
End
Begin VB.PictureBox Templine
BackColor = &H00FFFFFF&
Height = 6500
Left = 1000
ScaleHeight = 6435
ScaleWidth = 9180
TabIndex = 0
Top = 1150
Width = 9247
End
Begin VB.Label Label30
Caption = "90"
Height = 195
Left = 9996
TabIndex = 32
Top = 7680
Width = 300
End
Begin VB.Label Label29
Caption = "85"
Height = 195
Left = 9497
TabIndex = 31
Top = 7680
Width = 300
End
Begin VB.Label Label28
Caption = "80"
Height = 195
Left = 8997
TabIndex = 30
Top = 7680
Width = 300
End
Begin VB.Label Label27
Caption = "75"
Height = 195
Left = 8497
TabIndex = 29
Top = 7680
Width = 300
End
Begin VB.Label Label26
Caption = "70"
Height = 195
Left = 7997
TabIndex = 28
Top = 7680
Width = 300
End
Begin VB.Label Label25
Caption = "65"
Height = 195
Left = 7497
TabIndex = 27
Top = 7680
Width = 300
End
Begin VB.Label Label24
Caption = "60"
Height = 195
Left = 6997
TabIndex = 26
Top = 7680
Width = 300
End
Begin VB.Label Label23
Caption = "55"
Height = 195
Left = 6498
TabIndex = 25
Top = 7680
Width = 300
End
Begin VB.Label Label22
Caption = "50"
Height = 195
Left = 5998
TabIndex = 24
Top = 7680
Width = 300
End
Begin VB.Label Label21
Caption = "45"
Height = 195
Left = 5498
TabIndex = 23
Top = 7680
Width = 195
End
Begin VB.Label Label20
Caption = "40"
Height = 195
Left = 4998
TabIndex = 22
Top = 7680
Width = 195
End
Begin VB.Label Label19
Caption = "35"
Height = 195
Left = 4498
TabIndex = 21
Top = 7680
Width = 195
End
Begin VB.Label Label18
Caption = "30"
Height = 195
Left = 3999
TabIndex = 20
Top = 7680
Width = 195
End
Begin VB.Label Label17
Caption = "25"
Height = 195
Left = 3499
TabIndex = 19
Top = 7680
Width = 195
End
Begin VB.Label Label16
Caption = "20"
Height = 195
Left = 2999
TabIndex = 18
Top = 7680
Width = 195
End
Begin VB.Label Label15
Caption = "15"
Height = 195
Left = 2499
TabIndex = 17
Top = 7680
Width = 195
End
Begin VB.Label Label14
Caption = "10"
Height = 195
Left = 1999
TabIndex = 16
Top = 7680
Width = 195
End
Begin VB.Label Label13
Caption = "5"
Height = 195
Left = 1500
TabIndex = 15
Top = 7680
Width = 195
End
Begin VB.Label Label12
Caption = "80"
Height = 150
Left = 720
TabIndex = 14
Top = 1350
Width = 195
End
Begin VB.Label Label11
Caption = "0"
Height = 255
Left = 1000
TabIndex = 13
Top = 7680
Width = 135
End
Begin VB.Label Label10
Caption = "30"
Height = 150
Left = 720
TabIndex = 12
Top = 6350
Width = 195
End
Begin VB.Label Label9
Caption = "20"
Height = 150
Left = 720
TabIndex = 11
Top = 7350
Width = 255
End
Begin VB.Label Label8
Caption = "40"
Height = 150
Left = 720
TabIndex = 10
Top = 5350
Width = 195
End
Begin VB.Label Label7
Caption = "50"
Height = 150
Left = 720
TabIndex = 9
Top = 4350
Width = 195
End
Begin VB.Label Label6
Caption = "60"
Height = 150
Left = 720
TabIndex = 8
Top = 3250
Width = 195
End
Begin VB.Label Label5
Caption = "時間(S)"
Height = 255
Left = 10296
TabIndex = 7
Top = 7680
Width = 800
End
Begin VB.Label Label4
Caption = "70"
Height = 150
Left = 720
TabIndex = 6
Top = 2350
Width = 195
End
Begin VB.Label Label3
Caption = "溫度(C)"
Height = 255
Left = 360
TabIndex = 5
Top = 960
Width = 735
End
Begin VB.Label Label2
Caption = "串口號"
BeginProperty Font
Name = "宋體"
Size = 12
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 3239
TabIndex = 4
Top = 240
Width = 850
End
Begin VB.Label Label1
Caption = "溫度曲線圖"
BeginProperty Font
Name = "宋體"
Size = 15.75
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 4798
TabIndex = 2
Top = 720
Width = 1800
End
End
Attribute VB_Name = "TempForm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim flag_com_open As Boolean '定義COM端口的打開標識
Dim time_temp As Integer '定義記錄時間的變量
Dim temp_bufx, temp_bufy As Integer '定義兩個存放坐標的變量
Private Sub Combo_Com_Click()
On Error Resume Next
x = Combo_Com.Text '獲取選擇的列表項的文本
m = Len(x) '獲取列表項的長度
n = Val(Right$(x, m - 3)) '獲取列表項里的端口號
MSComm_Temp.CommPort = n '設置MScomm控件的端口號為選擇的端口號
End Sub
Private Sub Comm_open_Click()
If (flag_com_open = False) Then
Comm_open.Caption = "關閉端口" '根據flag_com_open的值設置按鈕Comm_open的Caption的值
flag_com_open = True
If MSComm_Temp.PortOpen = False Then
MSComm_Temp.PortOpen = True
End If
Timer1.Enabled = True '打開端口后使Timer1有效并開始計時
Else
Comm_open.Caption = "打開端口"
MSComm_Temp.PortOpen = False
flag_com_open = False
Timer1.Enabled = False '關閉端口后使Timer1無效
End If
End Sub
Private Sub Form_Load()
Dim i As Integer
Timer1.Enabled = False '設置定時器Timer1無效
Timer1.Interval = 1000 '設定定時器的觸發時間是1000ms
temp_bufx = 0
temp_bufy = 5500
Templine.AutoRedraw = True
Templine.DrawStyle = 2 '將劃線的格式改為虛線格式
For i = 250 To 6250 Step 500 '依次畫出溫度的各條基準線
Templine.Line (0, i)-(9250, i)
Next i
Templine.DrawStyle = 0 '將劃線的格式改為實線格式
For i = 1 To 16 '依次為下拉列表框添加列表項
Combo_Com.AddItem "COM" & i
Next i
MSComm_Temp.Settings = "9600,N,8,1" '波特率是9600,無校驗,8為數據位,1位停止位
MSComm_Temp.OutBufferSize = 0 '設置發送緩沖區的大小,以字符為單位
MSComm_Temp.InBufferSize = 0 '設置接收緩沖區的大小,以字符為單位
MSComm_Temp.InputMode = comInputModeText '以文本方式接收
MSComm_Temp.RThreshold = 4 '設置產生oncomm事件的字符數,以字符為單位
MSComm_Temp.SThreshold = 1
MSComm_Temp.InputLen = 0 '設置從接收緩沖區讀取的字符數,為0表示全部讀取
MSComm_Temp.InBufferCount = 0 '清空接收緩沖區
End Sub
Private Sub MSComm_Temp_OnComm()
Dim a As String
Dim temp As Integer
If MSComm_Temp.CommEvent = comEvReceive Then
a = MSComm_Temp.Input '讀取緩沖區內的數據
For i = 1 To 4
temp = temp * 10 + Val(Mid(a, i, 1)) '分析數據,得到傳輸的數據值
Next i
Templine.Line (temp_bufx, temp_bufy)-(time_temp * 50, 8250 - temp), vbRed '根據得到的數據值和當前的時間以及原有的數據畫出一條直線
temp_bufx = time_temp * 50 '存儲當前數據,以方便下次使用
temp_bufy = 8250 - temp
time_temp = time_temp + 1 '時間值增加1
End If
End Sub
Private Sub Timer1_Timer() 'Timer1中斷處理函數
MSComm_Temp.Output = Chr(&H30) '向下位機發送一個數據,用于和下位機通信
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -