0% found this document useful (0 votes)
31 views3 pages

Form1: "Seleccione El Puerto A Trabajar"

This code defines a Windows form application that communicates with a serial port. It contains handlers for buttons to connect/disconnect to a serial port, send data, and receive incoming data on a timer. When certain buttons are clicked, it sends individual characters ("R", "O", "L", "J") over the serial port.

Uploaded by

Jose Regino
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views3 pages

Form1: "Seleccione El Puerto A Trabajar"

This code defines a Windows form application that communicates with a serial port. It contains handlers for buttons to connect/disconnect to a serial port, send data, and receive incoming data on a timer. When certain buttons are clicked, it sends individual characters ("R", "O", "L", "J") over the serial port.

Uploaded by

Jose Regino
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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