Modbus Software, Driver and Libraries
 Login 
Member of Modbus Organization

Have a Question?

We accept VISA, MasterCard, PayPal

30-day Money-Back Guarantee

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 functions of conformance Class 0 and Class 1 have been implemented. In addition the most frequent used functions of conformance Class 2 have been implemented.

The following table lists the functions supported by the slave:

Function CodeCurrent Terminology Classic Terminology
Conformance Class 0
3 (03 hex)Read Multiple Registers Read Holding Registers
16 (10 hex)Write Multiple Registers Preset Multiple Registers
Conformance Class 1
1 (01 hex)Read CoilsRead Coil Status
2 (02 hex)Read Inputs Discretes Read Input Status
4 (04 hex)Read Input Registers Read Input Registers
5 (05 hex)Write CoilForce Single Coil
6 (06 hex)Write Single Register Preset Single Register
7 (07 hex)Read Exception Status Read Exception Status
Conformance Class 2
15 (0F hex)Force Multiple Coils Force Multiple Coils
22 (16 hex)Mask Write Register Mask Write Register
23 (17 hex)Read/Write Registers Read/Write Registers


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.

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.