Modbus Software, Driver and Libraries
 Login 
Member of Modbus Organization

Have a Question?

We accept VISA, MasterCard, PayPal

30-day Money-Back Guarantee

TMbusTcpMasterProtocol Class Reference
[MODBUS/TCP Protocol]

Inheritance diagram for TMbusTcpMasterProtocol:

Inheritance graph
Collaboration diagram for TMbusTcpMasterProtocol:

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:
Data and Control Functions for all Protocol Flavours

TMbusMasterFunctions


TCP/IP Connection Management Functions

 openProtocol ()
 Connects to a MODBUS/TCP slave.
 setPort (word portNo)
 Sets the TCP port number to be used by the protocol.
word getPort ()
 Returns the TCP port number used by the protocol.
string hostName
word port

Class 0 Modbus Functions

 writeMultipleRegisters (integer slaveAddr, integer startRef, word &*regArr)
 Modbus function 16 (10 hex), Preset Multiple Registers/Write Multiple Registers.
 writeMultipleLongInts (integer slaveAddr, integer startRef, integer &*int32Arr)
 Modbus function 16 (10 hex) for 32-bit long int data types, Preset Multiple Registers/Write Multiple Registers with long int data.
 writeMultipleMod10000 (integer slaveAddr, integer startRef, integer &*int32Arr)
 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.
 writeMultipleFloats (integer slaveAddr, integer startRef, single &*float32Arr)
 Modbus function 16 (10 hex) for 32-bit float data types, Preset Multiple Registers/Write Multiple Registers with float data.
 readMultipleRegisters (integer slaveAddr, integer startRef, word &*regArr)
 Modbus function 3 (03 hex), Read Holding Registers/Read Multiple Registers.
 readMultipleLongInts (integer slaveAddr, integer startRef, integer &*int32Arr)
 Modbus function 3 (03 hex) for 32-bit long int data types, Read Holding Registers/Read Multiple Registers as long int data.
 readMultipleMod10000 (integer slaveAddr, integer startRef, integer &*int32Arr)
 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.
 readMultipleFloats (integer slaveAddr, integer startRef, single &*float32Arr)
 Modbus function 3 (03 hex) for 32-bit float data types, Read Holding Registers/Read Multiple Registers as float data.

Class 1 Modbus Functions

 readCoils (integer slaveAddr, integer startRef, boolean &*bitArr)
 Modbus function 1 (01 hex), Read Coil Status/Read Coils.
 readInputDiscretes (integer slaveAddr, integer startRef, boolean &*bitArr)
 Modbus function 2 (02 hex), Read Inputs Status/Read Input Discretes.
 readInputRegisters (integer slaveAddr, integer startRef, word &*regArr)
 Modbus function 4 (04 hex), Read Input Registers.
 readInputLongInts (integer slaveAddr, integer startRef, integer &*int32Arr)
 Modbus function 4 (04 hex) for 32-bit long int data types, Read Input Registers as long int data.
 readInputMod10000 (integer slaveAddr, integer startRef, integer &*int32Arr)
 Modbus function 4 (04 hex) for 32-bit modulo-10000 long int data types, Read Input Registers as modulo-10000 long int data.
 readInputFloats (integer slaveAddr, integer startRef, single &*float32Arr)
 Modbus function 4 (04 hex) for 32-bit float data types, Read Input Registers as float data.
 writeCoil (integer slaveAddr, integer bitAddr, boolean bitVal)
 Modbus function 5 (05 hex), Force Single Coil/Write Coil.
 writeSingleRegister (integer slaveAddr, integer regAddr, word regVal)
 Modbus function 6 (06 hex), Preset Single Register/Write Single Register.
 readExceptionStatus (integer slaveAddr, byte &statusByte)
 Modbus function 7 (07 hex), Read Exception Status.

Class 2 Modbus Functions

 forceMultipleCoils (integer slaveAddr, integer startRef, boolean &*bitArr)
 Modbus function 15 (0F hex), Force Multiple Coils.
 maskWriteRegister (integer slaveAddr, integer regAddr, word andMask, word orMask)
 Modbus function 22 (16 hex), Mask Write Register.
 readWriteRegisters (integer slaveAddr, integer readRef, word &*readArr, integer writeRef, word &*writeArr)
 Modbus function 23 (17 hex), Read/Write Registers.

Protocol Configuration

 setTimeout (const integer timeOut)
 Configures time-out.
integer getTimeout ()
 Returns the time-out value.
 setPollDelay (const integer pollDelay)
 Configures poll delay.
integer getPollDelay ()
 Returns the poll delay time.
 setRetryCnt (const integer retryCnt)
 Configures the automatic retry setting.
integer getRetryCnt ()
 Returns the automatic retry count.
integer timeout
integer pollDelay
integer retryCnt
boolean bigEndianInts
boolean swappedFloats

Transmission Statistic Functions

cardinal getTotalCounter ()
 Returns how often a message transfer has been executed.
 resetTotalCounter ()
 Resets total message transfer counter.
cardinal getSuccessCounter ()
 Returns how often a message transfer was successful.
 resetSuccessCounter ()
 Resets successful message transfer counter.

Word Order Configuration

 configureBigEndianInts ()
 Configures int data type functions to do a word swap.
 configureSwappedFloats ()
 Configures float data type functions to do a word swap.
 configureLittleEndianInts ()
 Configures int data type functions not to do a word swap.
 configureIeeeFloats ()
 Configures float data type functions not to do a word swap.

Public Member Functions

 TMbusTcpMasterProtocol (TComponent aOwner)
 Constructs a TMbusTcpMasterProtocol object and initialises its data.
boolean isOpen ()
 Returns whether the protocol is open or not.
 closeProtocol ()
 Closes an open protocol including any associated communication resources (COM ports or sockets).
string getPackageVersion ()
 Returns the package version number.


Constructor & Destructor Documentation

TMbusTcpMasterProtocol TComponent  aOwner  ) 
 

Constructs a TMbusTcpMasterProtocol object and initialises its data.

Exceptions:
EOutOfResources Creation of class failed


Member Function Documentation

openProtocol  ) 
 

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 TCP port number is 502.
Exceptions:
EInOutError An I/O error occurred
EOpenErr The port could not be opened
EPortNoAccess No permission to access port
ETcpipConnectErr TCP/IP connection error, host not reachable
EConnectionWasClosed Remote peer closed TCP/IP connection
EIllegalArgumentError A parameter is invalid

setPort word  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
Exceptions:
EIllegalStateError Protocol is already open
EIllegalArgumentError A parameter is out of range

word getPort  ) 
 

Returns the TCP port number used by the protocol.

Returns:
Port number used by the protocol

boolean isOpen  )  [inherited]
 

Returns whether the protocol is open or not.

Return values:
true = open
false = closed


Member Data Documentation

string hostName
 

Note:
A protocol must be closed in order to configure it.
See also:
fHostName For reading

fHostName For writing

word port
 

Note:
A protocol must be closed in order to configure it.
Remarks:
Usually the port number remains unchanged and defaults to 502. However if the port number has to be different from 502 this property must be called before opening the connection with openProtocol().
See also:
getPort For reading

setPort For writing