Пример #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);
        }
Пример #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);
        }
Пример #3
0
 // perform the 2nd stage setup that requires YoctoAPI object
 protected void init(YPwmOutput hwd)
 {
     if (hwd == null)
     {
         return;
     }
     base.init(hwd);
     InternalStuff.log("registering PwmOutput callback");
     _func.registerValueCallback(valueChangeCallback);
 }
Пример #4
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();
        }
    /**
     * <summary>
     *   Retrieves a PWM for a given identifier.
     * <para>
     *   The identifier can be specified using several formats:
     * </para>
     * <para>
     * </para>
     * <para>
     *   - FunctionLogicalName
     * </para>
     * <para>
     *   - ModuleSerialNumber.FunctionIdentifier
     * </para>
     * <para>
     *   - ModuleSerialNumber.FunctionLogicalName
     * </para>
     * <para>
     *   - ModuleLogicalName.FunctionIdentifier
     * </para>
     * <para>
     *   - ModuleLogicalName.FunctionLogicalName
     * </para>
     * <para>
     * </para>
     * <para>
     *   This function does not require that the PWM is online at the time
     *   it is invoked. The returned object is nevertheless valid.
     *   Use the method <c>YPwmOutput.isOnline()</c> to test if the PWM is
     *   indeed online at a given time. In case of ambiguity when looking for
     *   a PWM by logical name, no error is notified: the first instance
     *   found is returned. The search is performed first by hardware name,
     *   then by logical name.
     * </para>
     * </summary>
     * <param name="func">
     *   a string that uniquely characterizes the PWM
     * </param>
     * <returns>
     *   a <c>YPwmOutput</c> object allowing you to drive the PWM.
     * </returns>
     */
    public static YPwmOutput FindPwmOutput(string func)
    {
        YPwmOutput obj;

        obj = (YPwmOutput)YFunction._FindFromCache("PwmOutput", func);
        if (obj == null)
        {
            obj = new YPwmOutput(func);
            YFunction._AddToCache("PwmOutput", func, obj);
        }
        return(obj);
    }
Пример #6
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);
        }
Пример #7
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());
        }
 /**
  * <summary>
  *   Retrieves a PWM for a given identifier.
  * <para>
  *   The identifier can be specified using several formats:
  * </para>
  * <para>
  * </para>
  * <para>
  *   - FunctionLogicalName
  * </para>
  * <para>
  *   - ModuleSerialNumber.FunctionIdentifier
  * </para>
  * <para>
  *   - ModuleSerialNumber.FunctionLogicalName
  * </para>
  * <para>
  *   - ModuleLogicalName.FunctionIdentifier
  * </para>
  * <para>
  *   - ModuleLogicalName.FunctionLogicalName
  * </para>
  * <para>
  * </para>
  * <para>
  *   This function does not require that the PWM is online at the time
  *   it is invoked. The returned object is nevertheless valid.
  *   Use the method <c>YPwmOutput.isOnline()</c> to test if the PWM is
  *   indeed online at a given time. In case of ambiguity when looking for
  *   a PWM by logical name, no error is notified: the first instance
  *   found is returned. The search is performed first by hardware name,
  *   then by logical name.
  * </para>
  * </summary>
  * <param name="func">
  *   a string that uniquely characterizes the PWM
  * </param>
  * <returns>
  *   a <c>YPwmOutput</c> object allowing you to drive the PWM.
  * </returns>
  */
 public static YPwmOutput FindPwmOutput(string func)
 {
     YPwmOutput obj;
     obj = (YPwmOutput) YFunction._FindFromCache("PwmOutput", func);
     if (obj == null) {
         obj = new YPwmOutput(func);
         YFunction._AddToCache("PwmOutput", func, obj);
     }
     return obj;
 }
Пример #9
0
 // perform the initial setup that may be done without a YoctoAPI object (hwd can be null)
 internal override void base_init(YFunction hwd, string instantiationName)
 {
     _func = (YPwmOutput)hwd;
     base.base_init(hwd, instantiationName);
 }
Пример #10
0
        //--- (end of YPwmOutput definitions)

        //--- (YPwmOutput implementation)
        internal YPwmOutputProxy(YPwmOutput hwd, string instantiationName) : base(hwd, instantiationName)
        {
            InternalStuff.log("PwmOutput " + instantiationName + " instantiation");
            base_init(hwd, instantiationName);
        }