set_on_tp_log

This function is used to register a callback function to check log messages when the tp_log command is used in DRL. It is useful when functions that should be executed automatically are made.

Definition
DRFLEx.h within class CDRFLEx, public section (line 641)

void set_on_tp_log(TOnTpLogCB pCallbackFunc) {
    _set_on_tp_log(_rbtCtrl, pCallbackFunc);
};

Parameter

Parameter Name

Data Type

Default Value

Description

pCallbackFunc

TOnTpLogCB

Refer to definition of callback function

Return
None

Example

// Simple utility to add timestamp
string GetTimestamp()
{
    time_t now = time(0);
    tm* ltm = localtime(&now);
    char buffer[64];
    sprintf(buffer, "%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(buffer);
}

// Callback for TP log messages
void OnTpLog(const char* strLog)
{
    printf("[%s] [TP LOG] %s\n", GetTimestamp(), strLog);

    // Example: also save to local log file
    ofstream logFile("tp_log_history.txt", ios::app);
    if (logFile.is_open())
    {
        logFile << "[" << GetTimestamp() << "] " << strLog << endl;
        logFile.close();
    }

    // Example: detect specific event keyword
    if (strstr(strLog, "Warning"))
        printf("[Host] Warning detected from TP log.\n");
}

// Register TP log callback
drfl.set_on_tp_log(OnTpLog);

printf("Waiting for TP log events...\n");
while (true)
{
    this_thread::sleep_for(chrono::seconds(1));
}

When registered, this callback function executes automatically when a log message is triggered on the Teach Pendant (TP) through DRL. It enables real-time monitoring and logging of TP events, allowing users to record, filter, or react to messages as needed.