Public Class Form1 Dim switch1, switch2, switch3, switch4 As Boolean Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load TrackBar1.Value = 750 Label1.Text = TrackBar1.Value End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If switch1 = False Then switch1 = True ElseIf switch1 = True Then switch1 = False End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click If switch2 = False Then switch2 = True ElseIf switch2 = True Then switch2 = False End If End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click If switch3 = False Then switch3 = True ElseIf switch3 = True Then switch3 = False End If End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click If switch4 = False Then switch4 = True ElseIf switch4 = True Then switch4 = False End If End Sub Private Sub SerialPort1_DataReceived(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived Dim out_data As Int16 = 0 Dim in_data As String = "" in_data = SerialPort1.ReadLine Select Case in_data Case "SW" If switch1 Then out_data = out_data Or 1 ElseIf Not switch1 Then out_data = out_data And 0 End If If switch2 Then out_data = out_data Or 2 ElseIf Not switch2 Then out_data = out_data And 61 End If If switch3 Then out_data = out_data Or 4 ElseIf Not switch3 Then out_data = out_data And 59 End If If switch4 Then out_data = out_data Or 8 ElseIf Not switch4 Then out_data = out_data And 55 End If SerialPort1.WriteLine(out_data) Do While SerialPort1.BytesToRead < 1 Loop SerialPort1.ReadExisting() Case "A1" SerialPort1.WriteLine(TrackBar1.Value) SerialPort1.WriteLine(out_data) Do While SerialPort1.BytesToRead < 2 Loop SerialPort1.ReadExisting() End Select End Sub Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click Form2.Visible = True End Sub Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll Label1.Text = TrackBar1.Value End Sub Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click TrackBar1.Value = 750 Label1.Text = TrackBar1.Value End Sub End Class