For p = 1 To Len(trame) lrc = lrc Xor Asc(Mid(trame, p, 1)) Next p
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPrivate 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" End If If Microsoft.VisualBasic.Left(Text2Display, 5) = "00 2F" Then lampe = Microsoft.VisualBasic.Right(Text2Display, 6) 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 Private Sub Timer_close_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer_close.Tick Dim xmtBuf() As Byte = {&HBE, &HEF, &H10, &H5, &H0, &HC, &H3E, &H11, &H11, &H1, &H0, &H18} SerialPort.Write(xmtBuf, 0, xmtBuf.Length) SerialPort.Close() Timer_close.Enabled = False End End Sub Private Sub Timer_lampe_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer_lampe.Tick Dim xmtBuf() As Byte = {&HBE, &HEF, &H10, &H5, &H0, &HDA, &H7F, &H11, &H11, &H1, &H0, &H2F} ecoute.Text = "lampe" SerialPort.Write(xmtBuf, 0, xmtBuf.Length) Timer_lampe.Enabled = False Timer_inter.Enabled = True End Sub
SerialPort.ReadChar