FieldTalk Modbus® Slave Library
C++ Editions
FOCUS Software Engineering

Main Page | Modules | Class Hierarchy | Class List | Class Members | Related Pages

Server Functions common to all Protocol Flavours


Detailed Description

The FieldTalk Modbus Slave Protocol Library's server engine implements the most commonly used Modbus data functions as well as some control functions. The functions to perform PLC program download and other device specific functions are outside the scope of this library.

All Bit Access and 16 Bits Access Modbus Function Codes have been implemented. In addition the most frequently used Diagnostics Function Codes have been implemented.

The following table lists the functions supported by the slave:

Modbus Function CodeCurrent Terminology Classic Terminology

16-bit Access
3Read Multiple Registers Read Holding Registers
4Read Input Registers Read Input Registers
6Write Single Register Preset Single Register
16 (10 Hex)Write Multiple Registers Preset Multiple Registers
22 (16 Hex)Mask Write Register Mask Write Register
23 (17 Hex)Read/Write Registers Read/Write Registers

Bit access
1Read CoilsRead Coil Status
2Read Inputs Discretes Read Input Status
5Write CoilForce Single Coil
15 (0F Hex)Force Multiple Coils Force Multiple Coils

Diagnostics
7Read Exception Status Read Exception Status
8 sub code 00Diagnostics - Return Query Data Diagnostics - Return Query Data


Server Management Functions

int MbusSlaveServer::addDataTable (int slaveAddr, MbusDataTableInterface *dataTablePtr)
 Associates a protocol object with a Data Provider and a slave address.
virtual int MbusSlaveServer::serverLoop ()=0
 Modbus slave server loop.
virtual void MbusSlaveServer::shutdownServer ()
 Shuts down the Modbus Server.
virtual int MbusSlaveServer::isStarted ()=0
 Returns if server has been started up.
virtual int MbusSlaveServer::getConnectionStatus ()=0
 Associates a protocol object with a Data Provider and a slave address.

Protocol Configuration

long MbusSlaveServer::setTimeout (long timeOut)
 Configures master transmit time-out supervision.
long MbusSlaveServer::getTimeout ()
 Returns the master time-out supervision value.

Transmission Statistic Functions

unsigned long MbusSlaveServer::getTotalCounter ()
 Returns how often a message transfer has been executed.
void MbusSlaveServer::resetTotalCounter ()
 Resets total message transfer counter.
unsigned long MbusSlaveServer::getSuccessCounter ()
 Returns how often a message transfer was successful.
void MbusSlaveServer::resetSuccessCounter ()
 Resets successful message transfer counter.

Utility Functions

static char * MbusSlaveServer::getPackageVersion ()
 Returns the package version number.

Function Documentation

int addDataTable int  slaveAddr,
MbusDataTableInterface dataTablePtr
[inherited]
 

Associates a protocol object with a Data Provider and a slave address.

Parameters:
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.
Returns:
FTALK_SUCCESS on success or error code. See Protocol Errors and Exceptions for a list of error codes.

long setTimeout long  timeOut  )  [inherited]
 

Configures master transmit time-out supervision.

The slave can monitor whether a master is actually transmitting characters or not. This function sets the transmit 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.

Remarks:
The time-out value is indicative only and not guaranteed to be maintained. How precise it is followed depends on the operating system used, it's scheduling priority and it's system timer resolution.
Note:
The time-out does not check if a master is sending valid frames.
Parameters:
timeOut Timeout value in ms (Range: 0 - 100000), 0 disables time-out
Return values:
FTALK_SUCCESS Success
FTALK_ILLEGAL_ARGUMENT_ERROR Argument out of range

unsigned long getTotalCounter  )  [inherited]
 

Returns how often a message transfer has been executed.

Returns:
Counter value

char * getPackageVersion  )  [static, inherited]
 

Returns the package version number.

Returns:
Package version string

long getTimeout  )  [inherited]
 

Returns the master time-out supervision value.

Remarks:
The time-out value is indicative only and not guaranteed to be maintained. How precise it is followed depends on the operating system used, it's scheduling priority and it's system timer resolution.
Returns:
Timeout value in ms

unsigned long getSuccessCounter  )  [inherited]
 

Returns how often a message transfer was successful.

Returns:
Counter value

virtual int serverLoop  )  [pure virtual, inherited]
 

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 endless loop:

 while (1)
 {
   mbusProtocol.serverLoop();
   doOtherStuff();
 }

Returns:
FTALK_SUCCESS on success or error code. See Protocol Errors and Exceptions for a list of error codes.

Implemented in MbusRtuSlaveProtocol, MbusAsciiSlaveProtocol, and MbusTcpSlaveProtocol.

void shutdownServer  )  [virtual, inherited]
 

Shuts down the Modbus Server.

This function also closes any associated serial ports or sockets.

Reimplemented in MbusSerialSlaveProtocol, and MbusTcpSlaveProtocol.

virtual int isStarted  )  [pure virtual, inherited]
 

Returns if server has been started up.

Return values:
true = started
false = shutdown

Implemented in MbusSerialSlaveProtocol, and MbusTcpSlaveProtocol.

virtual int getConnectionStatus  )  [pure virtual, inherited]
 

Associates a protocol object with a Data Provider and a slave address.

Parameters:
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.
Returns:
FTALK_SUCCESS on success or error code. See Protocol Errors and Exceptions for a list of error codes.

Implemented in MbusSerialSlaveProtocol, and MbusTcpSlaveProtocol.