.. _manual_set_on_tp_log: set_on_tp_log (Manual Mode) ------------------------------------------ This section explains how to use :ref:`set_on_tp_log ` during **Manual (Teach)** operations. This function registers a **callback function** that receives log messages from the Teach Pendant (TP). It is mainly used to display or store TP console messages, warnings, and information strings that occur while teaching or executing DRL programs in manual mode. **Typical usage** - Mirror TP logs in the host PC console for monitoring and debugging. - Record log messages to a file for teaching session documentation. - Detect specific log patterns (e.g., “Warning”, “Error”) to trigger responses or visual alerts. - Correlate log messages with progress, popup, or LED events for deeper diagnostics. .. Note:: - Each callback receives one text line (up to 256 bytes) from the TP. - The callback runs asynchronously, so ensure lightweight operations within it. - Use file logging or filtering logic for long teaching sessions. **Example: Log TP messages and highlight warnings** .. code-block:: cpp #include "DRFLEx.h" #include #include #include #include #include using namespace std; using namespace DRAFramework; CDRFLEx drfl; // Utility to get timestamp string GetTimestamp() { time_t now = time(0); tm* ltm = localtime(&now); char buf[64]; sprintf(buf, "%04d-%02d-%02d %02d:%02d:%02d", 1900 + ltm->tm_year, 1 + ltm->tm_mon, ltm->tm_mday, ltm->tm_hour, ltm->tm_min, ltm->tm_sec); return string(buf); } // TP log callback void OnTpLog(const char* strLog) { cout << "[" << GetTimestamp() << "] " << strLog << endl; // Write log to file ofstream logFile("tp_manual_log.txt", ios::app); if (logFile.is_open()) { logFile << "[" << GetTimestamp() << "] " << strLog << endl; logFile.close(); } // Change LED color for warnings if (strstr(strLog, "Warning") != nullptr) drfl.set_state_led_color(255, 200, 0); // Yellow else if (strstr(strLog, "Error") != nullptr) drfl.set_state_led_color(255, 0, 0); // Red } int main() { drfl.open_connection("192.168.137.100"); drfl.set_on_tp_log(OnTpLog); cout << "[Teach] Waiting for TP log messages...\n"; while (true) this_thread::sleep_for(chrono::seconds(1)); return 0; } When registered, this callback function executes automatically whenever a **log message** is generated by the Teach Pendant (TP). It allows the user to **mirror TP log outputs, detect anomalies, or store activity history** for improved transparency and debugging during manual operations. **Tips** - Use to capture TP logs for debugging or post-teaching analysis. - Combine with :ref:`set_on_tp_popup ` for event-linked log tracking. - Highlight warnings or errors using LED color changes for quick operator awareness.