Exemplo n.º 1
0
        // link the instance to a real YoctoAPI object
        internal override void linkToHardware(string hwdName)
        {
            YRangeFinder hwd = YRangeFinder.FindRangeFinder(hwdName);

            // first redo base_init to update all _func pointers
            base_init(hwd, hwdName);
            // then setup Yocto-API pointers and callbacks
            init(hwd);
        }
Exemplo n.º 2
0
 // perform the 2nd stage setup that requires YoctoAPI object
 protected void init(YRangeFinder hwd)
 {
     if (hwd == null)
     {
         return;
     }
     base.init(hwd);
     InternalStuff.log("registering RangeFinder callback");
     _func.registerValueCallback(valueChangeCallback);
 }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            string       errmsg = "";
            string       target;
            YRangeFinder rf;
            YLightSensor ir;
            YTemperature tmp;

            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")
            {
                rf = YRangeFinder.FirstRangeFinder();
                if (rf == null)
                {
                    Console.WriteLine("No module connected (check USB cable) ");
                    Environment.Exit(0);
                }
                target = rf.get_module().get_serialNumber();
            }
            else
            {
                rf = YRangeFinder.FindRangeFinder(target + ".rangefinder1");
            }

            if (!rf.isOnline())
            {
                Console.WriteLine("Module not connected");
                Console.WriteLine("check identification and USB cable");
                Environment.Exit(0);
            }
            ir  = YLightSensor.FindLightSensor(target + ".lightSensor1");
            tmp = YTemperature.FindTemperature(target + ".temperature1");

            while (rf.isOnline())
            {
                Console.WriteLine("Distance    : " + rf.get_currentValue().ToString());
                Console.WriteLine("Ambiant IR  : " + ir.get_currentValue().ToString());
                Console.WriteLine("Temperature : " + tmp.get_currentValue().ToString());
                Console.WriteLine("  (press Ctrl-C to exit)");
                YAPI.Sleep(1000, ref errmsg);
            }
            YAPI.FreeAPI();
        }
Exemplo n.º 4
0
        public static YRangeFinderProxy FindRangeFinder(string name)
        {
            // cases to handle:
            // name =""  no matching unknwn
            // name =""  unknown exists
            // name != "" no  matching unknown
            // name !="" unknown exists
            YRangeFinder      func = null;
            YRangeFinderProxy res  = (YRangeFinderProxy)YFunctionProxy.FindSimilarUnknownFunction("YRangeFinderProxy");

            if (name == "")
            {
                if (res != null)
                {
                    return(res);
                }
                res = (YRangeFinderProxy)YFunctionProxy.FindSimilarKnownFunction("YRangeFinderProxy");
                if (res != null)
                {
                    return(res);
                }
                func = YRangeFinder.FirstRangeFinder();
                if (func != null)
                {
                    name = func.get_hardwareId();
                    if (func.get_userData() != null)
                    {
                        return((YRangeFinderProxy)func.get_userData());
                    }
                }
            }
            else
            {
                func = YRangeFinder.FindRangeFinder(name);
                if (func.get_userData() != null)
                {
                    return((YRangeFinderProxy)func.get_userData());
                }
            }
            if (res == null)
            {
                res = new YRangeFinderProxy(func, name);
            }
            if (func != null)
            {
                res.linkToHardware(name);
                if (func.isOnline())
                {
                    res.arrival();
                }
            }
            return(res);
        }
Exemplo n.º 5
0
        /**
         * <summary>
         *   Enumerates all functions of type RangeFinder 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>YRangeFinder.FindRangeFinder</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>();
            YRangeFinder  it  = YRangeFinder.FirstRangeFinder();

            while (it != null)
            {
                res.Add(it.get_hardwareId());
                it = it.nextRangeFinder();
            }
            return(res.ToArray());
        }
Exemplo n.º 6
0
    /**
     * <summary>
     *   Retrieves a range finder 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 range finder is online at the time
     *   it is invoked. The returned object is nevertheless valid.
     *   Use the method <c>YRangeFinder.isOnline()</c> to test if the range finder is
     *   indeed online at a given time. In case of ambiguity when looking for
     *   a range finder 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>
     * <para>
     *   If a call to this object's is_online() method returns FALSE although
     *   you are certain that the matching device is plugged, make sure that you did
     *   call registerHub() at application initialization time.
     * </para>
     * <para>
     * </para>
     * </summary>
     * <param name="func">
     *   a string that uniquely characterizes the range finder, for instance
     *   <c>YRNGFND1.rangeFinder1</c>.
     * </param>
     * <returns>
     *   a <c>YRangeFinder</c> object allowing you to drive the range finder.
     * </returns>
     */
    public static YRangeFinder FindRangeFinder(string func)
    {
        YRangeFinder obj;

        lock (YAPI.globalLock) {
            obj = (YRangeFinder)YFunction._FindFromCache("RangeFinder", func);
            if (obj == null)
            {
                obj = new YRangeFinder(func);
                YFunction._AddToCache("RangeFinder", func, obj);
            }
        }
        return(obj);
    }
Exemplo n.º 7
0
        public override async Task <int> Run()
        {
            try {
                await YAPI.RegisterHub(HubURL);

                YRangeFinder rf;
                YLightSensor ir;
                YTemperature tmp;

                if (Target.ToLower() == "any")
                {
                    rf = YRangeFinder.FirstRangeFinder();
                    if (rf == null)
                    {
                        WriteLine("No module connected (check USB cable) ");
                        return(-1);
                    }

                    Target = await(await rf.get_module()).get_serialNumber();
                }
                else
                {
                    rf = YRangeFinder.FindRangeFinder(Target + ".rangefinder1");
                }

                ir  = YLightSensor.FindLightSensor(Target + ".lightSensor1");
                tmp = YTemperature.FindTemperature(Target + ".temperature1");

                while (await rf.isOnline())
                {
                    WriteLine("Distance    : " + await rf.get_currentValue());
                    WriteLine("Ambiant IR  : " + await ir.get_currentValue());
                    WriteLine("Temperature : " + await tmp.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);
        }
Exemplo n.º 8
0
 // 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 = (YRangeFinder)hwd;
     base.base_init(hwd, instantiationName);
 }
Exemplo n.º 9
0
        //--- (end of YRangeFinder definitions)

        //--- (YRangeFinder implementation)
        internal YRangeFinderProxy(YRangeFinder hwd, string instantiationName) : base(hwd, instantiationName)
        {
            InternalStuff.log("RangeFinder " + instantiationName + " instantiation");
            base_init(hwd, instantiationName);
        }