.. _cb_tonprogramstoppedcb: TOnProgramStoppedCB ------------------------------------------ This callback function is used to check whether program execution in the robot controller has been completely terminated when the program stops due to **errors** or **user commands** during execution in **Auto mode**. See :ref:`Rules for callback functions `. **Defined in:** ``DRFLEx.h`` .. code-block:: cpp // typedef (DRFL.h) typedef void (*TOnProgramStoppedCB)(const PROGRAM_STOP_CAUSE); // registration API (internal + wrapper) DRFL_API void _set_on_program_stopped(LPROBOTCONTROL pCtrl, TOnProgramStoppedCB pCallbackFunc); void set_on_program_stopped(TOnProgramStoppedCB pCallbackFunc) { _set_on_program_stopped(_rbtCtrl, pCallbackFunc); }; **Parameter** .. list-table:: :header-rows: 1 :widths: 20 25 15 40 * - Parameter Name - Data Type - Default Value - Description * - eStopCause - :ref:`PROGRAM_STOP_CAUSE ` - - - Cause of the program termination (e.g., user stop, error, safety, etc.). **Return** |br| None **Example** .. code-block:: cpp #include "DRFLEx.h" #include #include #include using namespace DRAFramework; // Called automatically when a running DRL program stops or terminates void OnProgramStoppedCB(const PROGRAM_STOP_CAUSE eStopCause) { switch (eStopCause) { case PROGRAM_STOP_CAUSE_FORCE: std::printf("[PROGRAM STOP] Program was force-stopped.\n"); break; case PROGRAM_STOP_CAUSE_ERROR: std::printf("[PROGRAM STOP] Error occurred during execution.\n"); // Optionally check for error code or perform recovery logic break; case PROGRAM_STOP_CAUSE_NORMAL: std::printf("[PROGRAM STOP] Program completed normally.\n"); break; default: std::printf("[PROGRAM STOP] Unknown stop cause: %d\n", eStopCause); break; } } int main() { CDRFLEx drfl; // Connect to the robot controller if (!drfl.open_connection("192.168.137.100")) { std::printf("Failed to connect to controller.\n"); return -1; } // Register callback for program stop event drfl.set_on_program_stopped(OnProgramStoppedCB); // Acquire control authority and turn the servo on drfl.manage_access_control(MANAGE_ACCESS_CONTROL_FORCE_REQUEST); std::this_thread::sleep_for(std::chrono::seconds(1)); drfl.set_robot_control(CONTROL_SERVO_ON); for (int i = 0; i < 10 && drfl.get_robot_state() != STATE_STANDBY; ++i) std::this_thread::sleep_for(std::chrono::seconds(1)); // drl_start requires Auto mode if (!drfl.set_robot_mode(ROBOT_MODE_AUTONOMOUS)) return -1; // Example: start DRL program and wait for callback if (!drfl.drl_start(ROBOT_SYSTEM_VIRTUAL, "movej(posj(0,0,90,0,90,0), vel=30, acc=30)\r\n")) { std::printf("drl_start was refused.\n"); return -1; } while (true) { std::this_thread::sleep_for(std::chrono::seconds(1)); } drfl.close_connection(); return 0; } **Notes** - The callback is invoked when any DRL program running in Auto mode terminates (normal or abnormal). - Use this to perform **cleanup**, **logging**, or **restart preparation** when the program ends.