Beispiel #1
0
        public static YCarbonDioxideProxy FindCarbonDioxide(string name)
        {
            // cases to handle:
            // name =""  no matching unknwn
            // name =""  unknown exists
            // name != "" no  matching unknown
            // name !="" unknown exists
            YCarbonDioxide      func = null;
            YCarbonDioxideProxy res  = (YCarbonDioxideProxy)YFunctionProxy.FindSimilarUnknownFunction("YCarbonDioxideProxy");

            if (name == "")
            {
                if (res != null)
                {
                    return(res);
                }
                res = (YCarbonDioxideProxy)YFunctionProxy.FindSimilarKnownFunction("YCarbonDioxideProxy");
                if (res != null)
                {
                    return(res);
                }
                func = YCarbonDioxide.FirstCarbonDioxide();
                if (func != null)
                {
                    name = func.get_hardwareId();
                    if (func.get_userData() != null)
                    {
                        return((YCarbonDioxideProxy)func.get_userData());
                    }
                }
            }
            else
            {
                func = YCarbonDioxide.FindCarbonDioxide(name);
                if (func.get_userData() != null)
                {
                    return((YCarbonDioxideProxy)func.get_userData());
                }
            }
            if (res == null)
            {
                res = new YCarbonDioxideProxy(func, name);
            }
            if (func != null)
            {
                res.linkToHardware(name);
                if (func.isOnline())
                {
                    res.arrival();
                }
            }
            return(res);
        }
Beispiel #2
0
        /**
         * <summary>
         *   Enumerates all functions of type CarbonDioxide 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>YCarbonDioxide.FindCarbonDioxide</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>();
            YCarbonDioxide it  = YCarbonDioxide.FirstCarbonDioxide();

            while (it != null)
            {
                res.Add(it.get_hardwareId());
                it = it.nextCarbonDioxide();
            }
            return(res.ToArray());
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            string errmsg = "";
            string target;

            YCarbonDioxide co2sensor;

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

            // Setup the API to use local USB devices
            if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS)
            {
                Console.WriteLine("RegisterHub error: " + errmsg);
                Environment.Exit(0);
            }

            if (target == "ANY")
            {
                co2sensor = YCarbonDioxide.FirstCarbonDioxide();

                if (co2sensor == null)
                {
                    Console.WriteLine("No module connected (check USB cable) ");
                    Environment.Exit(0);
                }
                Console.WriteLine("using " + co2sensor.get_module().get_serialNumber());
            }
            else
            {
                co2sensor = YCarbonDioxide.FindCarbonDioxide(target + ".carbonDioxide");
            }

            if (!co2sensor.isOnline())
            {
                Console.WriteLine("Module not connected");
                Console.WriteLine("check identification and USB cable");
                Environment.Exit(0);
            }
            while (co2sensor.isOnline())
            {
                Console.WriteLine("CO2: " + co2sensor.get_currentValue().ToString() + " ppm");
                Console.WriteLine("  (press Ctrl-C to exit)");

                YAPI.Sleep(1000, ref errmsg);
            }
            YAPI.FreeAPI();
        }
Beispiel #4
0
        public override async Task <int> Run()
        {
            try {
                await YAPI.RegisterHub(HubURL);

                YCarbonDioxide co2sensor;

                if (Target.ToLower() == "any")
                {
                    co2sensor = YCarbonDioxide.FirstCarbonDioxide();

                    if (co2sensor == null)
                    {
                        WriteLine("No module connected (check USB cable) ");
                        return(-1);
                    }
                    YModule ymod = await co2sensor.get_module();

                    WriteLine("using " + await ymod.get_serialNumber());
                }
                else
                {
                    co2sensor = YCarbonDioxide.FindCarbonDioxide(Target + ".carbonDioxide");
                }

                while (await co2sensor.isOnline())
                {
                    WriteLine("CO2: " + await co2sensor.get_currentValue() + " ppm");
                    await YAPI.Sleep(1000);
                }

                WriteLine("Module not connected (check identification and USB cable)");
            } catch (YAPI_Exception ex) {
                WriteLine("error: " + ex.Message);
            }

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