Exemple #1
0
        static void Main(string[] args)
        {
            string             errmsg = "";
            string             target;
            YCurrentLoopOutput loop;
            double             value;

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

            if (args.Length < 2)
            {
                usage();
            }

            target = args[0].ToUpper();
            value  = Convert.ToDouble(args[1]);

            if (target == "ANY")
            {
                loop = YCurrentLoopOutput.FirstCurrentLoopOutput();
                if (loop == null)
                {
                    Console.WriteLine("No module connected (check USB cable) ");
                    Environment.Exit(0);
                }
            }
            else
            {
                loop = YCurrentLoopOutput.FindCurrentLoopOutput(target + ".currentLoopOutput");
            }

            if (loop.isOnline())
            {
                loop.set_current(value);
                int loopPower = loop.get_loopPower();
                if (loopPower == YCurrentLoopOutput.LOOPPOWER_NOPWR)
                {
                    Console.WriteLine("Current loop not powered");
                    Environment.Exit(0);
                }
                if (loopPower == YCurrentLoopOutput.LOOPPOWER_LOWPWR)
                {
                    Console.WriteLine("Insufficient voltage on current loop");
                    Environment.Exit(0);
                }

                Console.WriteLine("current loop set to " + value.ToString() + " mA");
            }
            else
            {
                Console.WriteLine("Module not connected");
                Console.WriteLine("check identification and USB cable");
            }
            YAPI.FreeAPI();
        }
        // link the instance to a real YoctoAPI object
        internal override void linkToHardware(string hwdName)
        {
            YCurrentLoopOutput hwd = YCurrentLoopOutput.FindCurrentLoopOutput(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(YCurrentLoopOutput hwd)
 {
     if (hwd == null)
     {
         return;
     }
     base.init(hwd);
     InternalStuff.log("registering CurrentLoopOutput callback");
     _func.registerValueCallback(valueChangeCallback);
 }
Exemple #4
0
        public override async Task <int> Run()
        {
            try {
                await YAPI.RegisterHub(HubURL);

                YCurrentLoopOutput loop;
                double             value = Convert.ToDouble(LoopCurrent);

                if (Target.ToLower() == "any")
                {
                    loop = YCurrentLoopOutput.FirstCurrentLoopOutput();
                    if (loop == null)
                    {
                        WriteLine("No module connected (check USB cable) ");
                        return(-1);
                    }
                }
                else
                {
                    loop = YCurrentLoopOutput.FindCurrentLoopOutput(
                        Target + ".currentLoopOutput");
                }

                if (await loop.isOnline())
                {
                    await loop.set_current(value);

                    int loopPower = await loop.get_loopPower();

                    if (loopPower == YCurrentLoopOutput.LOOPPOWER_NOPWR)
                    {
                        WriteLine("Current loop not powered");
                    }
                    else if (loopPower == YCurrentLoopOutput.LOOPPOWER_LOWPWR)
                    {
                        WriteLine("Insufficient voltage on current loop");
                    }
                    else
                    {
                        WriteLine("current loop set to " + value + " mA");
                    }
                }
                else
                {
                    WriteLine("Module not connected (check identification and USB cable)");
                }
            } catch (YAPI_Exception ex) {
                WriteLine("error: " + ex.Message);
            }

            YAPI.FreeAPI();
            return(0);
        }
        public static YCurrentLoopOutputProxy FindCurrentLoopOutput(string name)
        {
            // cases to handle:
            // name =""  no matching unknwn
            // name =""  unknown exists
            // name != "" no  matching unknown
            // name !="" unknown exists
            YCurrentLoopOutput      func = null;
            YCurrentLoopOutputProxy res  = (YCurrentLoopOutputProxy)YFunctionProxy.FindSimilarUnknownFunction("YCurrentLoopOutputProxy");

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

            while (it != null)
            {
                res.Add(it.get_hardwareId());
                it = it.nextCurrentLoopOutput();
            }
            return(res.ToArray());
        }
    /**
     * <summary>
     *   Retrieves a 4-20mA 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 4-20mA output is online at the time
     *   it is invoked. The returned object is nevertheless valid.
     *   Use the method <c>YCurrentLoopOutput.isOnline()</c> to test if the 4-20mA output is
     *   indeed online at a given time. In case of ambiguity when looking for
     *   a 4-20mA 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>
     * </summary>
     * <param name="func">
     *   a string that uniquely characterizes the 4-20mA output
     * </param>
     * <returns>
     *   a <c>YCurrentLoopOutput</c> object allowing you to drive the 4-20mA output.
     * </returns>
     */
    public static YCurrentLoopOutput FindCurrentLoopOutput(string func)
    {
        YCurrentLoopOutput obj;

        obj = (YCurrentLoopOutput)YFunction._FindFromCache("CurrentLoopOutput", func);
        if (obj == null)
        {
            obj = new YCurrentLoopOutput(func);
            YFunction._AddToCache("CurrentLoopOutput", func, obj);
        }
        return(obj);
    }
 // 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 = (YCurrentLoopOutput)hwd;
     base.base_init(hwd, instantiationName);
 }
        //--- (end of YCurrentLoopOutput definitions)

        //--- (YCurrentLoopOutput implementation)
        internal YCurrentLoopOutputProxy(YCurrentLoopOutput hwd, string instantiationName) : base(hwd, instantiationName)
        {
            InternalStuff.log("CurrentLoopOutput " + instantiationName + " instantiation");
            base_init(hwd, instantiationName);
        }