VMB1usb and coding in VB.net question

Hello
I’m a student and I’m developping an application (VB.net 2008) for the velbus system.
I’ve already created an application similar to the velbuslink.
Now I hope that somebody can explain me how the comport buffer works.

Here I present some code that I use.

Dim compoort As New SerialPort
...

Try
            compoort.Read(recvBuffer, 0, recvBuffer.Length)
        Catch ex As Exception
            Console.WriteLine("compoort read exception")
        End Try

The problem I encounter is that when I try to read the memory of the vmbpb8.
That my receivebuffer gets messed up.
In normal circomstances when I receive a packet, my buffer contains only the bytes of 1 packet.
Sometimes the receivebuffer contains more packets, but the most recent is in front of the buffer.
But when I try to read the memory of the vmb8pb after ± 29 send/received packets the buffers gets scrumbled.
What I mean with scrumbled is that my receivebuffer doesn’t begin with &H 0FFB… . (normaly it does).

Now I hope that somebody can explain how these buffer works.
When it is cleared, when the received event is triggered (by received byte or by received packet) and so on?

You need to use the SerialPort class in VB.NET 2008
msdn.microsoft.com/en-us/library … lport.aspx

When data arrives at the COM port it is not certain in what chunks that data will arrive in your software. For example, a packet of eight bytes might arrive with two events: first 6 bytes, then 2 bytes (as an example). So you would need to wait for all eight bytes to arrive before being able to use the packet. Also, a remnant of another packet might still be incoming when you connect to the bus, giving you data that you can’t use.

Therefore it is best to keep collecting data and parsing it as you go.

Our Velbus library for .NET contains all the code you need:
viewtopic.php?f=13&t=383