Exemple #1
0
        private void StartReading()
        {
            if (!_FileDescriptor.HasValue)
            {
                throw new Exception($"${nameof(SerialDevice)} not open");
            }


            while (true)
            {
                _CancellationToken.ThrowIfCancellationRequested();

                int res = Libc.read(_FileDescriptor.Value, _ReadingBuffer, DefaultReadBuffer);

                if (res != -1)
                {
                    byte[] buf = new byte[res];
                    Marshal.Copy(_ReadingBuffer, buf, 0, res);

                    OnDataReceived(buf);
                }

                Thread.Sleep(50);
            }
        }
        public void Read(byte[] buf)
        {
            if (!fd.HasValue)
            {
                throw new Exception();
            }

            IntPtr ptr = Marshal.AllocHGlobal(buf.Length);
            Marshal.Copy(buf, 0, ptr, buf.Length);
            Libc.read(fd.Value, ptr, buf.Length);
            Marshal.FreeHGlobal(ptr);
        }
Exemple #3
0
        private void StartReading()
        {
            if (!fd.HasValue)
            {
                throw new Exception();
            }

            while (true)
            {
                CancellationToken.ThrowIfCancellationRequested();

                int res = Libc.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);
            }
        }