.. _cb_tonmonitoringsafetystatecb: TOnMonitoringSafetyStateCB ------------------------------------------ This callback is called each time the controller reports the robot's **safety state**. It receives the state as a :ref:`SAFETY_STATE ` value. Compare it with the previous value to detect a change. See :ref:`Rules for callback functions `. **Defined in:** ``DRFLEx.h`` .. code-block:: cpp // typedef (DRFLEx.h) typedef void (*TOnMonitoringSafetyStateCB)(const SAFETY_STATE); // registration API (internal + wrapper) DRFL_API void _set_on_monitoring_safety_state(LPROBOTCONTROL pCtrl, TOnMonitoringSafetyStateCB pCallbackFunc); // user-callable API void set_on_monitoring_safety_state(TOnMonitoringSafetyStateCB pCallbackFunc) { _set_on_monitoring_safety_state(_rbtCtrl, pCallbackFunc); }; **Parameter** .. list-table:: :header-rows: 1 :widths: 20 25 15 40 * - Parameter Name - Data Type - Default Value - Description * - eSafetyState - :ref:`SAFETY_STATE ` - - - Indicates the current safety state reported by the robot controller. **Return** |br| None **Example** .. code-block:: cpp #include "DRFLEx.h" #include #include #include using namespace DRAFramework; using namespace std; // Callback triggered when the robot's safety state changes void OnMonitoringSafetyStateCB(SAFETY_STATE eState) { cout << "[SAFETY STATE UPDATED]" << endl; switch (eState) { case SAFETY_STATE_SW_RUN: cout << "Safety State: standalone workspace RUN." << endl; break; case SAFETY_STATE_CW_RUN: cout << "Safety State: collaborative workspace RUN." << endl; break; case SAFETY_STATE_VD_STO: cout << "Safety State: violation detected, STO." << endl; break; case SAFETY_STATE_RV_MOVE: cout << "Safety State: recovery MOVE." << endl; break; default: cout << "Safety State: UNKNOWN (" << (int)eState << ")" << endl; break; } } int main() { CDRFLEx drfl; // Connect to robot controller if (!drfl.open_connection("192.168.137.100")) { cout << "Failed to connect to controller." << endl; return -1; } // Register callback for monitoring safety state drfl.set_on_monitoring_safety_state(OnMonitoringSafetyStateCB); // Keep monitoring continuously while (true) std::this_thread::sleep_for(std::chrono::seconds(1)); drfl.close_connection(); return 0; } **Notes** - The callback is triggered whenever the **safety state** changes due to: |br| - Emergency stop (E-Stop) |br| - Protective stop |br| - Safety door/fence signal |br| - Safety mode transition (e.g., Manual ↔ Auto) |br| - The :ref:`SAFETY_STATE ` enumeration defines the possible safety conditions. - Recommended usage: |br| - Display real-time safety status |br| - Log or alert operators upon stop or hazard events |br| - Trigger robot recovery or safe-shutdown sequences |br|