I am having trouble with the following piece of code, the searchIndex always returns -1. If I put a breakpoint after 'searchIndex = Array.IndexOf(buffer, &H90)' and look in the buffer array I can see 90h so it should return the index but it doesn't.
This code is in my serialport DataReceived sub
Any help would be great!
Thanks
Code:Dim searchIndex As Integer Dim buffer() As Byte = New Byte() {} Dim bytesRead As Integer bytesRead = SerialPort.BytesToRead ' Get how many bytes available. Array.Resize(buffer, bytesRead) ' Set the buffer to the number of bytes available. bytesRead = SerialPort.Read(buffer, 0, bytesRead) ' Read the bytes If bytesRead > 0 Then searchIndex = Array.IndexOf(buffer, &H90) If searchIndex <> -1 AndAlso buffer(searchIndex + 1) = &H90 Then If (searchIndex + 18) <= buffer.Length Then For x As Integer = searchIndex To (searchIndex + 18) Debug.WriteLine(buffer(x).ToString) Next End If End If End If




Reply With Quote