Example #1
0
        public byte[] ReadData()
        {
            var len = port.Read(buffer, READ_WAIT_MILLIS);

            if (len > 0)
            {
                var data = new byte[len];
                Array.Copy(buffer, data, len);
                return(data);
            }
            else
            {
                return(new byte[1]);
            }
        }
        void Step()
        {
            // handle incoming data.
            var len = port.Read(buffer, READ_WAIT_MILLIS);

            if (len > 0)
            {
                Log.Debug(TAG, "Read data len=" + len);

                var data = new byte[len];
                Array.Copy(buffer, data, len);
                DataReceived.Raise(this, new SerialDataReceivedArgs(data));
            }
        }
        public Task <byte[]> Read(int count)
        {
            var output = new byte[count];
            int i      = 0;

            while (i < count)
            {
                var chunk = new byte[count];
                var read  = port.Read(chunk, 200);
                chunk.CopyTo(output, i);
                i += read;
            }
            return(Task.FromResult(output));
        }