Concatenating serial buffers

Discussion in 'Questions (Windows Mobile)' started by mjcoon, Jun 29, 2008.

  1. mjcoon

    mjcoon Well-Known Member Licensed User

    I've been asking questions about serial input and arrays and am now seeking clarification of the process of adding subsequently-arrived bytes to those already received.

    It is handy to have the array size set exactly right for the bytes in the serial buffer. But when I get more and wish to add them I find that the ArrayCopy() function needs a target array size large enough for both sets of bytes.

    Does this mean that, because if I re-Dim the original array I lose its contents, I have to create a new array of the total size needed, do two ArrayCopy operations to load the two sequences of bytes, and then assign the new array back into the old buffer so that the rest of the code can continue as if all bytes had arrived together?

    It seems a bit like hard work for both me and for the device, though admittedly only a few tens of bytes are involved at any one time.

    Regards, Mike.
  2. Erel

    Erel Administrator Staff Member Licensed User

    Another solution is to create one large array and one small array.
    Read the data from the serial port with the small array and copy the data to the large array.
    Use another global variable to store the last position in the large array.

    Make sure to declare both arrays types as byte.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice