2 Replies Latest reply on Dec 12, 2016 11:10 PM by kaa_2152226

    How to Receive unknown number of bytes


      Iam using Discover wi-fi STM32F4DIS module. I want to receive data whose size is not known. In wiced_uart_receive_bytes() if suppose i initialized the size to be 40 bytes and iam receiving only 30 bytes this is not processing the 30 bytes and it is waiting for 40 bytes to be received. Actually i don't know the size of the data which has to be received. The data can be of any number of bytes and i need to process the received bytes.

      Please help me...



      Thank you

        • 1. Re: How to Receive unknown number of bytes

          Easiest way would be to put a header on your data. For example, if your data is 30 bytes long, you could first send the bytes 0xAB 0x1E where 0xAB is a sync byte and 0x1E is the payload length.


          Start up a thread that keeps reading single bytes of data, throwing them away until the sync byte is received. Once the sync byte is received, read one more byte to get the payload length. Then read [payload length] bytes and you should have your data.


          There are, of course, ways to make this more robust (checksums), but this should work for you.


          EDIT: edited reply with more detailed approach

          1 of 2 people found this helpful
          • 2. Re: How to Receive unknown number of bytes

            Thank you for your response!!!