예제 #1
0
        //
        // ere I2C-AI418ML...
        //

        private void BackgroundWorkerAdcProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            ReportAdcProgressWithStatus adcProgress = (ReportAdcProgressWithStatus)e.UserState;

            switch (adcProgress.Mode)
            {
            case AdcMode.Raw:
                textBoxAdcValue.Text = string.Format("{0}", adcProgress.Reading);
                break;

            case AdcMode.Voltage:
                textBoxAdcValue.Text = string.Format("{0:F3}v", adcProgress.Voltage);
                break;

            case AdcMode.Current:
                textBoxAdcValue.Text = string.Format("{0:F3}mA", adcProgress.Current);
                break;
            }
            if (adcProgress.StatusResults.HasErrors())
            {
                _displayError(adcProgress.StatusResults);

                checkBoxReadVoltage.Checked = false;
            }
        }
예제 #2
0
        private void BackgroundWorkerAdcDoWork(object sender, DoWorkEventArgs e)
        {
            var adc = new ere_I2C_AI418ML(_usbI2C, _ere_I2C_AI418ML_address);

            UsbI2C.StatusResults    statusResults = new UsbI2C.StatusResults();
            AdcBackgroundWorkerArgs args          = e.Argument as AdcBackgroundWorkerArgs;

            while (true)
            {
                uint   reading = 0;
                double voltage = 0.0;
                double current = 0.0;
                ReportAdcProgressWithStatus adcProgress = new ReportAdcProgressWithStatus(args.Mode, reading, voltage, current, statusResults);

                switch (args.Mode)
                {
                case AdcMode.Raw:
                    statusResults       = adc.ReadAdc(args.Channel, args.Size, args.Pga, out reading);
                    adcProgress.Reading = reading;
                    break;

                case AdcMode.Voltage:
                    statusResults       = adc.ReadVoltage(args.Channel, args.Size, args.Pga, out voltage);
                    adcProgress.Voltage = voltage;
                    break;

                case AdcMode.Current:
                    statusResults       = adc.ReadCurrent(args.Channel, args.Size, args.Pga, out voltage);
                    adcProgress.Voltage = voltage;
                    break;
                }

                _backgroundWorkerAdc.ReportProgress(0, adcProgress);

                Thread.Sleep(100);

                if (statusResults.HasErrors() || _backgroundWorkerAdc.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }
            }
        }