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).
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.
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:
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.