public AD7617Device()
        {
            // Reference to context
            this.oni_ref = ONIManager.ReserveDAQ();

            // Find the hardware clock rate
            var sample_clock_hz = (int)250e6; // TODO: oni_ref.DAQ.AcquisitionClockHz;

            // Find all RHD devices
            devices = oni_ref.DAQ.DeviceMap.Where(
                pair => pair.Value.id == (uint)Device.DeviceID.AD7617
                ).ToDictionary(x => x.Key, x => x.Value);

            // Stop here if there are no devices to use
            if (devices.Count == 0)
            {
                throw new oni.ONIException((int)oni.lib.Error.DEVIDX);
            }

            DeviceIndex         = new DeviceIndexSelection();
            DeviceIndex.Indices = devices.Keys.ToArray();

            source = Observable.Create <AD7617DataFrame>(observer =>
            {
                EventHandler <FrameReceivedEventArgs> inputReceived;
                var data_block = new AD7617DataBlock(NumChannels, BlockSize);

                oni_ref.Environment.Start();

                inputReceived = (sender, e) =>
                {
                    var frame = e.Value;
                    //If this frame contaisn data from the selected device_index
                    if (frame.DeviceIndices.Contains(DeviceIndex.SelectedIndex))
                    {
                        // Pull the sample
                        if (data_block.FillFromFrame(frame, DeviceIndex.SelectedIndex))
                        {
                            observer.OnNext(new AD7617DataFrame(data_block, sample_clock_hz)); //TODO: Does this deep copy??
                            data_block = new AD7617DataBlock(NumChannels, BlockSize);
                        }
                    }
                };

                oni_ref.Environment.FrameInputReceived += inputReceived;
                return(Disposable.Create(() =>
                {
                    oni_ref.Environment.FrameInputReceived -= inputReceived;
                    oni_ref.Environment.Stop();
                    oni_ref.Dispose();
                }));
            });
        }
示例#2
0
 public AD7617DataFrame(AD7617DataBlock dataBlock, int hardware_clock_hz)
 {
     Clock = GetClock(dataBlock.Clock);
     Time  = GetTime(dataBlock.Clock, hardware_clock_hz);
     Data  = GetData(dataBlock.Data);
 }