Example #1
0
        public byte[] read(IOBuffer buffer, bool raw = false)
        {
            if (!is_enabled())
            {
                throw new Exception("Channel must be enabled before the IOBuffer is instancied");
            }
            if (is_output())
            {
                throw new Exception("Unable to read from output channel");
            }

            byte[]       array  = new byte[(int)(buffer.get_samples_count() * sample_size)];
            MemoryStream stream = new MemoryStream(array, true);
            IntPtr       addr   = GCHandle.Alloc(array, GCHandleType.Pinned).AddrOfPinnedObject();
            uint         count;

            if (raw)
            {
                count = iio_channel_read_raw(this.chn, buffer.buf, addr, buffer.get_samples_count() * sample_size);
            }
            else
            {
                count = iio_channel_read(this.chn, buffer.buf, addr, buffer.get_samples_count() * sample_size);
            }
            stream.SetLength((long)count);
            return(stream.ToArray());
        }