FieldTalk Modbus® Master Protocol Library
C++ Editions
FOCUS Software Engineering

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

MbusTcpMasterProtocol Class Reference
[MODBUS/TCP Protocol]

Inheritance diagram for MbusTcpMasterProtocol:

Inheritance graph
Collaboration diagram for MbusTcpMasterProtocol:

Collaboration graph
List of all members.

Detailed Description

MODBUS/TCP Master Protocol class.

This class realises the MODBUS/TCP master protocol. It provides functions to establish and to close a TCP/IP connection to the slave as well as data and control functions which can be used after a connection to a slave device has been established successfully. The data and control functions are organized different conformance classes. For a more detailed description of the data and control functions see section Data and Control Functions for all Protocol Flavours.

It is also possible to instantiate multiple instances of this class for establishing multiple connections to either the same or different hosts.

Version:
1.1
See also:
mbusmaster

MbusMasterFunctions


TCP/IP Connection Management Functions

int openProtocol (const char *const hostName)
 Connects to a MODBUS/TCP slave.

virtual void closeProtocol ()
 Closes a TCP/IP connection to a slave and releases any system resources associated with the connection.

virtual int isOpen ()
 Returns whether currently connected or not.

int setPort (unsigned short portNo)
 Sets the TCP port number to be used by the protocol.

unsigned short getPort ()
 Returns the TCP port number used by the protocol.


Advantec ADAM 5000/6000 Series Commands

int adamSendReceiveAsciiCmd (const char *const commandSz, char *responseSz)
 Send/Receive ADAM 5000/6000 ASCII command.


Class 0 Modbus Functions

int writeMultipleRegisters (int slaveAddr, int startRef, const short regArr[], int refCnt)
 Modbus function 16 (10 hex), Preset Multiple Registers/Write Multiple Registers.

int writeMultipleLongInts (int slaveAddr, int startRef, const long int32Arr[], int refCnt)
 Modbus function 16 (10 hex) for 32-bit long int data types, Preset Multiple Registers/Write Multiple Registers with long int data.

int writeMultipleMod10000 (int slaveAddr, int startRef, const long int32Arr[], int refCnt)
 Modbus function 16 (10 hex) for 32-bit modulo-10000 long int data types, Preset Multiple Registers/Write Multiple Registers with modulo-10000 long int data.

int writeMultipleFloats (int slaveAddr, int startRef, const float float32Arr[], int refCnt)
 Modbus function 16 (10 hex) for 32-bit float data types, Preset Multiple Registers/Write Multiple Registers with float data.

int readMultipleRegisters (int slaveAddr, int startRef, short regArr[], int refCnt)
 Modbus function 3 (03 hex), Read Holding Registers/Read Multiple Registers.

int readMultipleLongInts (int slaveAddr, int startRef, long int32Arr[], int refCnt)
 Modbus function 3 (03 hex) for 32-bit long int data types, Read Holding Registers/Read Multiple Registers as long int data.

int readMultipleMod10000 (int slaveAddr, int startRef, long int32Arr[], int refCnt)
 Modbus function 3 (03 hex) for 32-bit modulo-10000 long int data types, Read Holding Registers/Read Multiple Registers as modulo-10000 long int data.

int readMultipleFloats (int slaveAddr, int startRef, float float32Arr[], int refCnt)
 Modbus function 3 (03 hex) for 32-bit float data types, Read Holding Registers/Read Multiple Registers as float data.


Class 1 Modbus Functions

int readCoils (int slaveAddr, int startRef, int bitArr[], int refCnt)
 Modbus function 1 (01 hex), Read Coil Status/Read Coils.

int readInputDiscretes (int slaveAddr, int startRef, int bitArr[], int refCnt)
 Modbus function 2 (02 hex), Read Inputs Status/Read Input Discretes.

int readInputRegisters (int slaveAddr, int startRef, short regArr[], int refCnt)
 Modbus function 4 (04 hex), Read Input Registers.

int readInputLongInts (int slaveAddr, int startRef, long int32Arr[], int refCnt)
 Modbus function 4 (04 hex) for 32-bit long int data types, Read Input Registers as long int data.

