.. _set_on_rt_log_alarm: set_on_rt_log_alarm ------------------------------------------ This function registers a **callback** for the messages the controller sends about the **RT session**: an unsupported version, RT input not received within the set time, a missing heartbeat, and another RT client already connected. Motion warnings and errors during RT control, including rejected RT commands, are reported through :ref:`set_on_log_alarm `. Register both callbacks. **Definition** |br| ``DRFLEx.h`` within class `CDRFLEx`, public section .. code-block:: cpp void set_on_rt_log_alarm(TOnLogAlarmCB pCallbackFunc) { _set_on_rt_log_alarm(_rbtCtrlUDP, pCallbackFunc); }; **Parameter** .. list-table:: :widths: 25 25 50 :header-rows: 1 * - **Parameter Name** - **Data Type** - **Description** * - pCallbackFunc - :ref:`TOnLogAlarmCB ` - Function pointer to user-defined callback that handles |br| log or alarm messages sent from the robot controller. **Note** - The callback executes automatically when the controller sends an RT session message. - See :ref:`Rules for callback functions `. **Example** .. code-block:: cpp #include #include // Define callback for alarm and log monitoring void OnRTLogAlarm(LPLOG_ALARM pLogAlarm) { printf("[RT LOG/ALARM] group %d, index %d: %s\n", pLogAlarm->_iGroup, pLogAlarm->_iIndex, pLogAlarm->_szParam[0]); } drfl.connect_rt_control("192.168.137.100", 12347); // Register real-time log and alarm callback drfl.set_on_rt_log_alarm(OnRTLogAlarm); // Configure and start RT control string version = "v1.0"; float period = 0.001f; int losscount = 4; drfl.set_rt_control_input(version, period, losscount); drfl.set_rt_control_output(version, period, losscount); drfl.start_rt_control(); // Keep the RT session open for 60 s; the callback runs when a message arrives const auto tEnd = std::chrono::steady_clock::now() + std::chrono::seconds(60); while (std::chrono::steady_clock::now() < tEnd) { std::this_thread::sleep_for(std::chrono::milliseconds(100)); } drfl.disconnect_rt_control(); In this example, ``OnRTLogAlarm()`` prints each RT session message the controller sends. **Tips** - Useful for detecting RT input timeouts and session problems during live control. - Integrate with a GUI or network logger to visualize alarm states in real time. - When the controller ends the RT session, it reports an alarm to the :ref:`set_on_rt_log_alarm ` callback, and RT data stops. - Do not call ``get_rt_control_input_version_list``, ``get_rt_control_output_version_list``, ``get_rt_control_input_data_list``, ``get_rt_control_output_data_list`` or ``disconnect_rt_control`` from an RT callback; the call does not return. ``connect_rt_control`` called from an RT callback returns false and prints ``Already connected``.