Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Text1.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Text1.BackColor = Color.Red
Text1.ForeColor = Color.White
Text1.TextAlign = HorizontalAlignment.Center
Text1.Text = "Port Fermé"
SerialPort1.Close()
SerialPort2.Close()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Connect.Click
Text1.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
With SerialPort1
If .PortName = "COM9" Then
Text1.TextAlign = HorizontalAlignment.Center
Text1.ForeColor = Color.White
Text1.Text = "Port Ouvert"
Text1.BackColor = Color.Green
Else
Text1.BackColor = Color.Red
End If
End With
With SerialPort1
.PortName = "COM9"
.BaudRate = 9600
.DataBits = 8
.Parity = IO.Ports.Parity.None
.StopBits = IO.Ports.StopBits.One
.Handshake = IO.Ports.Handshake.None
End With
Try
SerialPort1.Open()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btOn.Click
SerialPort1.Write("1")
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btOff.Click
SerialPort1.Write("0")
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Disconnect.Click
Text1.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
With SerialPort2
If .PortName = "COM9" Then
Text1.TextAlign = HorizontalAlignment.Center
Text1.ForeColor = Color.White
Text1.Text = "Port Fermé"
Text1.BackColor = Color.Red
SerialPort2.Close()
End If
End With
With SerialPort2
.PortName = "COM9"
.BaudRate = 9600
.DataBits = 8
.Parity = IO.Ports.Parity.None
.StopBits = IO.Ports.StopBits.One
.Handshake = IO.Ports.Handshake.None
End With
Try
SerialPort1.Close()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
Private Sub Text1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Text1.TextChanged
End Sub
End Class