1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
Public Class Form1
Dim WithEvents serialPort As New IO.Ports.SerialPort
'Ouverture Du Port
Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click
serialPort.Open()
btnConnect.Enabled = False
btnDisconnect.Enabled = True
lblMessage.Text = "Connected."
End Sub
' Deconection du port
Private Sub btnDisconnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisconnect.Click
serialPort.Close()
btnConnect.Enabled = True
btnDisconnect.Enabled = False
lblMessage.Text = "Disconnected."
End Sub
'Envoie et receptions des donnees
Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
Dim text As String
text = txtDataToSend.Text
serialPort.Write(text)
Dim buffer As Byte()
Dim offset As Integer
Dim count As Integer
Dim returnValue As String
returnValue = serialPort.Read(buffer, offset, count)
txtDataReceived.Text = (returnValue)
End Sub
End Class |
Partager