.. _set_on_disconnected: set_on_disconnected ------------------------------------------ This function registers a callback function that automatically checks whether the connection to the robot controller has been terminated for an external reason or by the user. Use it to run your own code automatically when this event occurs. **Definition** |br| ``DRFLEx.h`` within class `CDRFLEx`, public section .. code-block:: cpp void set_on_disconnected(TOnDisconnectedCB pCallbackFunc) { _set_on_disconnected(_rbtCtrl, pCallbackFunc); }; **Parameter** .. list-table:: :widths: 20 20 20 40 :header-rows: 1 * - **Parameter Name** - **Data Type** - **Default Value** - **Description** * - pCallbackFunc - :ref:`TOnDisconnectedCB ` - - - Refer to definition of callback function **Return** |br| None .. note:: When a connection ends (``close_connection``, loss of connection, or ``open_connection`` on an object that is already connected), every callback registered with a ``set_on_*`` function is unregistered, except those registered with ``set_on_disconnected``, ``set_on_monitoring_ctrl_io_ex`` (with DRCF_VERSION 3, the default), ``set_on_rt_monitoring_data`` and ``set_on_rt_log_alarm``, which stay registered. After each successful ``open_connection``, register the other callbacks again and call ``setup_monitoring_version`` again. ``open_connection`` on a connected object closes the existing connection first and prints "Already connected : ". See :ref:`Rules for callback functions `. **Example** .. code-block:: cpp void OnDisconnectedCB() { // Needs the reconnection of the robot controller and error handling } drfl.set_on_disconnected(OnDisconnectedCB); When registered, this callback function executes automatically when the **connection between the robot controller and the client is lost**. It allows the user to implement **reconnection logic or error recovery procedures** for stable operation in external environments.