// link the instance to a real YoctoAPI object
        internal override void linkToHardware(string hwdName)
        {
            YVoltageOutput hwd = YVoltageOutput.FindVoltageOutput(hwdName);

            // first redo base_init to update all _func pointers
            base_init(hwd, hwdName);
            // then setup Yocto-API pointers and callbacks
            init(hwd);
        }
 // perform the 2nd stage setup that requires YoctoAPI object
 protected void init(YVoltageOutput hwd)
 {
     if (hwd == null)
     {
         return;
     }
     base.init(hwd);
     InternalStuff.log("registering VoltageOutput callback");
     _func.registerValueCallback(valueChangeCallback);
 }
        public static YVoltageOutputProxy FindVoltageOutput(string name)
        {
            // cases to handle:
            // name =""  no matching unknwn
            // name =""  unknown exists
            // name != "" no  matching unknown
            // name !="" unknown exists
            YVoltageOutput      func = null;
            YVoltageOutputProxy res  = (YVoltageOutputProxy)YFunctionProxy.FindSimilarUnknownFunction("YVoltageOutputProxy");

            if (name == "")
            {
                if (res != null)
                {
                    return(res);
                }
                res = (YVoltageOutputProxy)YFunctionProxy.FindSimilarKnownFunction("YVoltageOutputProxy");
                if (res != null)
                {
                    return(res);
                }
                func = YVoltageOutput.FirstVoltageOutput();
                if (func != null)
                {
                    name = func.get_hardwareId();
                    if (func.get_userData() != null)
                    {
                        return((YVoltageOutputProxy)func.get_userData());
                    }
                }
            }
            else
            {
                func = YVoltageOutput.FindVoltageOutput(name);
                if (func.get_userData() != null)
                {
                    return((YVoltageOutputProxy)func.get_userData());
                }
            }
            if (res == null)
            {
                res = new YVoltageOutputProxy(func, name);
            }
            if (func != null)
            {
                res.linkToHardware(name);
                if (func.isOnline())
                {
                    res.arrival();
                }
            }
            return(res);
        }
        /**
         * <summary>
         *   Enumerates all functions of type VoltageOutput 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>YVoltageOutput.FindVoltageOutput</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>();
            YVoltageOutput it  = YVoltageOutput.FirstVoltageOutput();

            while (it != null)
            {
                res.Add(it.get_hardwareId());
                it = it.nextVoltageOutput();
            }
            return(res.ToArray());
        }
Beispiel #5
0
    /**
     * <summary>
     *   Retrieves a voltage output 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 voltage output is online at the time
     *   it is invoked. The returned object is nevertheless valid.
     *   Use the method <c>YVoltageOutput.isOnline()</c> to test if the voltage output is
     *   indeed online at a given time. In case of ambiguity when looking for
     *   a voltage output 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>
     * <para>
     *   If a call to this object's is_online() method returns FALSE although
     *   you are certain that the matching device is plugged, make sure that you did
     *   call registerHub() at application initialization time.
     * </para>
     * <para>
     * </para>
     * </summary>
     * <param name="func">
     *   a string that uniquely characterizes the voltage output
     * </param>
     * <returns>
     *   a <c>YVoltageOutput</c> object allowing you to drive the voltage output.
     * </returns>
     */
    public static YVoltageOutput FindVoltageOutput(string func)
    {
        YVoltageOutput obj;

        lock (YAPI.globalLock) {
            obj = (YVoltageOutput)YFunction._FindFromCache("VoltageOutput", func);
            if (obj == null)
            {
                obj = new YVoltageOutput(func);
                YFunction._AddToCache("VoltageOutput", func, obj);
            }
        }
        return(obj);
    }
Beispiel #6
0
        static void Main(string[] args)
        {
            string         errmsg = "";
            string         target;
            YVoltageOutput vout1;
            YVoltageOutput vout2;
            double         voltage;

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

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

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

            vout1 = YVoltageOutput.FindVoltageOutput(target + ".voltageOutput1");
            vout2 = YVoltageOutput.FindVoltageOutput(target + ".voltageOutput2");

            if (vout1.isOnline())
            {
                // output 1 : immediate change
                vout1.set_currentVoltage(voltage);
                // output 2 : smooth change
                vout2.voltageMove(voltage, 3000);
            }
            else
            {
                Console.WriteLine("Module not connected");
                Console.WriteLine("check identification and USB cable");
            }
            YAPI.FreeAPI();
        }
Beispiel #7
0
        public override async Task <int> Run()
        {
            try {
                await YAPI.RegisterHub(HubURL);

                YVoltageOutput vout1;
                YVoltageOutput vout2;
                double         voltage;

                voltage = Convert.ToDouble(RequestedVoltage);
                if (Target.ToLower() == "any")
                {
                    vout1 = YVoltageOutput.FirstVoltageOutput();
                    if (vout1 == null)
                    {
                        WriteLine("No module connected (check USB cable) ");
                        return(-1);
                    }

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

                vout1 = YVoltageOutput.FindVoltageOutput(Target + ".voltageOutput1");
                vout2 = YVoltageOutput.FindVoltageOutput(Target + ".voltageOutput2");

                if (await vout1.isOnline())
                {
                    WriteLine("output 1 : immediate change to " + voltage);
                    await vout1.set_currentVoltage(voltage);

                    WriteLine("output 2 : immediate smooth change to " + voltage);
                    await vout2.voltageMove(voltage, 3000);
                }
                else
                {
                    WriteLine("Module not connected (check identification and USB cable)");
                }
            } catch (YAPI_Exception ex) {
                WriteLine("error: " + ex.Message);
            }

            YAPI.FreeAPI();
            return(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 = (YVoltageOutput)hwd;
     base.base_init(hwd, instantiationName);
 }
        //--- (end of YVoltageOutput definitions)

        //--- (YVoltageOutput implementation)
        internal YVoltageOutputProxy(YVoltageOutput hwd, string instantiationName) : base(hwd, instantiationName)
        {
            InternalStuff.log("VoltageOutput " + instantiationName + " instantiation");
            base_init(hwd, instantiationName);
        }