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

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

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

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

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

            source = Observable.Create <DigitalInput32DataFrame>(observer =>
            {
                EventHandler <FrameReceivedEventArgs> inputReceived;
                var data_block = new DigitalInput32DataBlock(BlockSize);

                oni_ref.Environment.Start();

                inputReceived = (sender, e) =>
                {
                    var frame = e.Value;

                    // If this frame contains 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 DigitalInput32DataFrame(data_block, sample_clock_hz));
                            data_block = new DigitalInput32DataBlock(BlockSize);
                        }
                    }
                };

                oni_ref.Environment.FrameInputReceived += inputReceived;
                return(Disposable.Create(() =>
                {
                    oni_ref.Environment.FrameInputReceived -= inputReceived;
                    oni_ref.Dispose();
                }));
            });
        }
Esempio n. 2
0
 public DigitalInput32DataFrame(DigitalInput32DataBlock dataBlock, int hardware_clock_hz)
 {
     Clock     = GetClock(dataBlock.Clock);
     Time      = GetTime(dataBlock.Clock, hardware_clock_hz);
     PortState = GetState(dataBlock.PortState);
 }