AGENT.Contrib.Hardware.Bluetooth.Connection.GetBytes C# (CSharp) Method

GetBytes() protected method

Get a byte[] from the serial port. Will keep reading until the port returns a 0. 0 bytes were read on the port
protected GetBytes ( SerialPort port ) : byte[]
port System.IO.Ports.SerialPort
return byte[]
        protected byte[] GetBytes(SerialPort port)
        {
            byte[] bigBuffer = null;
            while (true)
            {
                //new up a buffer to read the available bytes
                byte[] buffer = new byte[port.BytesToRead];
                //read all of the available bytes, only read the buffer length
                int count = port.Read(buffer, 0, buffer.Length);
                //combine what we had before with the new data
                bigBuffer = CombineArrays(buffer, bigBuffer);
                if (count <= 0)
                {
                    var result = _channel.ConvertTo(bigBuffer);
                    if (OnReceived != null) OnReceived(result, _port, _channel, DateTime.Now);
                }  

            }

            return bigBuffer;
        }