You are on page 1of 1

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.

Load
ComboBox1.Items.Clear()
For Each puerto As String In My.Computer.Ports.SerialPortNames
ComboBox1.Items.Add(puerto)
If ComboBox1.Items.Count > 0 Then
ComboBox1.Text = "Puerto Disponible"
ElseIf ComboBox1.Items.Count = 0 Then
ComboBox1.Text = "No Hay Puerto!"
End If
Next

End Sub

Private Sub btnConectar_Click(sender As Object, e As EventArgs) Handles


btnConectar.Click
arduinoPort.PortName = ComboBox1.SelectedItem
arduinoPort.Open()
End Sub

Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs)


Handles ComboBox1.SelectedIndexChanged

End Sub

Private Sub btnDeconectar_Click(sender As Object, e As EventArgs) Handles


btnDeconectar.Click
arduinoPort.Close()
End Sub

Private Sub BtnPrendeyApago_Click(sender As Object, e As EventArgs) Handles


BtnPrendeyApago.Click
If BtnPrendeyApago.Text = "Prender" Then
If arduinoPort.IsOpen() Then
Try
arduinoPort.Write("a")
PictureBox1.BackColor = Color.Red
BtnPrendeyApago.Text = "Apagar"
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
ElseIf BtnPrendeyApago.Text = "Apagar" Then
If arduinoPort.IsOpen() Then
Try
arduinoPort.Write("s")
PictureBox1.BackColor = Color.Black
BtnPrendeyApago.Text = "Prender"
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
End If
End Sub

You might also like