Exemplo n.º 1
0
        // link the instance to a real YoctoAPI object
        internal override void linkToHardware(string hwdName)
        {
            YPwmOutput hwd = YPwmOutput.FindPwmOutput(hwdName);

            // first redo base_init to update all _func pointers
            base_init(hwd, hwdName);
            // then setup Yocto-API pointers and callbacks
            init(hwd);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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();
        }
Exemplo n.º 4
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);
        }