程序代码:
Public Class Form1 Dim RXD$ Dim Temp_val Dim LS_val Dim auto_temp_crt = 0 Dim settemp Dim auto_ls_crt = 0 Dim setls Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If Button1.Text = "客厅_开灯" Then ActionMess.Text = "开启客厅灯" PictureBox2.Image = My.Resources.客厅开灯 Button1.Text = "客厅_关灯" If SerialPort1.IsOpen Then SendCom("S1") End If Else PictureBox2.Image = My.Resources.客厅关灯 ActionMess.Text = "关闭客厅灯" Button1.Text = "客厅_开灯" If SerialPort1.IsOpen Then SendCom("S2") End If End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) If Button2.Text = "风扇_开启" Then ActionMess.Text = "开启风扇" PictureBox3.Image = My.Resources.风扇转 Button2.Text = "风扇_关闭" SendCom("S3") Else ActionMess.Text = "关闭风扇" PictureBox3.Image = My.Resources.风扇停 Button2.Text = "风扇_开启" SendCom("S4") End If End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) If Button3.Text = "台灯_开启" Then ActionMess.Text = "开启台灯" PictureBox3.Image = My.Resources.台灯亮 Button3.Text = "台灯_关闭" SendCom("S5") Else ActionMess.Text = "关闭台灯" PictureBox3.Image = My.Resources.台灯灭 Button3.Text = "台灯_开启" SendCom("S6") End If End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) If Button4.Text = "电视_开启" Then ActionMess.Text = "开启电视" PictureBox6.Image = My.Resources.电视开 SendCom("S7") Button4.Text = "电视_关闭" Else ActionMess.Text = "关闭电视" PictureBox6.Image = My.Resources.电视关 Button4.Text = "电视_开启" SendCom("S8") End If End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) If Button5.Text = "音响_开启" Then ActionMess.Text = "开启音响" PictureBox5.Image = My.Resources.音响响 Button5.Text = "音响_关闭" SendCom("S9") Else ActionMess.Text = "关闭音响" PictureBox5.Image = My.Resources.音响停 Button5.Text = "音响_开启" SendCom("SA") End If End Sub Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) If Button6.Text = "保全_启动" Then ActionMess.Text = "保全启动中" PictureBox10.Image = My.Resources.警报停 PictureBox10.Visible = True Button6.Text = "保全_关闭" Else ActionMess.Text = "保全已解除" PictureBox10.Visible = False Button6.Text = "保全_启动" End If End Sub Private Sub PictureBox5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox5.Click End Sub Private Sub SplitContainer1_Panel2_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) End Sub Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) If Button6.Text = "保全_关闭" Then PictureBox10.Image = My.Resources.警报响 SendCom("SB") Else PictureBox10.Image = My.Resources.警报停 SendCom("SC") End If End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) RXD$ = SerialPort1.ReadExisting() Dim DataID If RXD$ <> "" Then Label5.Text = RXD$ DataID = Mid(RXD, 1, 1) Select Case DataID Case "T" Temp_val = Mid(RXD, 2, 5) lb_Temp.Text = Temp_val Case "L" LS_val = Mid(RXD, 2, 4) lb_LS.Text = LS_val End Select End If If SerialPort1.IsOpen = True Then Dim NTCMD = Mid(RXD$, 1, 2) Label1.Text = NTCMD Select Case NTCMD Case "S1" PictureBox2.Image = My.Resources.客厅开灯 Button1.Text = "客厅_关灯" Case "S2" PictureBox2.Image = My.Resources.客厅关灯 Button1.Text = "客厅_开灯" Case "S3" PictureBox4.Image = My.Resources.风扇转 Button2.Text = "风扇_关闭" Case "S4" PictureBox4.Image = My.Resources.风扇停 Button2.Text = "风扇_开启" Case "S5" PictureBox3.Image = My.Resources.台灯亮 Button3.Text = "台灯_关闭" Case "S6" PictureBox3.Image = My.Resources.台灯灭 Button3.Text = "台灯_开灯" Case "S7" PictureBox6.Image = My.Resources.电视开 Button4.Text = "电视_关闭" PictureBox6.Visible = True Case "S8" PictureBox6.Image = My.Resources.电视关 Button4.Text = "电视_开启" PictureBox6.Visible = False Case "S9" PictureBox5.Image = My.Resources.音响响 Button5.Text = "音响_关闭" PictureBox5.Visible = True Case "SA" PictureBox5.Image = My.Resources.音响停 Button5.Text = "音响_开启" PictureBox5.Visible = False Case "SB" If PictureBox10.Visible = True Then PictureBox10.Image = My.Resources.警报响 End If Case "SC" If PictureBox10.Visible = True Then PictureBox10.Image = My.Resources.警报停 End If End Select ' get temp Label2.Text = lb_Temp.Text Dim temp = Val(Mid(Label2.Text, 1, 1)) * 100 + Val(Mid(Label2.Text, 2, 1)) * 10 + Val(Mid(Label2.Text, 4, 1)) If auto_temp_crt = 1 Then If temp > settemp * 10 Then PictureBox4.Image = My.Resources.风扇转 Button2.Text = "风扇_关闭" SendCom("0000001") Else PictureBox4.Image = My.Resources.风扇停 Button2.Text = "风扇_开启" SendCom("0000002") End If End If ' get ls Label1.Text = lb_LS.Text Dim ls = Val(Mid(Label1.Text, 1, 1)) * 100 + Val(Mid(Label1.Text, 2, 1)) * 10 + Val(Mid(Label1.Text, 3, 1)) If auto_ls_crt = 1 Then If ls < setls Then PictureBox2.Image = My.Resources.客厅开灯 Button2.Text = "客厅_开灯" SendCom("0000003") Else PictureBox2.Image = My.Resources.客厅关灯 Button2.Text = "客厅_关灯" SendCom("0000004") End If End If End If End Sub Public Sub SendCom(ByVal sendstr) If SerialPort1.IsOpen Then SerialPort1.Write(sendstr) End If End Sub Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) SendCom("BS7") End Sub Private Sub ToolStripLabel1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) If ToolStripLabel1.Text = "启动温控与光控" Then auto_temp_crt = 1 auto_ls_crt = 1 ToolStripLabel1.Text = "关闭温控与光控" Else auto_temp_crt = 0 auto_ls_crt = 0 ToolStripLabel1.Text = "启动温控与光控" End If End Sub Private Sub ToolStripLabel2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) settemp = InputBox("请输入设定温度" & vbCrLf & "延迟发生时间2秒", "模拟数值", 0) Label1.Text = settemp End Sub Private Sub SmartHome_Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) For Each sp As String In (sp) Next End Sub Private Sub StatusStrip1_ItemClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) End Sub Private Sub ToolStripStatusLabel1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripStatusLabel1.Click End Sub Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) End Sub Private Sub ToolStrip1_ItemClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles ToolStrip1.ItemClicked End Sub Private Sub PictureBox4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox4.Click End Sub Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click End Sub Private Sub ToolStripLabel3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripLabel3.Click setls = InputBox("请输入设定光照度" & vbCrLf & "延迟发生时间2秒", "模拟数值", 0) Label1.Text = setls End Sub Private Sub PictureBox3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox3.Click End Sub Private Sub PictureBox6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox6.Click End Sub Private Sub Label6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label6.Click End Sub Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged Try SerialPort1.PortName = ComboBox1.Items(ComboBox1.SelectedIndex) SerialPort1.Open() Timer1.Enabled = True Catch ex As Exception MsgBox(ex.ToString) End Try End Sub Private Sub Label5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label5.Click End Sub Private Sub lb_Temp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lb_Temp.Click End Sub Private Function ActionMess() As Object Throw New NotImplementedException End Function Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub End Class
现在被我删除了主界面,只剩下smarthome,运行不了了,