Beispiel #1
0
        public Rhd2000EvalBoard()
        {
            BitFileName        = "main.bit";
            SampleRate         = AmplifierSampleRate.SampleRate20000Hz;
            LowerBandwidth     = 0.1;
            UpperBandwidth     = 7500.0;
            DspCutoffFrequency = 1.0;
            DspEnabled         = true;

            source = Observable.Create <Rhd2000DataFrame>((observer, cancellationToken) =>
            {
                var activeTtlOut = ttlOut = 0;
                return(Task.Factory.StartNew(() =>
                {
                    Load();
                    var ledSequence = LedSequence();
                    try
                    {
                        evalBoard.SetTtlMode(0);
                        evalBoard.SetTtlOut(activeTtlOut);
                        evalBoard.SetContinuousRunMode(true);
                        evalBoard.EnableExternalFastSettle(ExternalFastSettleEnabled);
                        evalBoard.Run();

                        var blocksToRead = GetDataBlockReadCount(SampleRate);
                        var fifoCapacity = Rhythm.Net.Rhd2000EvalBoard.FifoCapacityInWords();

                        var queue = new Queue <Rhd2000DataBlock>();
                        ledSequence.MoveNext();
                        while (!cancellationToken.IsCancellationRequested)
                        {
                            if (activeTtlOut != ttlOut)
                            {
                                activeTtlOut = ttlOut;
                                evalBoard.SetTtlOut(activeTtlOut);
                            }

                            if (evalBoard.ReadDataBlocks(blocksToRead, queue))
                            {
                                var wordsInFifo = evalBoard.NumWordsInFifo();
                                var bufferPercentageCapacity = 100.0 * wordsInFifo / fifoCapacity;
                                foreach (var dataBlock in queue)
                                {
                                    observer.OnNext(new Rhd2000DataFrame(dataBlock, bufferPercentageCapacity));
                                }
                                queue.Clear();
                                ledSequence.MoveNext();
                            }
                        }
                    }
                    finally
                    {
                        ledSequence.Dispose();
                        evalBoard.ClearTtlOut();
                        evalBoard.SetContinuousRunMode(false);
                        evalBoard.SetMaxTimeStep(0);
                        evalBoard.Flush();
                        evalBoard.Close();
                        evalBoard = null;
                        chipRegisters = null;
                    }
                },
                                             cancellationToken,
                                             TaskCreationOptions.LongRunning,
                                             TaskScheduler.Default));
            })
                     .PublishReconnectable()
                     .RefCount();
        }