Exemple #1
0
        /// <summary>
        /// This task will update cooler power based on TEC Volatage readout every three seconds
        /// Due to the fact that this value must not be updated more than every two seconds according to the documentation
        /// a helper method is required in case the device polling interval is faster than that.
        /// </summary>
        private void CoolerPowerUpdateTask()
        {
            Task.Run(async() => {
                coolerPowerReadoutCts?.Dispose();
                coolerPowerReadoutCts = new CancellationTokenSource();
                try {
                    camera.get_Option(ToupCam.eOPTION.OPTION_TEC_VOLTAGE_MAX, out var maxVoltage);
                    while (true)
                    {
                        coolerPowerReadoutCts.Token.ThrowIfCancellationRequested();

                        camera.get_Option(ToupCam.eOPTION.OPTION_TEC_VOLTAGE, out var voltage);

                        CoolerPower = 100 * voltage / (double)maxVoltage;

                        //Recommendation to not readout CoolerPower in less than two seconds.
                        await Task.Delay(TimeSpan.FromSeconds(3), coolerPowerReadoutCts.Token);
                    }
                } catch (OperationCanceledException) {
                }
            });
        }