Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
SerialPort.Open()
Dim xmtBuf() As Byte = {&HBE, &HEF, &H10, &H5, &H0, &HC6, &HFF, &H11, &H11, &H1, &H0, &H1}
vga = "1"
serie = "1"
lampe = "0"
SerialPort.Write(xmtBuf, 0, xmtBuf.Length)
Timer_source.Enabled = True
End Sub
Private Sub SerialPort_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) _
Handles SerialPort.DataReceived
Dim Count As Integer = SerialPort.BytesToRead
Dim Buffer(0 To Count - 1) As Byte
Dim Text2Display As String = ""
serie = "0"
SerialPort.Read(Buffer, 0, Count)
For I As Integer = 0 To Buffer.GetUpperBound(0)
Text2Display += Buffer(I).ToString("X2") & " "
Next
If Text2Display = "00 26 00" Then
vga = "0"
affichage(Text2Display)
'ici tu case ton second test qu'il y a su ton timer
End If
If Microsoft.VisualBasic.Left(Text2Display, 5) = "00 2F" Then
lampe = Microsoft.VisualBasic.Right(Text2Display, 6)
'ici le 3eme test ou alors tu cloture le port
End If
affichage(Text2Display)
End Sub
Private Sub affichage(ByVal [text] As String)
If Me.ecoute.InvokeRequired Then
Dim d As New SetTextCallback(AddressOf affichage)
Me.Invoke(d, New Object() {[text]})
Else
Me.ecoute.Text = [text]
End If
End Sub
Private Sub Timer_source_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer_source.Tick
Dim xmtBuf() As Byte = {&HBE, &HEF, &H10, &H5, &H0, &HDC, &HBF, &H11, &H11, &H1, &H0, &H26}
SerialPort.Write(xmtBuf, 0, xmtBuf.Length)
ecoute.Text = "source"
Timer_source.Enabled = False
Timer_lampe.Enabled = True
End Sub
j'ai mit des annotation
en utilisant cela tu n'a plus que 1 timer