コード例 #1
0
        static void Main(string[] args)
        {
            string       errmsg = "";
            string       target;
            YLightSensor ir, al;
            YProximity   p;

            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")
            {
                p = YProximity.FirstProximity();
                if (p == null)
                {
                    Console.WriteLine("No module connected (check USB cable) ");
                    Environment.Exit(0);
                }
                target = p.get_module().get_serialNumber();
            }
            else
            {
                p = YProximity.FindProximity(target + ".proximity1");
            }

            if (!p.isOnline())
            {
                Console.WriteLine("Module not connected");
                Console.WriteLine("check identification and USB cable");
                Environment.Exit(0);
            }
            al = YLightSensor.FindLightSensor(target + ".lightSensor1");
            ir = YLightSensor.FindLightSensor(target + ".lightSensor2");

            while (p.isOnline())
            {
                Console.Write(" Proximity: " + p.get_currentValue().ToString());
                Console.Write(" Ambiant: " + al.get_currentValue().ToString());
                Console.Write(" IR: " + ir.get_currentValue().ToString());

                Console.WriteLine("  (press Ctrl-C to exit)");
                YAPI.Sleep(1000, ref errmsg);
            }
            YAPI.FreeAPI();
        }
コード例 #2
0
        public static YProximityProxy FindProximity(string name)
        {
            // cases to handle:
            // name =""  no matching unknwn
            // name =""  unknown exists
            // name != "" no  matching unknown
            // name !="" unknown exists
            YProximity      func = null;
            YProximityProxy res  = (YProximityProxy)YFunctionProxy.FindSimilarUnknownFunction("YProximityProxy");

            if (name == "")
            {
                if (res != null)
                {
                    return(res);
                }
                res = (YProximityProxy)YFunctionProxy.FindSimilarKnownFunction("YProximityProxy");
                if (res != null)
                {
                    return(res);
                }
                func = YProximity.FirstProximity();
                if (func != null)
                {
                    name = func.get_hardwareId();
                    if (func.get_userData() != null)
                    {
                        return((YProximityProxy)func.get_userData());
                    }
                }
            }
            else
            {
                func = YProximity.FindProximity(name);
                if (func.get_userData() != null)
                {
                    return((YProximityProxy)func.get_userData());
                }
            }
            if (res == null)
            {
                res = new YProximityProxy(func, name);
            }
            if (func != null)
            {
                res.linkToHardware(name);
                if (func.isOnline())
                {
                    res.arrival();
                }
            }
            return(res);
        }
コード例 #3
0
        /**
         * <summary>
         *   Enumerates all functions of type Proximity 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>YProximity.FindProximity</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>();
            YProximity    it  = YProximity.FirstProximity();

            while (it != null)
            {
                res.Add(it.get_hardwareId());
                it = it.nextProximity();
            }
            return(res.ToArray());
        }
コード例 #4
0
ファイル: Demo.cs プロジェクト: yoctopuce/yoctolib_uwp
        public override async Task <int> Run()
        {
            try {
                await YAPI.RegisterHub(HubURL);

                YLightSensor ir, al;
                YProximity   p;

                if (Target.ToLower() == "any")
                {
                    p = YProximity.FirstProximity();
                    if (p == null)
                    {
                        WriteLine("No module connected (check USB cable) ");
                        return(-1);
                    }

                    Target = await(await p.get_module()).get_serialNumber();
                }
                else
                {
                    p = YProximity.FindProximity(Target + ".proximity1");
                }

                al = YLightSensor.FindLightSensor(Target + ".lightSensor1");
                ir = YLightSensor.FindLightSensor(Target + ".lightSensor2");

                while (await p.isOnline())
                {
                    Write("Proximity: " + await p.get_currentValue());
                    Write("\tAmbiant: " + await al.get_currentValue());
                    WriteLine("\tIR: " + await ir.get_currentValue());
                    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);
        }