コード例 #1
0
ファイル: YFunction.cs プロジェクト: yoctopuce/yoctolib_uwp
        /// <summary>
        /// Invalidates the cache. Invalidates the cache of the function attributes. Forces the
        /// next call to get_xxx() or loadxxx() to use values that come from the device.
        ///
        ///
        /// </summary>
        public virtual async Task clearCache()
        {
            try {
                YDevice dev = await getYDevice();

                dev.imm_clearCache();
            } catch (YAPI_Exception) { }
            if (_cacheExpiration != 0)
            {
                _cacheExpiration = YAPI.GetTickCount();
            }
        }
コード例 #2
0
ファイル: YFunction.cs プロジェクト: yoctopuce/yoctolib_uwp
        // Load and parse the REST API for a function given by class name and
        // identifier, possibly applying changes
        // Device cache will be preloaded when loading function "module" and
        // leveraged for other modules
        internal virtual async Task <YJSONObject> _devRequest(string extra)
        {
            YDevice dev = await getYDevice();

            _hwId = _yapi._yHash.imm_resolveHwID(_className, _func);
            string[] split = _hwId.Split(new char[] { '\\', '.' });
            _funId  = split[1];
            _serial = split[0];
            YJSONObject loadval = null;

            if (extra.Equals(""))
            {
                // use a cached API string, without reloading unless module is
                // requested
                YJSONObject jsonval = await dev.requestAPI();

                loadval = jsonval.getYJSONObject(_funId);
            }
            else
            {
                dev.imm_clearCache();
            }
            if (loadval == null)
            {
                // request specified function only to minimize traffic
                if (extra.Equals(""))
                {
                    string httpreq = "GET /api/" + _funId + ".json";
                    string yreq    = await dev.requestHTTPSyncAsString(httpreq, null);

                    loadval = new YJSONObject(yreq);
                    loadval.parse();
                }
                else
                {
                    string httpreq = "GET /api/" + _funId + extra;
                    await dev.requestHTTPAsync(httpreq, null, null, null);

                    return(null);
                }
            }
            return(loadval);
        }