FieldTalk Modbus Slave C++ Library
Library version 2.9.1
|
This base class implements common functionality for both serial Modbus protocols. More...
Public Types | |
enum | { SER_DATABITS_7 = 7, SER_DATABITS_8 = 8 } |
enum | { SER_STOPBITS_1 = 1, SER_STOPBITS_2 = 2 } |
enum | { SER_PARITY_NONE = 0, SER_PARITY_EVEN = 2, SER_PARITY_ODD = 1 } |
Public Member Functions | |
virtual int | startupServer (const char *const portName, long baudRate, int dataBits, int stopBits, int parity) |
Puts the Modbus server into operation. More... | |
void | shutdownServer () |
Shuts down the Modbus server. More... | |
int | isStarted () |
Returns whether server has been started up. More... | |
virtual int | enableRs485Mode (int rtsDelay) |
Enables RS485 mode. More... | |
int | addDataTable (int slaveAddr, MbusDataTableInterface *dataTablePtr) |
Associates a protocol object with a Data Provider and a Modbus slave ID. More... | |
virtual int | serverLoop ()=0 |
Modbus slave server loop. 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. | |
This base class implements common functionality for both serial Modbus protocols.
These methods apply to RTU and ASCII protocol flavours via inheritance.
anonymous enum |
|
virtual |
Puts the Modbus server into operation.
This function opens the serial port. After the port has been opened queries from a Modbus master will be processed.
portName | Serial port identifier (e.g. "COM1", "/dev/ser1 or /dev/ttyS0") |
baudRate | The port baudRate in bps (typically 1200 - 115200, maximum value depends on UART hardware) |
dataBits | Must be SER_DATABITS_8 for RTU |
stopBits | SER_STOPBITS_1: 1 stop bit, SER_STOPBITS_2: 2 stop bits |
parity | SER_PARITY_NONE: no parity, SER_PARITY_ODD: odd parity, SER_PARITY_EVEN: even parity |
Reimplemented in MbusRtuSlaveProtocol.
References FTALK_ILLEGAL_ARGUMENT_ERROR, FTALK_ILLEGAL_SLAVE_ADDRESS, FTALK_ILLEGAL_STATE_ERROR, FTALK_NO_DATA_TABLE_ERROR, FTALK_OPEN_ERR, FTALK_PORT_ALREADY_OPEN, FTALK_PORT_NO_ACCESS, FTALK_SUCCESS, and isStarted().
|
virtual |
Shuts down the Modbus server.
This function also closes any associated communication resources like serial ports or sockets.
Implements MbusSlaveServer.
|
virtual |
Returns whether server has been started up.
true | = started |
false | = shutdown |
Implements MbusSlaveServer.
|
virtual |
Enables RS485 mode.
In RS485 mode the RTS signal can be used to enable and disable the transmitter of a RS232/RS485 converter. The RTS signal is asserted before sending data. It is cleared after the transmit buffer has been emptied and in addition the specified delay time has elapsed. The delay time is necessary because even the transmit buffer is already empty, the UART's FIFO will still contain unsent characters.
rtsDelay | Delay time in ms (Range: 0 - 100000) which applies after the transmit buffer is empty. 0 disables this mode. |
FTALK_SUCCESS | Success |
FTALK_ILLEGAL_ARGUMENT_ERROR | Argument out of range |
FTALK_ILLEGAL_STATE_ERROR | Protocol is already open |
References FTALK_ILLEGAL_ARGUMENT_ERROR, FTALK_ILLEGAL_STATE_ERROR, FTALK_SUCCESS, and isStarted().
|
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.
|
pure virtualinherited |
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:
Implemented in MbusTcpSlaveProtocol, MbusRtuSlaveProtocol, MbusRtuOverTcpSlaveProtocol, MbusUdpSlaveProtocol, MbusAsciiSlaveProtocol, and MbusIpServerBase.
|
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.