You're reading the documentation for an older, but still supported version (GL013300).
For information on the latest version, please have a look at GL013301.

add_modbus_signal

This is a function for using the Modbus I/O signal by registering it in advance. The modbus I/O signal registered using this function should be reset after rebooting, as it is stored in the memory. However, if it is registered in the T/P application, it can be reused, as it is added in the initialization process.

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

bool add_modbus_signal(string strSymbol,
                       string strIpAddress,
                       unsigned short nPort,
                       MODBUS_REGISTER_TYPE eRegType,
                       unsigned short iRegIndex,
                       unsigned short nRegValue = 0,
                       unsigned char nSlaiveId = 255)
{
    return _add_modbus_signal(_rbtCtrl,
                              strSymbol.c_str(),
                              strIpAddress.c_str(),
                              nPort,
                              eRegType,
                              iRegIndex,
                              nRegValue,
                              nSlaiveId);
};

Parameter

Parameter Name

Data Type

Default Value

Description

strSymbol

string

Modbus signal name

strIpAddress

string

Modbus module IP address

nPort

unsigned short

Modbus module port number

eRegType

MODBUS_REGISTER_TYPE

Modbus register type definitions

iRegIndex

unsigned short

Index of the Modbus register to access

nRegValue

unsigned short

0

Output value when the type is MODBUS_REGISTER_TYPE_COILS or MODBUS_REGISTER_TYPE_HOLDING_REGISTER (ignored for other types)

nSlaiveId

unsigned char

255

Slave ID of the target Modbus device (default: broadcast)

Return

Value

Description

0

Error — failed to register Modbus signal

1

Success — Modbus signal successfully added

Example

// Example of connecting Modbus I/O and allocating context point
// Modbus IP: 192.168.127.254
// Add 2 points: "di1", "di2"

drfl.add_modbus_signal("di1", "192.168.127.254", 502,
                       MODBUS_REGISTER_TYPE_DISCRETE_INPUTS, 0, 0);
drfl.add_modbus_signal("di2", "192.168.127.254", 502,
                       MODBUS_REGISTER_TYPE_DISCRETE_INPUTS, 0, 0);

This example registers two Modbus digital input points named di1 and di2 on the external Modbus module connected via TCP at IP 192.168.127.254, port 502. Once registered, the signals can be monitored or controlled in subsequent API calls.