For information on the latest version, please have a look at 1.33.5.
add_modbus_signal
This function registers a Modbus I/O signal in advance so that it can be used. A Modbus I/O signal registered with this function is stored in memory, so it must be set up again after a reboot. However, a signal registered in the T/P application can be reused, because it is added during the initialization process.
Definition
DRFLEx.h within class CDRFLEx, public section
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 definitions |
||
iRegIndex |
unsigned short |
Index of the Modbus register to access |
|
nRegValue |
unsigned short |
0 |
Output value when the type is |
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.