示例#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);
        }
示例#2
0
 public void FromBytes_values_conversion_for_10_or_8bit([Values(true, false)] bool voltage10bit)
 {
     DataSampleConverter.FromBytes(new byte[7] {
         0, 133, 128, 1, 0, 0, 0
     }, DateTimeOffset.UtcNow, voltage10bit)
     .Voltage
     .Should().BeApproximately(2.609d, TOLERANCE);
 }
示例#3
0
        public void ToBytes_FromBytes_roundtrip_conversion_for_10_or_8bit([Values(true, false)] bool voltage10bit)
        {
            var inputSample = new DataSample(DateTimeOffset.UtcNow, 4.679d);

            var bytes        = DataSampleConverter.ToBytes(inputSample, voltage10bit);
            var resultSample = DataSampleConverter.FromBytes(bytes, DateTimeOffset.UtcNow, voltage10bit);

            resultSample.Voltage
            .Should().BeApproximately(inputSample.Voltage, TOLERANCE);
        }