示例#1
0
        // link the instance to a real YoctoAPI object
        internal override void linkToHardware(string hwdName)
        {
            YCarbonDioxide hwd = YCarbonDioxide.FindCarbonDioxide(hwdName);

            // first redo base_init to update all _func pointers
            base_init(hwd, hwdName);
            // then setup Yocto-API pointers and callbacks
            init(hwd);
        }
示例#2
0
 // perform the 2nd stage setup that requires YoctoAPI object
 protected void init(YCarbonDioxide hwd)
 {
     if (hwd == null)
     {
         return;
     }
     base.init(hwd);
     InternalStuff.log("registering CarbonDioxide callback");
     _func.registerValueCallback(valueChangeCallback);
 }
示例#3
0
    /**
     * <summary>
     *   Retrieves a CO2 sensor 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 CO2 sensor is online at the time
     *   it is invoked. The returned object is nevertheless valid.
     *   Use the method <c>YCarbonDioxide.isOnline()</c> to test if the CO2 sensor is
     *   indeed online at a given time. In case of ambiguity when looking for
     *   a CO2 sensor 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>
     * </summary>
     * <param name="func">
     *   a string that uniquely characterizes the CO2 sensor
     * </param>
     * <returns>
     *   a <c>YCarbonDioxide</c> object allowing you to drive the CO2 sensor.
     * </returns>
     */
    public static YCarbonDioxide FindCarbonDioxide(string func)
    {
        YCarbonDioxide obj;

        obj = (YCarbonDioxide)YFunction._FindFromCache("CarbonDioxide", func);
        if (obj == null)
        {
            obj = new YCarbonDioxide(func);
            YFunction._AddToCache("CarbonDioxide", func, obj);
        }
        return(obj);
    }
    // --- (end of YCarbonDioxide implementation)

    // --- (CarbonDioxide functions)

    /**
     * <summary>
     *   Retrieves a CO2 sensor 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 CO2 sensor is online at the time
     *   it is invoked. The returned object is nevertheless valid.
     *   Use the method <c>YCarbonDioxide.isOnline()</c> to test if the CO2 sensor is
     *   indeed online at a given time. In case of ambiguity when looking for
     *   a CO2 sensor 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>
     * </summary>
     * <param name="func">
     *   a string that uniquely characterizes the CO2 sensor
     * </param>
     * <returns>
     *   a <c>YCarbonDioxide</c> object allowing you to drive the CO2 sensor.
     * </returns>
     */
    public static YCarbonDioxide FindCarbonDioxide(string func)
    {
        YCarbonDioxide res;

        if (_CarbonDioxideCache.ContainsKey(func))
        {
            return((YCarbonDioxide)_CarbonDioxideCache[func]);
        }
        res = new YCarbonDioxide(func);
        _CarbonDioxideCache.Add(func, res);
        return(res);
    }
示例#5
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);
        }
示例#6
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());
        }
示例#7
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();
        }
示例#8
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);
        }
 // --- (end of YCarbonDioxide implementation)
 // --- (CarbonDioxide functions)
 /**
    * <summary>
    *   Retrieves a CO2 sensor 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 CO2 sensor is online at the time
    *   it is invoked. The returned object is nevertheless valid.
    *   Use the method <c>YCarbonDioxide.isOnline()</c> to test if the CO2 sensor is
    *   indeed online at a given time. In case of ambiguity when looking for
    *   a CO2 sensor 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>
    * </summary>
    * <param name="func">
    *   a string that uniquely characterizes the CO2 sensor
    * </param>
    * <returns>
    *   a <c>YCarbonDioxide</c> object allowing you to drive the CO2 sensor.
    * </returns>
    */
 public static YCarbonDioxide FindCarbonDioxide(string func)
 {
     YCarbonDioxide res;
     if (_CarbonDioxideCache.ContainsKey(func))
       return (YCarbonDioxide)_CarbonDioxideCache[func];
     res = new YCarbonDioxide(func);
     _CarbonDioxideCache.Add(func, res);
     return res;
 }
示例#10
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 = (YCarbonDioxide)hwd;
     base.base_init(hwd, instantiationName);
 }
示例#11
0
        //--- (end of YCarbonDioxide definitions)

        //--- (YCarbonDioxide implementation)
        internal YCarbonDioxideProxy(YCarbonDioxide hwd, string instantiationName) : base(hwd, instantiationName)
        {
            InternalStuff.log("CarbonDioxide " + instantiationName + " instantiation");
            base_init(hwd, instantiationName);
        }
 /**
  * <summary>
  *   Retrieves a CO2 sensor 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 CO2 sensor is online at the time
  *   it is invoked. The returned object is nevertheless valid.
  *   Use the method <c>YCarbonDioxide.isOnline()</c> to test if the CO2 sensor is
  *   indeed online at a given time. In case of ambiguity when looking for
  *   a CO2 sensor 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>
  * </summary>
  * <param name="func">
  *   a string that uniquely characterizes the CO2 sensor
  * </param>
  * <returns>
  *   a <c>YCarbonDioxide</c> object allowing you to drive the CO2 sensor.
  * </returns>
  */
 public static YCarbonDioxide FindCarbonDioxide(string func)
 {
     YCarbonDioxide obj;
     obj = (YCarbonDioxide) YFunction._FindFromCache("CarbonDioxide", func);
     if (obj == null) {
         obj = new YCarbonDioxide(func);
         YFunction._AddToCache("CarbonDioxide", func, obj);
     }
     return obj;
 }