FieldTalk Modbus Slave C++ Library  Library version 2.6.1

This FieldTalk Modbus® Slave C++ Library allows you to incorporate Modbus slave functionality into your own programs.


Typical applications are Modbus based Supervisory Control and Data Acquisition Systems (SCADA), Modbus data concentrators, Modbus gateways, User Interfaces and Factory Information Systems (FIS).


  • Robust design suitable for real-time and industrial applications
  • Full implementation of Bit Access and 16 Bits Access Function Codes as well as a subset of the most commonly used Diagnostics Function Codes
  • Standard Modbus bit and 16-bit integer data types (coils, discretes & registers)
  • Daniel/Enron single register 32-bit transfers
  • File Record read & write functions
  • Support of Broadcasting
  • Master time-out supervision
  • Failure and transmission counters
  • Supports single or multiple slave addresses

Library Structure

The library is organised in two categories of classes.

One category implements the Server Engines for each Modbus slave protocol flavour. There is one Server Engine class for each protocol flavour and a common Server Engine base class, which applies to all protocol flavours. Because the two serial protocols ASCII and RTU share some common code, an intermediate base class implements the functions specific to serial protocols.


The second category of classes is Data Providers classes. Data Provider classes represent the interface between the Server Engine and your application.


The base class MbusSlaveServer contains a protocol unspecific contains a protocol unspecific Server Engine and the protocol state machine. All protocol flavours inherit from this base class.

The class MbusAsciiSlaveProtocol implements the Modbus ASCII protocol, the class MbusRtuSlaveProtocol implements the Modbus RTU protocol and the class MbusTcpSlaveProtocol implements the MODBUS/TCP protocol.

Before a server can be used, a Data Provider has to be declared. A Data Provider is created by declaring a new class derived from MbusDataTableInterface. The class MbusDataTableInterface is the base class for a Data Provider and implements a set of default methods. An application specific Data Provider simply overrides selected default methods and the Modbus slave is ready.

class MyMbusDataTable: public MbusDataTableInterface
... // Application specific data interface
} dataTable;

In order to use one of the three slave protocols, the desired protocol flavour class has to be instantiated and associated with the Data Provider. The following example creates an RTU protocol and links a data table to slave address 20:

MbusRtuSlaveProtocol mbusProtocol;
mbusProtocol.addDataTable(20, &dataTable);

After a protocol object has been declared and started up the server loop has to be executed cyclically. The Modbus slave is ready to accept connections and to reply to master queries.

while (1)