int readInputMod10000 (int slaveAddr, int startRef, long int32Arr[], int refCnt)
 Modbus function 4 (04 hex) for 32-bit modulo-10000 long int data types, Read Input Registers as modulo-10000 long int data.

int readInputFloats (int slaveAddr, int startRef, float float32Arr[], int refCnt)
 Modbus function 4 (04 hex) for 32-bit float data types, Read Input Registers as float data.

int writeCoil (int slaveAddr, int bitAddr, int bitVal)
 Modbus function 5 (05 hex), Force Single Coil/Write Coil.

int writeSingleRegister (int slaveAddr, int regAddr, short regVal)
 Modbus function 6 (06 hex), Preset Single Register/Write Single Register.

int readExceptionStatus (int slaveAddr, unsigned char *statusByte)
 Modbus function 7 (07 hex), Read Exception Status.


Class 2 Modbus Functions

int forceMultipleCoils (int slaveAddr, int startRef, const int bitArr[], int refCnt)
 Modbus function 15 (0F hex), Force Multiple Coils.

int maskWriteRegister (int slaveAddr, int regAddr, unsigned short andMask, unsigned short orMask)
 Modbus function 22 (16 hex), Mask Write Register.

int readWriteRegisters (int slaveAddr, int readRef, short readArr[], int readCnt, int writeRef, const short writeArr[], int writeCnt)
 Modbus function 23 (17 hex), Read/Write Registers.


Protocol Configuration

int setTimeout (int timeOut)
 Configures time-out.

int getTimeout ()
 Returns the time-out value.

int setPollDelay (int pollDelay)
 Configures poll delay.

int getPollDelay ()
 Returns the poll delay time.

int setRetryCnt (int retryCnt)
 Configures the automatic retry setting.

int getRetryCnt ()
 Returns the automatic retry count.


Transmission Statistic Functions

unsigned long getTotalCounter ()
 Returns how often a message transfer has been executed.

void resetTotalCounter ()
 Resets total message transfer counter.

unsigned long getSuccessCounter ()
 Returns how often a message transfer was successful.

void resetSuccessCounter ()
 Resets successful message transfer counter.


Word Order Configuration

void configureBigEndianInts ()
 Configures int data type functions to do a word swap.

void configureSwappedFloats ()
 Configures float data type functions to do a word swap.

void configureLittleEndianInts ()
 Configures int data type functions not to do a word swap.

void configureIeeeFloats ()
 Configures float data type functions not to do a word swap.


Public Member Functions

 MbusTcpMasterProtocol ()
 Constructs a MbusTcpMasterProtocol object and initialises its data.


Static Public Member Functions

char * getPackageVersion ()
 Returns the package version number.


Member Function Documentation

int openProtocol const char *const  hostName  ) 
 

Connects to a MODBUS/TCP slave.

This function establishes a logical network connection between master and slave. After a connection has been established data and control functions can be used. A TCP/IP connection should be closed if it is no longer needed.

Note:
The default time-out for the connection is 1000 ms.

The default TCP port number is 502.

Parameters:
hostName String with IP address or host name
Returns:
FTALK_SUCCESS on success or error code. See Protocol Errors and Exceptions for a list of error codes.

Reimplemented in MbusRtuOverTcpMasterProtocol.

int isOpen  )  [virtual]
 

Returns whether currently connected or not.

Return values:
true = connected
false = not connected

Reimplemented from MbusMasterFunctions.

int setPort unsigned short  portNo  ) 
 

Sets the TCP port number to be used by the protocol.

Remarks:
Usually the port number remains unchanged and defaults to 502. In this case no call to this function is necessary. However if the port number has to be different from 502 this function must be called before opening the connection with openProtocol().
Parameters:
portNo Port number to be used when opening the connection
Return values:
FTALK_SUCCESS Success
FTALK_ILLEGAL_STATE_ERROR Protocol already open

Reimplemented in MbusRtuOverTcpMasterProtocol.

unsigned short getPort  ) 
 

Returns the TCP port number used by the protocol.

Returns:
Port number used by the protocol