Ejemplo n.º 1
0
        PollingLoop CreatePollingLoop()
        {
            Contract.Assert(AttachedDevice.HasValue);

            bool useMaxPollingInterval = (DeviceConstants.MaxPollingInterval == PollingInterval);
            var  request = useMaxPollingInterval ? DataRequest.Periodic : DataRequest.Frequent;

            var stream = DeviceManager.OpenDeviceStream(AttachedDevice.Value);

            var pollingLoop = new PollingLoop
                              (
                stream, request, PollingInterval,
                (timeStamp, bytes) =>
                DataSampleConverter.FromBytes
                (
                    bytes, timeStamp,
                    Use10BitVoltage,
                    useMaxPollingInterval
                ),
                EventsQueue
                              );

            pollingLoop.DataReceived += (s, args) => Readings.AddSample(args.Sample);
            pollingLoop.Disposed     += (s, args) => Stop();

            return(pollingLoop);
        }