Public Class Form1
Dim StrBufferOut As String
Dim StrBufferIn As String
Private Sub
Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
StrBufferOut = ""
StrBufferIn = ""
btnConectar.Enabled = False
btnEnviarDados.Enabled = False
tmTimer.Enabled = False
End Sub
Private Sub
btnConectar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
btnConectar.Click
If btnConectar.Text = "Conectar"
Then
btnConectar.Text = "Desconectar"
btnEnviarDados.Enabled = True
tmTimer.Enabled = True
SerialPort.PortName = cmbPortasSeriais.Text
SerialPort.Open()
Else
If btnConectar.Text = "Desconectar"
Then
btnConectar.Text = "Conectar"
btnEnviarDados.Enabled = False
tmTimer.Enabled = False
SerialPort.Close()
End If
End If
End Sub
Private Sub
btnDeterminarConexao_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
btnDeterminarConexao.Click
cmbPortasSeriais.Items.Clear()
For Each
ListaPortaSerial As String
In My.Computer.Ports.SerialPortNames
Me.cmbPortasSeriais.Items.Add(ListaPortaSerial)
Next
If cmbPortasSeriais.Items.Count > 0 Then
cmbPortasSeriais.Text = cmbPortasSeriais.Items(0)
btnConectar.Enabled = True
MessageBox.Show("Selecione
uma porta serial para se conectar.")
Else
btnConectar.Enabled = False
btnEnviarDados.Enabled = False
cmbPortasSeriais.Items.Clear()
MessageBox.Show("Nâo
foi encontrada nenhuma porta disponivel..")
End If
End Sub
Private Sub
btnEnviarDados_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
btnEnviarDados.Click
SerialPort.DiscardOutBuffer()
StrBufferOut = txtDiscardOutBuffer.Text
SerialPort.Write(StrBufferOut)
End Sub
Private Sub
tmTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
tmTimer.Tick
StrBufferIn = SerialPort.ReadExisting
If StrBufferIn <> ""
Then
StrBufferIn = StrBufferIn
StrBufferIn = ""
SerialPort.DiscardInBuffer()
End If
End Sub
End Class
Pegue o projeto neste link: http://www.mediafire.com/?7y6u4hq2ju1ncd1
0 comentários:
Postar um comentário