Ejemplo n.º 1
0
        public override async Task <int> Run()
        {
            try {
                await YAPI.RegisterHub(HubURL);

                YPwmInput pwm;
                YPwmInput pwm1 = null;
                YPwmInput pwm2 = null;
                YModule   m    = null;
                if (Target.ToLower() == "any")
                {
                    // retreive any pwm input available
                    pwm = YPwmInput.FirstPwmInput();
                    if (pwm == null)
                    {
                        WriteLine("No module connected");
                        return(-1);
                    }
                }
                else
                {
                    // retreive the first pwm input from the device given on command line
                    pwm = YPwmInput.FindPwmInput(Target + ".pwmInput1");
                }

                // we need to retreive both channels from the device.
                if (await pwm.isOnline())
                {
                    m = await pwm.get_module();

                    pwm1 = YPwmInput.FindPwmInput(await m.get_serialNumber() + ".pwmInput1");
                    pwm2 = YPwmInput.FindPwmInput(await m.get_serialNumber() + ".pwmInput2");
                }

                while (await m.isOnline())
                {
                    WriteLine("PWM1: " + await pwm1.get_frequency() + " Hz " + await
                              pwm1.get_dutyCycle() +
                              " % " + await pwm1.get_pulseCounter() + " pulse edges ");
                    WriteLine("PWM2: " + await pwm2.get_frequency() + " Hz " + await
                              pwm2.get_dutyCycle() +
                              " % " + await pwm2.get_pulseCounter() + " pulse edges ");
                    await YAPI.Sleep(1000);
                }

                WriteLine("Module not connected (check identification and USB cable)");
            } catch (YAPI_Exception ex) {
                WriteLine("error: " + ex.Message);
            }

            YAPI.FreeAPI();
            return(0);
        }
        /**
         * <summary>
         *   Returns the pulse counter value.
         * <para>
         *   Actually that
         *   counter is incremented twice per period. That counter is
         *   limited  to 1 billion.
         * </para>
         * <para>
         * </para>
         * </summary>
         * <returns>
         *   an integer corresponding to the pulse counter value
         * </returns>
         * <para>
         *   On failure, throws an exception or returns <c>YPwmInput.PULSECOUNTER_INVALID</c>.
         * </para>
         */
        public long get_pulseCounter()
        {
            long res;

            if (_func == null)
            {
                throw new YoctoApiProxyException("No PwmInput connected");
            }
            res = _func.get_pulseCounter();
            if (res == YAPI.INVALID_INT)
            {
                res = _PulseCounter_INVALID;
            }
            return(res);
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            string    errmsg = "";
            string    target;
            YPwmInput pwm;
            YPwmInput pwm1 = null;
            YPwmInput pwm2 = null;
            YModule   m    = null;

            if (args.Length < 1)
            {
                usage();
            }
            target = args[0].ToUpper();

            // Setup the API to use local USB devices
            if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS)
            {
                Console.WriteLine("RegisterHub error: " + errmsg);
                Environment.Exit(0);
            }

            if (target == "ANY")
            {
                // retreive any pwm input available
                pwm = YPwmInput.FirstPwmInput();
                if (pwm == null)
                {
                    die("No module connected");
                }
            }
            else
            {
                // retreive the first pwm input from the device given on command line
                pwm = YPwmInput.FindPwmInput(target + ".pwmInput1");
            }

            // we need to retreive both channels from the device.
            if (pwm.isOnline())
            {
                m    = pwm.get_module();
                pwm1 = YPwmInput.FindPwmInput(m.get_serialNumber() + ".pwmInput1");
                pwm2 = YPwmInput.FindPwmInput(m.get_serialNumber() + ".pwmInput2");
            }
            else
            {
                die("Module not connected");
            }

            while (m.isOnline())
            {
                Console.WriteLine("PWM1: " + pwm1.get_frequency().ToString() + " Hz "
                                  + pwm1.get_dutyCycle().ToString() + " % "
                                  + pwm1.get_pulseCounter().ToString() + " pulse edges ");
                Console.WriteLine("PWM2: " + pwm2.get_frequency().ToString() + " Hz "
                                  + pwm2.get_dutyCycle().ToString() + " % "
                                  + pwm2.get_pulseCounter().ToString() + " pulse edges ");
                Console.WriteLine("  (press Ctrl-C to exit)");
                YAPI.Sleep(1000, ref errmsg);
            }
            YAPI.FreeAPI();
            die("Module not connected");
        }