Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Public Class Form1

Dim strBufferOut As String


Dim strBufferIn As String

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles txtBufferOut.TextChanged

End Sub

Private Sub btnDeterrminarConexion_Click(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles btnDeterrminarConexion.Click
cboPuertos.Items.Clear()
For Each PuertoDisponible As String In My.Computer.Ports.SerialPortNames
cboPuertos.Items.Add(PuertoDisponible)

Next
If cboPuertos.Items.Count > 0 Then
cboPuertos.Text = cboPuertos.Items(0)
MessageBox.Show("SELECCIONE EL PUERTO A TRABAJAR")
btnConectar.Enabled = True
Else

MessageBox.Show("NINGUN PUERTO ENCONTRADO")


btnConectar.Enabled = False
btnEnviarDato.Enabled = False
cboPuertos.Items.Clear()
cboPuertos.Text = ("")
End If
End Sub

Private Sub btnConectar_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnConectar.Click
If btnConectar.Text = "CONECTAR" Then
spPuertos.PortName = cboPuertos.Text
btnConectar.Text = "desconectar"
btnEnviarDato.Enabled = True
tmrTimer.Enabled = True
spPuertos.Open()
Button1.Visible = True
Button3.Visible = True

Else
btnConectar.Text = "desconectar"
btnConectar.Text = "CONECTAR"
btnEnviarDato.Enabled = False
tmrTimer.Enabled = False
spPuertos.Close()
End If
End Sub

Private Sub btnEnviarDato_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnEnviarDato.Click
spPuertos.DiscardOutBuffer()
strBufferOut = txtBufferOut.Text
spPuertos.Write(strBufferOut)
End Sub

Private Sub tmrTimer_Tick(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles tmrTimer.Tick
strBufferIn = spPuertos.ReadExisting
If strBufferIn <> "" Then
txtBufferIn.Text = strBufferIn
strBufferIn = ""
spPuertos.DiscardInBuffer()

End If
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load
strBufferOut = ""
strBufferIn = ""
btnConectar.Enabled = False
btnEnviarDato.Enabled = False
tmrTimer.Enabled = False
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
spPuertos.DiscardOutBuffer()
strBufferOut = "R"
spPuertos.Write(strBufferOut)
Button2.Visible = True
Button1.Visible = False

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click
spPuertos.DiscardOutBuffer()
strBufferOut = "O"
spPuertos.Write(strBufferOut)
Button1.Visible = True
Button2.Visible = False

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click
spPuertos.DiscardOutBuffer()
strBufferOut = "L"
spPuertos.Write(strBufferOut)
Button4.Visible = True
Button3.Visible = False
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button4.Click
spPuertos.DiscardOutBuffer()
strBufferOut = "J"
spPuertos.Write(strBufferOut)
Button3.Visible = True
Button4.Visible = False
End Sub
End Class

You might also like