TOnMonitoringModbusCB

This callback function is used to check the Modbus I/O state data registered in the robot controller.

See Rules for callback functions.

Defined in: DRFLEx.h

// typedef (DRFL.h)
typedef void (*TOnMonitoringModbusCB)(const LPMONITORING_MODBUS);

// registration API (internal + wrapper)
DRFL_API void _set_on_monitoring_modbus(LPROBOTCONTROL pCtrl, TOnMonitoringModbusCB pCallbackFunc);
void set_on_monitoring_modbus(TOnMonitoringModbusCB pCallbackFunc)
{
    _set_on_monitoring_modbus(_rbtCtrl, pCallbackFunc);
};

Parameter

Parameter Name

Data Type

Default Value

Description

pModbus

MONITORING_MODBUS

Pointer to structure containing Modbus register symbols and values.

Return
None

Example

#include "DRFLEx.h"
#include <iostream>
#include <thread>
#include <chrono>
using namespace DRAFramework;
using namespace std;

// Callback: invoked when Modbus monitoring data updates
void OnMonitoringModbusCB(const LPMONITORING_MODBUS pModbus)
{
    if (!pModbus) return;

    cout << "[MODBUS] register count = " << pModbus->_iRegCount << endl;

    // Each entry contains a symbol (name) and its current value
    for (int i = 0; i < pModbus->_iRegCount; ++i)
    {
        // Example fields based on structure naming
        //   _tRegister[i]._szSymbol  → register name
        //   _tRegister[i]._iValue    → register value
        cout << "  " << pModbus->_tRegister[i]._szSymbol
             << " : " << pModbus->_tRegister[i]._iValue << endl;
    }
}

int main()
{
    CDRFLEx drfl;

    // Connect to the controller
    if (!drfl.open_connection("192.168.137.100")) {
        cout << "Failed to connect to controller." << endl;
        return -1;
    }

    // Register Modbus monitoring callback
    drfl.set_on_monitoring_modbus(OnMonitoringModbusCB);

    // Keep process alive to receive Modbus updates
    while (true)
        std::this_thread::sleep_for(std::chrono::seconds(1));

    drfl.close_connection();
    return 0;
}

Notes

  • Use this callback to build Modbus dashboards, alarm rules, or data logging pipelines.

  • For I/O state (GPIO) monitoring, see TOnMonitoringCtrlIOCB and its EX variants.

  • Each callback receives the most recent data. If the callback takes longer than the data period (100 ms before DRCF 3.5, 20 ms from DRCF 3.5), intermediate samples are not delivered. Do not rely on receiving every sample (for example for integration or differentiation).