/** * <summary> * Pauses the execution flow for a specified duration. * <para> * This function implements a passive waiting loop, meaning that it does not * consume CPU cycles significantly. The processor is left available for * other threads and processes. During the pause, the library nevertheless * reads from time to time information from the Yoctopuce modules by * calling <c>yHandleEvents()</c>, in order to stay up-to-date. * </para> * <para> * This function may signal an error in case there is a communication problem * while contacting a module. * </para> * </summary> * <param name="ms_duration"> * an integer corresponding to the duration of the pause, * in milliseconds. * </param> * <param name="errmsg"> * a string passed by reference to receive any error message. * </param> * <returns> * <c>YAPI.SUCCESS</c> when the call succeeds. * </returns> * <para> * On failure, throws an exception or returns a negative error code. * </para> */ public static async Task <int> Sleep(ulong ms_duration, YRefParam errmsg) { YAPIContext yctx = imm_GetYCtx(); try { return(await imm_GetYCtx().Sleep(ms_duration)); } catch (YAPI_Exception ex) { errmsg.Value = ex.Message; return(ex.errorType); } }
/** * <summary> * Force a hub discovery, if a callback as been registered with <c>yRegisterHubDiscoveryCallback</c> it * will be called for each net work hub that will respond to the discovery. * <para> * </para> * </summary> * <param name="errmsg"> * a string passed by reference to receive any error message. * </param> * <returns> * <c>YAPI.SUCCESS</c> when the call succeeds. * On failure, throws an exception or returns a negative error code. * </returns> */ public static async Task <int> TriggerHubDiscovery(YRefParam errmsg) { YAPIContext yctx = imm_GetYCtx(); try { return(await imm_GetYCtx().TriggerHubDiscovery()); } catch (YAPI_Exception ex) { errmsg.Value = ex.Message; return(ex.errorType); } }
/** * <summary> * Maintains the device-to-library communication channel. * <para> * If your program includes significant loops, you may want to include * a call to this function to make sure that the library takes care of * the information pushed by the modules on the communication channels. * This is not strictly necessary, but it may improve the reactivity * of the library for the following commands. * </para> * <para> * This function may signal an error in case there is a communication problem * while contacting a module. * </para> * </summary> * <param name="errmsg"> * a string passed by reference to receive any error message. * </param> * <returns> * <c>YAPI.SUCCESS</c> when the call succeeds. * </returns> * <para> * On failure, throws an exception or returns a negative error code. * </para> */ public static async Task <int> HandleEvents(YRefParam errmsg) { YAPIContext yctx = imm_GetYCtx(); try { return(await imm_GetYCtx().HandleEvents()); } catch (YAPI_Exception ex) { errmsg.Value = ex.Message; return(ex.errorType); } }
/** * <summary> * Triggers a (re)detection of connected Yoctopuce modules. * <para> * The library searches the machines or USB ports previously registered using * <c>yRegisterHub()</c>, and invokes any user-defined callback function * in case a change in the list of connected devices is detected. * </para> * <para> * This function can be called as frequently as desired to refresh the device list * and to make the application aware of hot-plug events. * </para> * </summary> * <param name="errmsg"> * a string passed by reference to receive any error message. * </param> * <returns> * <c>YAPI.SUCCESS</c> when the call succeeds. * </returns> * <para> * On failure, throws an exception or returns a negative error code. * </para> */ public static async Task <int> UpdateDeviceList(YRefParam errmsg) { YAPIContext yctx = imm_GetYCtx(); try { return(await imm_GetYCtx().UpdateDeviceList()); } catch (YAPI_Exception ex) { errmsg.Value = ex.Message; return(ex.errorType); } }
/** * <summary> * Test if the hub is reachable. * <para> * This method do not register the hub, it only test if the * hub is usable. The url parameter follow the same convention as the <c>RegisterHub</c> * method. This method is useful to verify the authentication parameters for a hub. It * is possible to force this method to return after mstimeout milliseconds. * </para> * <para> * </para> * </summary> * <param name="url"> * a string containing either <c>"usb"</c>,<c>"callback"</c> or the * root URL of the hub to monitor * </param> * <param name="mstimeout"> * the number of millisecond available to test the connection. * </param> * <param name="errmsg"> * a string passed by reference to receive any error message. * </param> * <returns> * <c>YAPI.SUCCESS</c> when the call succeeds. * </returns> * <para> * On failure returns a negative error code. * </para> */ public static async Task <int> TestHub(string url, uint mstimeout, YRefParam errmsg) { YAPIContext yctx = imm_GetYCtx(); try { return(await imm_GetYCtx().TestHub(url, mstimeout)); } catch (YAPI_Exception ex) { errmsg.Value = ex.Message; return(ex.errorType); } }
/** * <summary> * Fault-tolerant alternative to <c>RegisterHub()</c>. * <para> * This function has the same * purpose and same arguments as <c>RegisterHub()</c>, but does not trigger * an error when the selected hub is not available at the time of the function call. * This makes it possible to register a network hub independently of the current * connectivity, and to try to contact it only when a device is actively needed. * </para> * <para> * </para> * </summary> * <param name="url"> * a string containing either <c>"usb"</c>,<c>"callback"</c> or the * root URL of the hub to monitor * </param> * <param name="errmsg"> * a string passed by reference to receive any error message. * </param> * <returns> * <c>YAPI.SUCCESS</c> when the call succeeds. * </returns> * <para> * On failure, throws an exception or returns a negative error code. * </para> */ public static async Task <int> PreregisterHub(string url, YRefParam errmsg) { YAPIContext yctx = imm_GetYCtx(); try { return(await imm_GetYCtx().PreregisterHub(url)); } catch (YAPI_Exception ex) { errmsg.Value = ex.Message; return(ex.errorType); } }
/** * <summary> * Initializes the Yoctopuce programming library explicitly. * <para> * It is not strictly needed to call <c>yInitAPI()</c>, as the library is * automatically initialized when calling <c>yRegisterHub()</c> for the * first time. * </para> * <para> * When <c>YAPI.DETECT_NONE</c> is used as detection <c>mode</c>, * you must explicitly use <c>yRegisterHub()</c> to point the API to the * VirtualHub on which your devices are connected before trying to access them. * </para> * </summary> * <param name="mode"> * an integer corresponding to the type of automatic * device detection to use. Possible values are * <c>YAPI.DETECT_NONE</c>, <c>YAPI.DETECT_USB</c>, <c>YAPI.DETECT_NET</c>, * and <c>YAPI.DETECT_ALL</c>. * </param> * <param name="errmsg"> * a string passed by reference to receive any error message. * </param> * <returns> * <c>YAPI.SUCCESS</c> when the call succeeds. * </returns> * <para> * On failure, throws an exception or returns a negative error code. * </para> */ public static async Task <int> InitAPI(int mode, YRefParam errmsg) { YAPIContext yctx = imm_GetYCtx(); try { return(await yctx.InitAPI(mode)); } catch (YAPI_Exception ex) { errmsg.Value = ex.Message; return(ex.errorType); } }