Esempio n. 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);
        }
Esempio n. 3
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);
        }