Esempio n. 1
0
        private static async Task InputDemo(IAdDaBoard adDaBoard)
        {
            const double vRef = 5.0;

            adDaBoard.Input.DataRate             = InputDataRate.SampleRate50Sps;
            adDaBoard.Input.AutoSelfCalibrate    = true;
            adDaBoard.Input.DetectCurrentSources = InputDetectCurrentSources.Off;
            adDaBoard.Input.Gain           = InputGain.Gain1;
            adDaBoard.Input.UseInputBuffer = false;

            // The demo continously reads the value of the 10 kohm potentiometer knob and the photo resistor and
            // writes the values to the Output window in Visual Studio.

            while (true)
            {
                double knobValue  = adDaBoard.Input.GetInput(vRef, InputPin.AD0);
                double knobValue1 = adDaBoard.Input.GetInput(vRef, InputPin.AD1);
                double knobValue2 = adDaBoard.Input.GetInput(vRef, InputPin.AD2);
                double knobValue3 = adDaBoard.Input.GetInput(vRef, InputPin.AD3);

                Debug.WriteLine($"Knob: {knobValue:0.0000}, $knob1: {knobValue1:0.0000}, $knob2: {knobValue2:0.0000},$knob3: {knobValue3:0.0000}");

                await Task.Delay(100);
            }
        }
Esempio n. 2
0
        private static async Task InputOutputDemo(IAdDaBoard adDaBoard)
        {
            adDaBoard.Input.DataRate             = InputDataRate.SampleRate50Sps;
            adDaBoard.Input.AutoSelfCalibrate    = true;
            adDaBoard.Input.DetectCurrentSources = InputDetectCurrentSources.Off;
            adDaBoard.Input.Gain           = InputGain.Gain1;
            adDaBoard.Input.UseInputBuffer = false;

            // The demo continously reads the value of the 10 kohm potentiometer knob and sets the onboard LEDs to its value.
            // Turning the knob to its min/max positions will light up one LED and turn off the other (in the middle both will be shining, but not at full intensity).

            while (true)
            {
                // Get the normalized knob-value between -1.0 and 1.0 (which will actually be between 0.0 and 1.0 due to how the board is constructed):
                double normalizedKnobValue  = adDaBoard.Input.GetInput(1.0, InputPin.AD0);
                double normalizedKnobValue1 = adDaBoard.Input.GetInput(1.0, InputPin.AD1);
                double normalizedKnobValue2 = adDaBoard.Input.GetInput(1.0, InputPin.AD2);
                double normalizedKnobValue3 = adDaBoard.Input.GetInput(1.0, InputPin.AD3);

                // ...and the "inverted" value:
                double invertedNormalizedKnobValue = 1.0 - normalizedKnobValue;

                // Set both outputs at the same time:
                adDaBoard.Output.SetOutputs(normalizedKnobValue, invertedNormalizedKnobValue);

                await Task.Delay(10);
            }
        }
Esempio n. 3
0
        private async Task Demo()
        {
            // (Technically the demo will never end, but in a different scenario the IAdDaBoard should be disposed,
            // therefor I chose tho get the AD/DA-board in a using-statement.)

            using (IAdDaBoard adDaBoard = await AdDaBoardFactory.GetAdDaBoard().ConfigureAwait(false))
            {
                await _currentDemo(adDaBoard).ConfigureAwait(false);
            }
        }
Esempio n. 4
0
        private async Task KnobToScreenDemo(IAdDaBoard adDaBoard)
        {
            adDaBoard.Input.DataRate             = InputDataRate.SampleRate50Sps;
            adDaBoard.Input.AutoSelfCalibrate    = true;
            adDaBoard.Input.DetectCurrentSources = InputDetectCurrentSources.Off;
            adDaBoard.Input.Gain           = InputGain.Gain1;
            adDaBoard.Input.UseInputBuffer = false;

            // The demo continously reads the value of the 10 kohm potentiometer knob and both writes the
            // voltage on the screen and converts the value to an angle, rotating a canvas-drawing on the screen.

            while (true)
            {
                // Get the normalized knob-value between 0.0 and 1.0:
                double normalizedKnobValue = adDaBoard.Input.GetInput(1.0, InputPin.AD0);

                // Convert the normalized knob value to an angle between -130 and 130 degrees.
                double angle = normalizedKnobValue * 260 - 130;

                // Convert the normalized knob value to a voltage between 0.0 and 5.0 V.
                double voltage = normalizedKnobValue * 5.0;

                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
                    CoreDispatcherPriority.Normal,
                    () =>
                {
                    // Write the voltage.
                    KnobValue.Text = voltage.ToString("0.000") + " V";

                    // Rotate the canvas drawing an arrow.
                    ArrowCanvas.RenderTransform = new RotateTransform {
                        CenterX = 0.5, CenterY = 0.5, Angle = angle
                    };
                });

                await Task.Delay(100);
            }
        }
