title: Reading 4 byte array sent as individual bytes
body: <p>I'm writing this with C# and .net 2.0</p>
  
  <p>I'm being sent a 4 byte array by a device as individual bytes.</p>
  
  <p>I currently read this in the following way</p>
  
  <pre><code>while(m_ReadThreadisRunning)
  {       
    if(canRead)
    {
      lock (m_Serialport)
      {
        try
        {
          //Check if data read needs reset
          if(DataRead[3] != 0)
          {
            m_ReadBuffer.Add(DataRead);                       
            DataRead = new byte[4];   
            ReadCounter = 0;
          }
  
          int ByteRead = m_Serialport.ReadByte();     
          Debug.Log("Byte : " + ByteRead);
  
          try
          {
            DataRead[ReadCounter] = ConvertIntToByte(ByteRead);
          }
          catch(Exception e)
          {
            Debug.Log("Error when setting element in DataRead");
          }
          finally
          {
            if(ByteRead != 0)
              ReadCounter ++; 
          }
        }
        catch(TimeoutException e)
        {
        }
        catch(Exception e)
        {
            ReadCounter = 0;  
        }
      }
    }
  }
  </code></pre>
  
  <p>The problem is that multiple devices can send me information at the same time and this causes some data to end up in wrong arrays.</p>
  
  <p>A byte array being sent to me always starts with the hex '2f' and ends with the check-sum.</p>
  
  <p>Any advice on what I can do to handle this would be greatly appreciated.</p>
  
  <p>[EDIT]</p>
  
  <p>Sorry, I knew I'd miss out important information. All devices are attached to the same port. The Byte array is in the following order :- '2f' 'Device id' 'msg' 'Check-sum'.</p>