Home > other >  Vb PC integrated practice (Vb)
Vb PC integrated practice (Vb)

Time:05-07

Public Class Form
Public RXD $
Public Temp_val
Public Humi_val
Dim auto_temp_crt=0
Dim auto_humi_crt=0
Dim set_t
Dim set_h
Private Sub smarthome_Load_1 (ByVal sender As System. Object, ByVal e the As System. EventArgs) Handles MyBase. Load
For Each sp As String In My.Com puter. Ports. SerialPortNames
ComboBox1. Items. The Add (sp)
Next
End Sub
Private Sub ComboBox1_SelectedIndexChanged_1 (ByVal sender As System. Object, ByVal e the As System. EventArgs) Handles ComboBox1. SelectedIndexChanged
SerialPort1. PortName=ComboBox1. Items (ComboBox1 SelectedIndex)
SerialPort1. The Open ()
Timer1. Enabled=True
End Sub

Private Sub Timer1_Tick (ByVal sender As System. Object, ByVal e the As System. EventArgs) Handles Timer1. Tick
RXD $=SerialPort1. ReadExisting ()
Dim DataID
If RXD $& lt;> "" Then
DataID=Mid (RXD, 1, 1)
If DataID="H" Then
Humi_val=Mid (RXD, 2, 5)
Lab_h. Text=Humi_val
End the If
End the If
If RXD $& lt;> "" Then
DataID=Mid (RXD, 1, 1)
If DataID="T" Then
Temp_val=Mid (RXD, 2, 5)
Lab_t. Text=Temp_val
End the If
End the If
End Sub

Private Sub ToolStripLabel1_Click_1 (ByVal sender As System. Object, ByVal e the As System. EventArgs) Handles ToolStripLabel1. Click
If ToolStripLabel1. Text="start temperature control" Then
Auto_temp_crt=1
ToolStripLabel1. Text="close temperature control"
The Else
Auto_temp_crt=0
ToolStripLabel1. Text="start temperature control"
End the If
End Sub
Private Sub ToolStripLabel2_Click_1 (ByVal sender As System. Object, ByVal e the As System. EventArgs) Handles ToolStripLabel2. Click
If ToolStripLabel2. Text="start the humidity control" Then
Auto_humi_crt=1
ToolStripLabel2. Text="close the humidity control"
The Else
Auto_humi_crt=0
ToolStripLabel2. Text="start the humidity control"
End the If
End Sub
Private Sub SendCom (ByVal sendstr)
If SerialPort1. IsOpen Then
SerialPort1. Write (sendstr)
End the If
End Sub
Private Sub ToolStripLabel3_Click_1 (ByVal sender As System. Object, ByVal e the As System. EventArgs) Handles ToolStripLabel3. Click
Dim set_t=InputBox (" please enter the set temperature & amp;" VbCrLf & amp; "For 2 seconds delay time", "simulation numerical", 0)
Label4. Text=set_t
If auto_temp_crt=1 Then
If Lab_t. Text & lt; Set_t Then
PictureBox2) Image=My) Resources. The wind? Fan Θ? 停?
Button2. Text="fan close?"
SendCom (" 4 ")
The Else
PictureBox1) Image=My) Resources. The wind? Fan Θ? Turn Ji
Button2. Text="fan open"
SendCom (" 3 ")
End the If
End the If
End Sub
Private Sub ToolStripLabel4_Click_1 (ByVal sender As System. Object, ByVal e the As System. EventArgs) Handles ToolStripLabel4. Click
Dim set_h=InputBox (" please enter the setting humidity & amp;" VbCrLf & amp; "For 2 seconds delay time", "simulation numerical", 0)
Label5. Text=set_h
If auto_humi_crt=1 Then
If Lab_h. Text & lt; Set_h Then
PictureBox3. Image=My. Resources. Humidifier close
Button3. Text="humidifier closed"
SendCom (" 6 ")
The Else
PictureBox3. Image=My. Resources. Humidifier open
Button3. Text="humidifier open"
SendCom (" 5 ")
End the If
End the If
End Sub
Private Sub Button1_Click_1 (ByVal sender As System. Object, ByVal e the As System. EventArgs) Handles for. Click
If for the Text="sitting room lights" Then
PictureBox1) Image=My) Resources. The living room lights
For the Text="sitting room to turn off the lights"
SendCom (" 1 ")
The Else
PictureBox1) Image=My) Resources. The living room to turn off the lights
For the Text="sitting room lights"
SendCom (" 2 ")
End the If
End Sub


Private Sub Button2_Click_1 (ByVal sender As System. Object, ByVal e the As System. EventArgs) Handles Button2. Click
If Button2. Text="fan open" Then
PictureBox2. Image=My. Resources. Turn the fan
Button2. Text="fan closed"
SendCom (" 3 ")
The Else
PictureBox2. Image=My) Resources) fan stop
Button2. Text="fan open"
SendCom (" 4 ")
End the If
End Sub

Private Sub Button3_Click_1 (ByVal sender As System. Object, ByVal e the As System. EventArgs) Handles Button3. Click
If Button3. Text="humidifier open" Then
PictureBox3. Image=My. Resources. Humidifier open
Button3. Text="humidifier close?"
SendCom (" 5 ")
The Else
PictureBox3. Image=My. Resources. Humidifier close
Button3. Text="humidifier open?"
SendCom (" 6 ")
End the If
End Sub
The End of the Class

  • Related