Esempio n. 5
0
        private static async Task OutputDemo(IAdDaBoard adDaBoard)
        {
            int outputLevel     = 0; // This ('outputLevel') variable will from 0 to 100 and back to 0 repeatedly ...
            int outputLevelStep = 5; // ... taking a step of this ('outputLevelStep') value at the time.

            while (true)
            {
                double normalizedOutputLevel         = outputLevel / 100.0;         // Get a floating point value between 0.0 and 1.0...
                double invertedNormalizedOutputLevel = 1.0 - normalizedOutputLevel; // ...and the "inverted"; between 1.0 and 0.0

                // Set the two outputs one at a time (of course the "SetOutputs" method could also be used here).
                adDaBoard.Output.SetOutput(OutputPin.DAC0, normalizedOutputLevel);
                adDaBoard.Output.SetOutput(OutputPin.DAC1, invertedNormalizedOutputLevel);

                outputLevel += outputLevelStep;
                if ((outputLevel == 0) || (outputLevel == 100))
                {
                    outputLevelStep = -outputLevelStep;
                }

                await Task.Delay(50);
            }
        }
Esempio n. 6
0
        /*
         *
         * <MediaElement x:Name="beeper"></MediaElement>
         *
         * private void AssignBeep()
         * {
         *  Uri beepUri = new Uri("Project;component/beep.mp3", UriKind.RelativeOrAbsolute);
         *  StreamResourceInfo streamInfo = Application.GetResourceStream(beepUri);
         *  this.beeper.SetSource(streamInfo.Stream);
         *  this.beeper.AutoPlay = false;
         * }
         *
         * private void PlayBeep()
         * {
         *  this.beeper.Position = new TimeSpan(0, 0, 0, 0);
         *  this.beeper.Volume = 1;
         *  this.beeper.Play();
         * }
         *
         */

        private async Task KnobToScreenDemo(IAdDaBoard adDaBoard)
        {
            adDaBoard.Input.DataRate             = InputDataRate.SampleRate50Sps;
            adDaBoard.Input.AutoSelfCalibrate    = true;
            adDaBoard.Input.DetectCurrentSources = InputDetectCurrentSources.Off;
            adDaBoard.Input.Gain           = InputGain.Gain1;
            adDaBoard.Input.UseInputBuffer = false;

            // The demo continously reads the value of the 10 kohm potentiometer knob and both writes the
            // voltage on the screen and converts the value to an angle, rotating a canvas-drawing on the screen.

            while (true)
            {
                // Get the normalized knob-value between 0.0 and 1.0:
                double normalizedKnobValue  = adDaBoard.Input.GetInput(1.0, InputPin.AD0);
                double normalizedKnobValue1 = adDaBoard.Input.GetInput(1.0, InputPin.AD1);
                double normalizedKnobValue2 = adDaBoard.Input.GetInput(1.0, InputPin.AD2);
                double normalizedKnobValue3 = adDaBoard.Input.GetInput(1.0, InputPin.AD3);

                // Convert the normalized knob value to an angle between -130 and 130 degrees.
                double angle  = normalizedKnobValue * 260 - 130;
                double angle1 = normalizedKnobValue1 * 260 - 130;
                double angle2 = normalizedKnobValue2 * 260 - 130;
                double angle3 = normalizedKnobValue3 * 260 - 130;

                // Convert the normalized knob value to a voltage as shown in Arduino Code.
                double voltage  = normalizedKnobValue * 6.0;
                double voltage1 = (normalizedKnobValue1 * 193) / 10;
                double voltage2 = (normalizedKnobValue2 * 193) / 10;
                double voltage3 = (normalizedKnobValue3 * 193) / 10;

                double temp;
                double barles = 116;
                //char oklevel;
                //char testcable;
                //double cabres = 30;



                temp = normalizedKnobValue1 - normalizedKnobValue;                  //temporarly stored value for calculations
                temp = temp / barles;                                               // devide by resistance in milliohms generating current
                temp = ((normalizedKnobValue3 - normalizedKnobValue2) * 10) / temp; // getting all in value of 0.1 mOhm with resolution of 0.2 mOhm



                //Write data to the file

                /*
                 * //a = time of measurement
                 * for (int a = 1; a < 60; a++)
                 * {
                 *  await Windows.Storage.FileIO.WriteTextAsync(data, voltage.ToString());
                 *  await Windows.Storage.FileIO.WriteTextAsync(data, voltage1.ToString());
                 *  await Windows.Storage.FileIO.WriteTextAsync(data, voltage2.ToString());
                 *  await Windows.Storage.FileIO.WriteTextAsync(data, voltage3.ToString());
                 *  await Windows.Storage.FileIO.WriteTextAsync(data, "\r\nand");
                 *
                 * }
                 */


                //char testmode;
                //uint barles;
                //char oklevel;


                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
                    CoreDispatcherPriority.Normal,
                    () =>
                {
                    // Write the voltage.
                    KnobValue.Text  = voltage.ToString("0.000") + " V";
                    KnobValue1.Text = voltage1.ToString("0.000") + " V";
                    KnobValue2.Text = voltage2.ToString("0.000") + " V";
                    KnobValue3.Text = voltage3.ToString("0.000") + " V";


                    // Rotate the canvas drawing an arrow.
                    //ArrowCanvas.RenderTransform = new RotateTransform { CenterX = 0.5, CenterY = 0.5, Angle = angle };
                });

                await Task.Delay(100);
            }
        }