Exemplo n.º 1
0
        public int Read(byte[] buf, int offset, int len)
        {
            if (!fd.HasValue || len > READING_BUFFER_SIZE)
            {
                throw new Exception();
            }

            int res = ComWrapper.com_read(fd.Value, readingBuffer, len);

            if (res != -1)
            {
                Marshal.Copy(readingBuffer, buf, offset, res);
            }
            else
            {
                throw new Exception();
            }

            return(res);
        }
Exemplo n.º 2
0
        private void StartReading()
        {
            if (!fd.HasValue)
            {
                throw new Exception();
            }

            while (true)
            {
                CancellationToken.ThrowIfCancellationRequested();

                int res = ComWrapper.com_read(fd.Value, readingBuffer, READING_BUFFER_SIZE);
                if (res != -1)
                {
                    byte[] buf = new byte[res];
                    Marshal.Copy(readingBuffer, buf, 0, res);
                    OnDataReceived(buf);
                }

                Thread.Sleep(50);
            }
        }