예제 #1
0
        public void PinFunctionTimeoutTest()
        {
            Console.WriteLine("Starting pin functions timeout functionality test...");

            /* Timer for measuring elapsed time */
            Stopwatch timer = new Stopwatch();

            for (uint timeout = 100; timeout <= 800; timeout += 100)
            {
                Console.WriteLine("Testing timeout of " + timeout.ToString() + "ms...");
                FX3.SetPin(FX3.DIO4, 1);

                /* Pulse wait */
                timer.Restart();
                FX3.PulseWait(FX3.DIO3, 0, 0, timeout);
                timer.Stop();
                Console.WriteLine("Pulse wait time: " + timer.ElapsedMilliseconds.ToString() + "ms");
                Assert.GreaterOrEqual(timer.ElapsedMilliseconds, timeout, "ERROR: Function returned in less than timeout period");
                Assert.LessOrEqual(timer.ElapsedMilliseconds, timeout + 100, "ERROR: Function returned in over 100ms more than timeout period");
                CheckFirmwareResponsiveness();

                /* Measure pin freq */
                timer.Restart();
                Assert.AreEqual(double.PositiveInfinity, FX3.MeasurePinFreq(FX3.DIO4, 0, timeout, 1), "ERROR: Invalid pin freq. Expected timeout");
                timer.Stop();
                Console.WriteLine("Measure pin freq time: " + timer.ElapsedMilliseconds.ToString() + "ms");
                Assert.GreaterOrEqual(timer.ElapsedMilliseconds, timeout, "ERROR: Function returned in less than timeout period");
                Assert.LessOrEqual(timer.ElapsedMilliseconds, timeout + 100, "ERROR: Function returned in over 100ms more than timeout period");
                CheckFirmwareResponsiveness();

                /* Measure pin delay */
                timer.Restart();
                FX3.MeasurePinDelay(FX3.DIO4, 0, FX3.DIO1, timeout);
                timer.Stop();
                Console.WriteLine("Measure pin delay time: " + timer.ElapsedMilliseconds.ToString() + "ms");
                Assert.GreaterOrEqual(timer.ElapsedMilliseconds, timeout, "ERROR: Function returned in less than timeout period");
                Assert.LessOrEqual(timer.ElapsedMilliseconds, timeout + 100, "ERROR: Function returned in over 100ms more than timeout period");
                CheckFirmwareResponsiveness();

                /* Measure busy pulse */
                timer.Restart();
                Assert.AreEqual(double.PositiveInfinity, FX3.MeasureBusyPulse(FX3.DIO4, 1, 1, FX3.DIO1, 0, timeout), "ERROR: Expected measure busy pulse to return timeout");
                timer.Stop();
                Console.WriteLine("Measure busy pulse time: " + timer.ElapsedMilliseconds.ToString() + "ms");
                Assert.GreaterOrEqual(timer.ElapsedMilliseconds, timeout, "ERROR: Function returned in less than timeout period");
                Assert.LessOrEqual(timer.ElapsedMilliseconds, timeout + 100, "ERROR: Function returned in over 100ms more than timeout period");
                CheckFirmwareResponsiveness();
            }
        }