福建工程学院国脉信息学院本科毕业设计
附录3 PC机程序: Dim n As Integer Dim t As Integer ‘定义全局变量 Private Sub Command1_Click() ‘单击温度设置按钮程序 Dim i As Integer If Len(Trim(Text2.Text)) < 3 Or Val(Text2.Text) > 100 Or Val(Text2.Text) < 0 Or Left(Right(Text2.Text, 2), 1) <> \ Label3.Caption = \设定输入错误,不发送\ Else Label3.Caption = \ Select Case Len(Trim(Text2.Text)) Case 5 Text8.Text = Trim(Text2.Text) Case 4 Text8.Text = \ Case 3 Text8.Text = \ End Select MSComm1.Output = \ Timer2.Enabled = True End If End Sub Private Sub Command2_Click() ‘单击按钮执行数据采集或停止采集 If Command2.Caption = \采集数据\ Command2.Caption = \停止采集\ Timer1.Enabled = True MSComm1.Output = \ Else Command2.Caption = \采集数据\ Timer1.Enabled = False MSComm1.Output = \
福建工程学院国脉信息学院本科毕业设计
MSComm1.Output = \ End If End Sub Private Sub Command4_Click() ‘单击按钮清空数据 Text1.Text = \Text4.Text = \End Sub Private Sub Command5_Click() ‘单击按钮开关通信端口 If Command5.Caption = \开通信端口\ Command5.Caption = \关通信端口\ COM.Enabled = False Command2.Enabled = True Command1.Enabled = True Text2.Enabled = True Select Case COM.ListIndex '指定端口号(COM) Case 0 MSComm1.CommPort = 1 Case 1 MSComm1.CommPort = 2 Case 2 MSComm1.CommPort = 3 Case 3 MSComm1.CommPort = 4 End Select MSComm1.Settings = \ '9600波特,无校验,8位数据位,1位停止位 MSComm1.InputMode = comInputModeText '接收文本数据 MSComm1.InputLen = 0 '读出接收缓冲区的所有内容 MSComm1.InBufferSize = 1024 MSComm1.OutBufferSize = 1024 MSComm1.RThreshold = 1 '每接收到1个字符,发生1次事件 MSComm1.PortOpen = True '打开串口 Else Timer1.Enabled = False MSComm1.Output = \ MSComm1.Output = \ Command5.Caption = \开通信端口\ COM.Enabled = True
福建工程学院国脉信息学院本科毕业设计
MSComm1.PortOpen = False Command2.Caption = \采集数据\ Command2.Enabled = False Command1.Enabled = False Text2.Enabled = False End If End Sub Private Sub Command7_Click() ‘单击按钮保存温度数据 CommonDialog1.Action = 2 Open CommonDialog1.FileName For Append As #1 Write #1, Now Write #1, Text4.Text Close #1 End Sub Private Sub Form_Load() COM.AddItem \ COM.AddItem \ COM.AddItem \ COM.AddItem \End Sub Private Sub MSComm1_OnComm() ‘串口接收到数据时读出数据 Select Case MSComm1.CommEvent Case comEvReceive Text1.Text = Text1.Text & MSComm1.Input Case Else End Select End Sub Private Sub Text1_Change() ‘对读出的数据进行处理 If (Len(Text1.Text) Mod 4 = 0) And (Len(Text1.Text) > 0) Then Text3.Text = Right$(Text1.Text, 4) & \℃\Text4.Text = Time & Chr$(6) & Chr$(6) & Chr$(6) & Text3.Text & \ \
福建工程学院国脉信息学院本科毕业设计
Text7.Text = Time$ n = n + 1 End If If n = 100 Then n = 0 Text1.Text = \End If End Sub Private Sub Text5_Change() ‘改变读数据的时间 Timer1.Interval = Val(Text5.Text) * 1000 End Sub Private Sub Timer1_Timer() ‘采集数据后进行绘图 MSComm1.Output = \Dim a As Single Dim a1 As String Dim a2 As String Dim a3 As String Dim k As Integer Static b(200) As Integer Text7.Text = Time For k = 1 To 199 b(k) = b(k + 1) Next k b(200) = Val(Text3.Text) With MSChart1 For i = 1 To 200 a = Val(Mid(Text7.Text, 1, 2)) * 3600 + Val(Mid(Text7.Text, 4, 2)) * 60 + Val(Mid(Text7.Text, 7, 2)) - 200 * Val(Text5.Text) + i * Val(Text5.Text) + 1 If a < 0 Then a = a + 86400 ElseIf a > 86400 Then a = a - 86400 End If
相关推荐: