FieldTalk Modbus Slave C++ Library
Library version 2.9.1
|
This class realises a Modbus server using MODBUS over UDP protocol variant. More...
Public Member Functions | |
MbusUdpSlaveProtocol () | |
Instantiates a MODBUS/UDP protocol server object. More... | |
int | startupServer () |
Puts the Modbus server into operation. More... | |
int | startupServer (const char *const hostName) |
Puts the Modbus server into operation. More... | |
void | shutdownServer () |
Shuts down the Modbus server. More... | |
int | serverLoop () |
Modbus slave server loop. More... | |
int | addDataTable (int slaveAddr, MbusDataTableInterface *dataTablePtr) |
Associates a protocol object with a Data Provider and a Modbus slave ID. More... | |
int | getConnectionStatus () |
Checks if a Modbus master is polling periodically. More... | |
Static Public Member Functions | |
static const TCHAR * | getPackageVersion () |
Returns the library version number. More... | |
Protocol Configuration | |
int | setTimeout (long timeOut) |
Configures master activity time-out supervision. More... | |
long | getTimeout () |
Returns the currently set master activity time-out value. More... | |
void | disableExceptionReplies () |
Supress exception replies to be sent. More... | |
void | enableExceptionReplies () |
Enables exception replies after they have been turned off. More... | |
Transmission Statistic Functions | |
unsigned long | getTotalCounter () |
Returns how often a message transfer has been executed. More... | |
void | resetTotalCounter () |
Resets total message transfer counter. | |
unsigned long | getSuccessCounter () |
Returns how often a message transfer was successful. More... | |
void | resetSuccessCounter () |
Resets successful message transfer counter. | |
TCP/IP Server Management Functions | |
int | isStarted () |
Returns whether server has been started up. More... | |
int | setPort (unsigned short portNo) |
Sets the TCP port number to be used by the protocol. More... | |
void | installIpAddrValidationCallBack (int(*f)(const char *masterIpAddrSz)) |
This function installs a callback handler for validating a master's IP address. More... | |
void | installMasterPollNotifyCallBack (void(*f)(const char *masterIpAddrSz)) |
This function installs a callback handler to be called everytime a master polls this slave. More... | |
unsigned short | getPort () |
Returns the TCP port number used by the protocol. More... | |
This class realises a Modbus server using MODBUS over UDP protocol variant.
It provides functions to start-up and to execute the server engine. This server engine can handle multiple master connections and is implemented as a single threaded UDP server. Upon receipt of a valid master query the server engine calls Data Provider methods to exchange data with the user application. For a more detailed description which Modbus data and control functions have been implemented in the server engine seesection Server Functions common to all Modbus Protocol Flavours.
Instantiates a MODBUS/UDP protocol server object.
The association with a Data Provider is done after construction using the addDataTable method.
References MasterInfo::protocol, and MasterInfo::UDP.
|
inlinevirtual |
Puts the Modbus server into operation.
The server accepts connections on any interface.
This function opens a TCP/IP socket, binds the configured TCP port to the Modbus/TCP protocol and initialises the server engine.
Reimplemented from MbusIpServerBase.
References MbusIpServerBase::startupServer().
|
virtual |
Puts the Modbus server into operation.
The server accepts communication only on the interfaces which match the supplied hostname or IP address. This method allows to run different servers on multiple interfaces (so called multihomed servers).
This function opens a UDP listening socket, binds the configured TCP port to the Modbus/UDP protocol and initialises the server engine.
hostName | String with IP address for a specific host interface or NULL if connections are accepted on any interface. Multihomeing does not work for aliased IP addresses. |
Implements MbusIpServerBase.
References FTALK_OPEN_ERR, FTALK_PORT_ALREADY_BOUND, FTALK_PORT_NO_ACCESS, FTALK_PORT_NOT_AVAIL, FTALK_SUCCESS, FTALK_TCPIP_CONNECT_ERR, and shutdownServer().
|
virtual |
Shuts down the Modbus server.
This function closes the UDP listeners and releases any system resources associated with the connections.
Reimplemented from MbusIpServerBase.
References MbusIpServerBase::shutdownServer().
|
virtual |
Modbus slave server loop.
This server loop must be called continuously. It must not be blocked. The server has to be started before calling the serverLoop() method.
In most cases the server loop is executed in an infinite loop in its own thread:
Implements MbusIpServerBase.
References FTALK_IO_ERROR, FTALK_SUCCESS, and MasterInfo::transactionId.
|
virtualinherited |
Returns whether server has been started up.
true | = started |
false | = shutdown |
Implements MbusSlaveServer.
|
inherited |
Sets the TCP port number to be used by the protocol.
portNo | Port number the server shall listen on |
FTALK_SUCCESS | Success |
FTALK_ILLEGAL_STATE_ERROR | Server already running |
References FTALK_ILLEGAL_STATE_ERROR, FTALK_SUCCESS, and MbusIpServerBase::isStarted().
|
inherited |
This function installs a callback handler for validating a master's IP address.
Pass a pointer to a function with checks a master's IP address and either accepts or rejects a master's connection.
f | Callback function pointer |
|
inherited |
This function installs a callback handler to be called everytime a master polls this slave.
This routine can be used to implement custom time-out mechanisms.
f | Callback function pointer |
|
inlineinherited |
Returns the TCP port number used by the protocol.
|
inherited |
Associates a protocol object with a Data Provider and a Modbus slave ID.
slaveAddr | Modbus slave address for server to listen on (-1 - 255). 0 is regarded as a valid value for a MODBUS/TCP server address. A value of -1 means the server disregards the slave address and listens to all slave addresses. 0 or -1 is only valid for MODBUS/TCP! |
dataTablePtr | Modbus data table pointer. Must point to a Data Provider object derived from the MbusDataTableInterface class. The Data Provider is the interface between your application data and the Modbus network. |
References FTALK_ILLEGAL_ARGUMENT_ERROR, and FTALK_SUCCESS.
|
inlineinherited |
Checks if a Modbus master is polling periodically.
true | = A master is polling at a frequency higher than the master transmit time-out value |
false | = No master is polling within the time-out period |
|
inherited |
Configures master activity time-out supervision.
The slave can monitor whether a master is actually polling or not. This function sets the activity time-out to the specified value. A value of 0 disables the time-out, which stops time-out notifications being sent to the Data Provider. Default value is 1000 ms.
timeOut | Timeout value in ms (Range: 0 - 100000), 0 disables time-out |
FTALK_SUCCESS | Success |
FTALK_ILLEGAL_ARGUMENT_ERROR | Argument out of range |
References FTALK_ILLEGAL_ARGUMENT_ERROR, and FTALK_SUCCESS.
|
inlineinherited |
Returns the currently set master activity time-out value.
|
inherited |
Supress exception replies to be sent.
With this option only positive replies are sent to the master. All failure replies are silently discarded. This option can be useful if redundant Modbus devices are used. In this scenario supressing the reply would trigger a swap-over of the redundant devices.
|
inherited |
Enables exception replies after they have been turned off.
Sending exception replies in case of slave failures is the normal mode of operation.
|
inlineinherited |
Returns how often a message transfer has been executed.
|
inlineinherited |
Returns how often a message transfer was successful.
|
staticinherited |
Returns the library version number.