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

                YPwmOutput pwmoutput1;
                YPwmOutput pwmoutput2;
                int        frequency;
                double     dutyCycle;

                frequency = Convert.ToInt32(RequestedFrequency);
                dutyCycle = Convert.ToDouble(RequestedDutyCycle);

                if (Target.ToLower() == "any")
                {
                    pwmoutput1 = YPwmOutput.FirstPwmOutput();
                    if (pwmoutput1 == null)
                    {
                        WriteLine("No module connected (check USB cable) ");
                        return(-1);
                    }

                    Target = await(await pwmoutput1.get_module()).get_serialNumber();
                }

                pwmoutput1 = YPwmOutput.FindPwmOutput(Target + ".pwmOutput1");
                pwmoutput2 = YPwmOutput.FindPwmOutput(Target + ".pwmOutput2");

                if (await pwmoutput1.isOnline())
                {
                    // output 1 : immediate change
                    await pwmoutput1.set_frequency(frequency);

                    await pwmoutput1.set_enabled(YPwmOutput.ENABLED_TRUE);

                    await pwmoutput1.set_dutyCycle(dutyCycle);

                    // output 2 : smooth change
                    await pwmoutput2.set_frequency(frequency);

                    await pwmoutput2.set_enabled(YPwmOutput.ENABLED_TRUE);

                    await pwmoutput2.dutyCycleMove(dutyCycle, 3000);

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

            YAPI.FreeAPI();
            return(0);
        }
Example #2
0
        static void Main(string[] args)
        {
            string     errmsg = "";
            string     target;
            YPwmOutput pwmoutput1;
            YPwmOutput pwmoutput2;
            int        frequency;
            double     dutyCycle;

            if (args.Length < 3)
            {
                usage();
            }
            target    = args[0].ToUpper();
            frequency = Convert.ToInt32(args[1]);
            dutyCycle = Convert.ToDouble(args[2]);

            if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS)
            {
                Console.WriteLine("RegisterHub error: " + errmsg);
                Environment.Exit(0);
            }

            if (target == "ANY")
            {
                pwmoutput1 = YPwmOutput.FirstPwmOutput();
                if (pwmoutput1 == null)
                {
                    Console.WriteLine("No module connected (check USB cable) ");
                    Environment.Exit(0);
                }
                target = pwmoutput1.get_module().get_serialNumber();
            }

            pwmoutput1 = YPwmOutput.FindPwmOutput(target + ".pwmOutput1");
            pwmoutput2 = YPwmOutput.FindPwmOutput(target + ".pwmOutput2");

            if (pwmoutput1.isOnline())
            {
                // output 1 : immediate change
                pwmoutput1.set_frequency(frequency);
                pwmoutput1.set_enabled(YPwmOutput.ENABLED_TRUE);
                pwmoutput1.set_dutyCycle(dutyCycle);
                // output 2 : smooth change
                pwmoutput2.set_frequency(frequency);
                pwmoutput2.set_enabled(YPwmOutput.ENABLED_TRUE);
                pwmoutput2.dutyCycleMove(dutyCycle, 3000);
            }
            else
            {
                Console.WriteLine("Module not connected");
                Console.WriteLine("check identification and USB cable");
            }
            YAPI.FreeAPI();
        }
Example #3
0
        public static YPwmOutputProxy FindPwmOutput(string name)
        {
            // cases to handle:
            // name =""  no matching unknwn
            // name =""  unknown exists
            // name != "" no  matching unknown
            // name !="" unknown exists
            YPwmOutput      func = null;
            YPwmOutputProxy res  = (YPwmOutputProxy)YFunctionProxy.FindSimilarUnknownFunction("YPwmOutputProxy");

            if (name == "")
            {
                if (res != null)
                {
                    return(res);
                }
                res = (YPwmOutputProxy)YFunctionProxy.FindSimilarKnownFunction("YPwmOutputProxy");
                if (res != null)
                {
                    return(res);
                }
                func = YPwmOutput.FirstPwmOutput();
                if (func != null)
                {
                    name = func.get_hardwareId();
                    if (func.get_userData() != null)
                    {
                        return((YPwmOutputProxy)func.get_userData());
                    }
                }
            }
            else
            {
                func = YPwmOutput.FindPwmOutput(name);
                if (func.get_userData() != null)
                {
                    return((YPwmOutputProxy)func.get_userData());
                }
            }
            if (res == null)
            {
                res = new YPwmOutputProxy(func, name);
            }
            if (func != null)
            {
                res.linkToHardware(name);
                if (func.isOnline())
                {
                    res.arrival();
                }
            }
            return(res);
        }
Example #4
0
        /**
         * <summary>
         *   Enumerates all functions of type PwmOutput available on the devices
         *   currently reachable by the library, and returns their unique hardware ID.
         * <para>
         *   Each of these IDs can be provided as argument to the method
         *   <c>YPwmOutput.FindPwmOutput</c> to obtain an object that can control the
         *   corresponding device.
         * </para>
         * </summary>
         * <returns>
         *   an array of strings, each string containing the unique hardwareId
         *   of a device function currently connected.
         * </returns>
         */
        public static new string[] GetSimilarFunctions()
        {
            List <string> res = new List <string>();
            YPwmOutput    it  = YPwmOutput.FirstPwmOutput();

            while (it != null)
            {
                res.Add(it.get_hardwareId());
                it = it.nextPwmOutput();
            }
            return(res.ToArray());
        }