Пример #1
0
        /// <summary>Enumerates connected relays.  RegisterYocto must have been called first</summary>
        public static IEnumerable <YRelay> IterateRelays()
        {
            YRelay relay = YRelay.FirstRelay();

            while (relay != null)
            {
                yield return(relay);

                relay = relay.nextRelay();
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            string errmsg = "";
            string target;
            YRelay relay;
            string state;
            string channel;

            if (args.Length < 3)
            {
                usage();
            }
            target  = args[0].ToUpper();
            channel = args[1];
            state   = args[2].ToUpper();

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

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

            Console.WriteLine("using " + target);
            relay = YRelay.FindRelay(target + ".relay" + channel);

            if (relay.isOnline())
            {
                if (state == "ON")
                {
                    relay.set_output(YRelay.OUTPUT_ON);
                }
                else
                {
                    relay.set_output(YRelay.OUTPUT_OFF);
                }
            }
            else
            {
                Console.WriteLine("Module not connected");
                Console.WriteLine("check identification and USB cable");
            }
            YAPI.FreeAPI();
        }
Пример #3
0
        public static YRelayProxy FindRelay(string name)
        {
            // cases to handle:
            // name =""  no matching unknwn
            // name =""  unknown exists
            // name != "" no  matching unknown
            // name !="" unknown exists
            YRelay      func = null;
            YRelayProxy res  = (YRelayProxy)YFunctionProxy.FindSimilarUnknownFunction("YRelayProxy");

            if (name == "")
            {
                if (res != null)
                {
                    return(res);
                }
                res = (YRelayProxy)YFunctionProxy.FindSimilarKnownFunction("YRelayProxy");
                if (res != null)
                {
                    return(res);
                }
                func = YRelay.FirstRelay();
                if (func != null)
                {
                    name = func.get_hardwareId();
                    if (func.get_userData() != null)
                    {
                        return((YRelayProxy)func.get_userData());
                    }
                }
            }
            else
            {
                func = YRelay.FindRelay(name);
                if (func.get_userData() != null)
                {
                    return((YRelayProxy)func.get_userData());
                }
            }
            if (res == null)
            {
                res = new YRelayProxy(func, name);
            }
            if (func != null)
            {
                res.linkToHardware(name);
                if (func.isOnline())
                {
                    res.arrival();
                }
            }
            return(res);
        }
Пример #4
0
        /**
         * <summary>
         *   Enumerates all functions of type Relay 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>YRelay.FindRelay</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>();
            YRelay        it  = YRelay.FirstRelay();

            while (it != null)
            {
                res.Add(it.get_hardwareId());
                it = it.nextRelay();
            }
            return(res.ToArray());
        }
Пример #5
0
        static void Main(string[] args)
        {
            string errmsg = "";
            string target;
            YRelay relay;
            string state;

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

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

            if (target == "ANY")
            {
                relay = YRelay.FirstRelay();
                if (relay == null)
                {
                    Console.WriteLine("No module connected (check USB cable) ");
                    Environment.Exit(0);
                }
            }
            else
            {
                relay = YRelay.FindRelay(target + ".relay1");
            }

            if (relay.isOnline())
            {
                if (state == "A")
                {
                    relay.set_state(YRelay.STATE_A);
                }
                else
                {
                    relay.set_state(YRelay.STATE_B);
                }
            }
            else
            {
                Console.WriteLine("Module not connected");
                Console.WriteLine("check identification and USB cable");
            }
            YAPI.FreeAPI();
        }
Пример #6
0
        public override async Task <int> Run()
        {
            try {
                await YAPI.RegisterHub(HubURL);

                YRelay relay;

                if (Target.ToLower() == "any")
                {
                    relay = YRelay.FirstRelay();
                    if (relay == null)
                    {
                        WriteLine("No module connected (check USB cable) ");
                        return(-1);
                    }
                }
                else
                {
                    relay = YRelay.FindRelay(Target + ".relay1");
                }

                if (await relay.isOnline())
                {
                    if (RequestedState.ToUpper() == "A")
                    {
                        await relay.set_state(YRelay.STATE_A);
                    }
                    else
                    {
                        await relay.set_state(YRelay.STATE_B);
                    }
                }
                else
                {
                    WriteLine("Module not connected (check identification and USB cable)");
                }
            } catch (YAPI_Exception ex) {
                WriteLine("error: " + ex.Message);
            }

            YAPI.FreeAPI();
            return(0);
        }
Пример #7
0
        public override async Task <int> Run()
        {
            try {
                await YAPI.RegisterHub(HubURL);

                YRelay relay;
                if (Target.ToLower() == "any")
                {
                    relay = YRelay.FirstRelay();
                    if (relay == null)
                    {
                        WriteLine("No module connected (check USB cable) ");
                        return(-1);
                    }

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

                WriteLine("using " + Target + ".relay" + Channel);
                relay = YRelay.FindRelay(Target + ".relay" + Channel);

                if (await relay.isOnline())
                {
                    if (RequestedState.ToUpper() == "ON")
                    {
                        await relay.set_output(YRelay.OUTPUT_ON);
                    }
                    else
                    {
                        await relay.set_output(YRelay.OUTPUT_OFF);
                    }
                }
                else
                {
                    WriteLine("Module not connected (check identification and USB cable)");
                }
            } catch (YAPI_Exception ex) {
                WriteLine("error: " + ex.Message);
            }

            YAPI.FreeAPI();
            return(0);
        }