FieldTalk Modbus Master Library, Delphi Edition  Library version 2.12.0
TMbusUdpMasterProtocol Class Reference

MODBUS/UDP Master Protocol class. More...

Public Member Functions

 TMbusUdpMasterProtocol (TComponent aOwner)
 Constructs a TMbusUdpMasterProtocol object and initialises its data. More...
 
 openProtocol ()
 Connects to a MODBUS/TCP slave. More...
 
 setPort (word portNo)
 Sets the TCP port number to be used by the protocol. More...
 
 setClosingTimeout (const integer msTime)
 Applies a time-out to socket closure and makes closeProtocol() wait for the server to acknowledge closing before potentially opening a new one. More...
 
word getPort ()
 Returns the TCP port number used by the protocol. More...
 
boolean isOpen ()
 Returns whether the protocol is open or not. More...
 
 closeProtocol ()
 Closes an open protocol including any associated communication resources (COM ports or sockets).
 
string getPackageVersion ()
 Returns the package version number. More...
 

Public Attributes

string hostName
 Host name property (eg '127.0.0.1') More...
 
word port
 TCP port property (eg 502) More...
 

Bit Access

Table 0:00000 (Coils) and Table 1:00000 (Input Status)

 readCoils (integer slaveAddr, integer startRef, boolean []bitArr)
 Modbus function 1 (01 hex), Read Coil Status/Read Coils. More...
 
 readInputDiscretes (integer slaveAddr, integer startRef, boolean []bitArr)
 Modbus function 2 (02 hex), Read Inputs Status/Read Input Discretes. More...
 
 writeCoil (integer slaveAddr, integer bitAddr, boolean bitVal)
 Modbus function 5 (05 hex), Force Single Coil/Write Coil. More...
 
 forceMultipleCoils (integer slaveAddr, integer startRef, boolean []bitArr)
 Modbus function 15 (0F hex), Force Multiple Coils. More...
 

16-bit Access

Table 4:00000 (Holding Registers) and Table 3:00000 (Input Registers)

 readMultipleRegisters (integer slaveAddr, integer startRef, word []regArr)
 Modbus function 3 (03 hex), Read Holding Registers/Read Multiple Registers. More...
 
 readInputRegisters (integer slaveAddr, integer startRef, word []regArr)
 Modbus function 4 (04 hex), Read Input Registers. More...
 
 writeSingleRegister (integer slaveAddr, integer regAddr, word regVal)
 Modbus function 6 (06 hex), Preset Single Register/Write Single Register. More...
 
 writeMultipleRegisters (integer slaveAddr, integer startRef, word []regArr)
 Modbus function 16 (10 hex), Preset Multiple Registers/Write Multiple Registers. More...
 
 maskWriteRegister (integer slaveAddr, integer regAddr, word andMask, word orMask)
 Modbus function 22 (16 hex), Mask Write Register. More...
 
 readWriteRegisters (integer slaveAddr, integer readRef, word []readArr, integer writeRef, word []writeArr)
 Modbus function 23 (17 hex), Read/Write Registers. More...
 

32-bit Access

Table 4:00000 (Holding Registers) and Table 3:00000 (Input 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. More...
 
 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. More...
 
 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. More...
 
 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. More...
 
 readInputFloats (integer slaveAddr, integer startRef, single []float32Arr)
 Modbus function 4 (04 hex) for 32-bit float data types, Read Input Registers as float data. More...
 
 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. More...
 
 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. More...
 
 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. More...
 
 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. More...
 

64-bit Access

Table 4:00000 (Holding Registers) and Table 3:00000 (Input Registers)

 readHoldingRegistersI64 (integer slaveAddr, integer startRef, int64 []int64Arr)
 Modbus function 3 for 64-bit integer data, Read Holding Registers as int64_t type. More...
 
 readInputRegistersI64 (integer slaveAddr, integer startRef, int64 []int64Arr)
 Modbus function 4 for 64-bit integer data, Read Holding Registers as int64_t type. More...
 
 writeMultipleRegistersI64 (integer slaveAddr, integer startRef, int64 []int64Arr)
 Modbus function 16 (10 Hex) for 64-bit integer data, Write Multiple Registers as int64_t type. More...
 
 readHoldingRegistersF64 (integer slaveAddr, integer startRef, double []doubleArr)
 Modbus function 3 for 64-bit floating point data, Read Input Registers as double type. More...
 
 readInputRegistersF64 (integer slaveAddr, integer startRef, double []doubleArr)
 Modbus function 4 for 64-bit floating point data, Read Input Registers as double type. More...
 
 writeMultipleRegistersF64 (integer slaveAddr, integer startRef, double []doubleArr)
 Modbus function 16 (10 Hex) for 64-bit floating point data, Write Multiple Registers as double type. More...
 

Diagnostics

 readExceptionStatus (integer slaveAddr, byte &statusByte)
 Modbus function 7 (07 hex), Read Exception Status. More...
 
 returnQueryData (integer slaveAddr, byte []queryArr, byte []echoArr)
 Modbus function code 8, sub-function 00, Return Query Data. More...
 
 restartCommunicationsOption (integer slaveAddr, boolean clearEventLog)
 Modbus function code 8, sub-function 01, Restart Communications Option. More...
 

Custom Function Codes

 customFunction (integer slaveAddr, integer functionCode, byte []requestArr, byte []responseArr, integer &responseLen)
 User Defined Function CodeThis method can be used to implement User Defined Function Codes. More...
 

Protocol Configuration

 setTimeout (const integer timeOut)
 Configures time-out. More...
 
integer getTimeout ()
 Returns the time-out value. More...
 
 setPollDelay (const integer pollDelay)
 Configures poll delay. More...
 
integer getPollDelay ()
 Returns the poll delay time. More...
 
 setRetryCnt (const integer retryCnt)
 Configures the automatic retry setting. More...
 
integer getRetryCnt ()
 Returns the automatic retry count. More...
 
integer timeout
 Time-out port property. More...
 
integer pollDelay
 Poll delay property. More...
 
integer retryCnt
 Retry count property. More...
 

Transmission Statistic Functions

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

Slave Configuration

 configureBigEndianInts ()
 Configures int data type functions to do a word swap. More...
 
 configureBigEndianInts (integer slaveAddr)
 Enables int data type functions to do a word swap on a per slave basis. More...
 
 configureSwappedFloats ()
 Configures float data type functions to do a word swap. More...
 
 configureSwappedFloats (integer slaveAddr)
 Enables float data type functions to do a word swap on a per slave basis. More...
 
 configureLittleEndianInts ()
 Configures int data type functions not to do a word swap. More...
 
 configureLittleEndianInts (integer slaveAddr)
 Disables word swapping for int data type functions on a per slave basis. More...
 
 configureIeeeFloats ()
 Configures float data type functions not to do a word swap. More...
 
 configureIeeeFloats (integer slaveAddr)
 Disables float data type functions to do a word swap on a per slave basis. More...
 
 configureStandard32BitMode ()
 Configures all slaves for Standard 32-bit Mode. More...
 
 configureStandard32BitMode (integer slaveAddr)
 Configures a slave for Standard 32-bit Register Mode. More...
 
 configureEnron32BitMode ()
 Configures all slaves for Daniel/ENRON 32-bit Mode. More...
 
 configureEnron32BitMode (integer slaveAddr)
 Configures all slaves for Daniel/ENRON 32-bit Mode. More...
 
 configureCountFromOne ()
 Configures the reference counting scheme to start with one for all slaves. More...
 
 configureCountFromOne (integer slaveAddr)
 Configures a slave's reference counting scheme to start with one. More...
 
 configureCountFromZero ()
 Configures the reference counting scheme to start with zero for all slaves. More...
 
 configureCountFromZero (integer slaveAddr)
 Configures a slave's reference counting scheme to start with zero. More...
 

Detailed Description

MODBUS/UDP Master Protocol class.

This class realises a Modbus client using MODBUS over UDP protocol variant. It provides functions to establish a UDP 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 into different conformance classes. For a more detailed description of the data and control functions see section Data and Control Functions for all Modbus Protocol Flavours.

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

See also
Data and Control Functions for all Modbus Protocol Flavours, IP based Protocols

Constructor & Destructor Documentation

◆ TMbusUdpMasterProtocol()

TMbusUdpMasterProtocol ( TComponent  aOwner)

Constructs a TMbusUdpMasterProtocol object and initialises its data.

Exceptions
EOutOfResourcesCreation of class failed

Member Function Documentation

◆ openProtocol()

openProtocol ( )
inherited

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
EInOutErrorAn I/O error occurred
EOpenErrThe port could not be opened
EPortNoAccessNo permission to access port
ETcpipConnectErrTCP/IP connection error, host not reachable
EConnectionWasClosedRemote peer closed TCP/IP connection
EIllegalArgumentErrorA parameter is invalid

◆ setPort()

setPort ( word  portNo)
inherited

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
portNoPort number to be used when opening the connection
Exceptions
EIllegalStateErrorProtocol is already open
EIllegalArgumentErrorA parameter is out of range

◆ setClosingTimeout()

setClosingTimeout ( const integer  msTime)
inherited

Applies a time-out to socket closure and makes closeProtocol() wait for the server to acknowledge closing before potentially opening a new one.

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
A protocol must be closed in order to configure it.
Parameters
msTimeTimeout value in ms (Range: 1 - 100000)
Exceptions
EIllegalStateErrorProtocol is already open
EIllegalArgumentErrorA parameter is out of range

◆ getPort()

word getPort ( )
inherited

Returns the TCP port number used by the protocol.

Returns
Port number used by the protocol

◆ readCoils()

readCoils ( integer  slaveAddr,
integer  startRef,
boolean []  bitArr 
)
inherited

Modbus function 1 (01 hex), Read Coil Status/Read Coils.

Reads the contents of the discrete outputs (coils, 0:00000 table).

Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 1 - 255)
startRefStart reference (Range: 1 - 65536)
bitArrBuffer which will contain the data read. The length of the array determines how many coils are read (Range: 1-2000).
Exceptions
EIllegalStateErrorPort or connection is closed
EInOutErrorAn I/O error occurred
EIllegalArgumentErrorA parameter is out of range
EBusProtocolExceptionA protocol failure occurred. See descendants of EBusProtocolException for a more detailed failure list.
Note
No broadcast supported

◆ readInputDiscretes()

readInputDiscretes ( integer  slaveAddr,
integer  startRef,
boolean []  bitArr 
)
inherited

Modbus function 2 (02 hex), Read Inputs Status/Read Input Discretes.

Reads the contents of the discrete inputs (input status, 1:00000 table).

Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 1 - 255)
startRefStart reference (Range: 1 - 65536)
bitArrBuffer which will contain the data read. The length of the array determines how many inputs are read (Range: 1-2000).
Exceptions
EIllegalStateErrorPort or connection is closed
EInOutErrorAn I/O error occurred
EIllegalArgumentErrorA parameter is out of range
EBusProtocolExceptionA protocol failure occurred. See descendants of EBusProtocolException for a more detailed failure list.
Note
No broadcast supported

◆ writeCoil()

writeCoil ( integer  slaveAddr,
integer  bitAddr,
boolean  bitVal 
)
inherited

Modbus function 5 (05 hex), Force Single Coil/Write Coil.

Sets a single discrete output variable (coil, 0:00000 table) to either ON or OFF.

Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 0 - 255)
bitAddrCoil address (Range: 1 - 65536)
bitValtrue sets, false clears discrete output variable
Exceptions
EIllegalStateErrorPort or connection is closed
EInOutErrorAn I/O error occurred
EIllegalArgumentErrorA parameter is out of range
EBusProtocolExceptionA protocol failure occurred. See descendants of EBusProtocolException for a more detailed failure list.
Note
Broadcast supported for serial protocols

◆ forceMultipleCoils()

forceMultipleCoils ( integer  slaveAddr,
integer  startRef,
boolean []  bitArr 
)
inherited

Modbus function 15 (0F hex), Force Multiple Coils.

Writes binary values into a sequence of discrete outputs (coils, 0:00000 table).

Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 1 - 255)
startRefStart reference (Range: 1 - 65536)
bitArrBuffer which contains the data to be sent. The length of the array determines how many coils are written (Range: 1-1968).
Exceptions
EIllegalStateErrorPort or connection is closed
EInOutErrorAn I/O error occurred
EIllegalArgumentErrorA parameter is out of range
EBusProtocolExceptionA protocol failure occurred. See descendants of EBusProtocolException for a more detailed failure list.
Note
Broadcast supported for serial protocols

◆ readMultipleRegisters()

readMultipleRegisters ( integer  slaveAddr,
integer  startRef,
word []  regArr 
)
inherited

Modbus function 3 (03 hex), Read Holding Registers/Read Multiple Registers.

Reads the contents of the output registers (holding registers, 4:00000 table).

Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 1 - 255)
startRefStart register (Range: 1 - 65536)
regArrBuffer which will be filled with the data read. The length of the array determines how many registers are read (Range: 1-125).
Exceptions
EIllegalStateErrorPort or connection is closed
EInOutErrorAn I/O error occurred
EIllegalArgumentErrorA parameter is out of range
EBusProtocolExceptionA protocol failure occurred. See descendants of EBusProtocolException for a more detailed failure list.
Note
No broadcast supported

◆ readInputRegisters()

readInputRegisters ( integer  slaveAddr,
integer  startRef,
word []  regArr 
)
inherited

Modbus function 4 (04 hex), Read Input Registers.

Read the contents of the input registers (3:00000 table).

Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 1 - 255)
startRefStart register (Range: 1 - 65536)
regArrBuffer which will be filled with the data read. The length of the array determines how many registers are read (Range: 1-125).
Exceptions
EIllegalStateErrorPort or connection is closed
EInOutErrorAn I/O error occurred
EIllegalArgumentErrorA parameter is out of range
EBusProtocolExceptionA protocol failure occurred. See descendants of EBusProtocolException for a more detailed failure list.
Note
No broadcast supported

◆ writeSingleRegister()

writeSingleRegister ( integer  slaveAddr,
integer  regAddr,
word  regVal 
)
inherited

Modbus function 6 (06 hex), Preset Single Register/Write Single Register.

Writes a value into a single output register (holding register, 4:00000 reference).

Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 0 - 255)
regAddrRegister address (Range: 1 - 65536)
regValData to be sent
Exceptions
EIllegalStateErrorPort or connection is closed
EInOutErrorAn I/O error occurred
EIllegalArgumentErrorA parameter is out of range
EBusProtocolExceptionA protocol failure occurred. See descendants of EBusProtocolException for a more detailed failure list.
Note
Broadcast supported for serial protocols

◆ writeMultipleRegisters()

writeMultipleRegisters ( integer  slaveAddr,
integer  startRef,
word []  regArr 
)
inherited

Modbus function 16 (10 hex), Preset Multiple Registers/Write Multiple Registers.

Writes values into a sequence of output registers (holding registers, 4:00000 table).

Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 0 - 255)
startRefStart register (Range: 1 - 65536)
regArrBuffer with the data to be sent.The length of the array determines how many registers are written (Range: 1-123).
Exceptions
EIllegalStateErrorPort or connection is closed
EInOutErrorAn I/O error occurred
EIllegalArgumentErrorA parameter is out of range
EBusProtocolExceptionA protocol failure occurred. See descendants of EBusProtocolException for a more detailed failure list.
Note
Broadcast supported for serial protocols

◆ maskWriteRegister()

maskWriteRegister ( integer  slaveAddr,
integer  regAddr,
word  andMask,
word  orMask 
)
inherited

Modbus function 22 (16 hex), Mask Write Register.

Masks bits according to an AND & an OR mask into a single output register (holding register, 4:00000 reference). Masking is done as follows: result = (currentVal AND andMask) OR (orMask AND (NOT andMask))

Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 1 - 255)
regAddrRegister address (Range: 1 - 65536)
andMaskMask to be applied as a logic AND to the register
orMaskMask to be applied as a logic OR to the register
Note
No broadcast supported

◆ readWriteRegisters()

readWriteRegisters ( integer  slaveAddr,
integer  readRef,
word []  readArr,
integer  writeRef,
word []  writeArr 
)
inherited

Modbus function 23 (17 hex), Read/Write Registers.

Combines reading and writing of the output registers in one transaction (holding registers, 4:00000 table).

Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 1 - 255)
readRefStart registers for reading (Range: 1 - 65536)
readArrBuffer which will contain the data read. The length of the array determines how many registers are read (Range: 1-125).
writeRefStart registers for writing (Range: 1 - 65536)
writeArrBuffer with data to be sent. The length of the array determines how many registers are written (Range: 1-121).
Exceptions
EIllegalStateErrorPort or connection is closed
EInOutErrorAn I/O error occurred
EIllegalArgumentErrorA parameter is out of range
EBusProtocolExceptionA protocol failure occurred. See descendants of EBusProtocolException for a more detailed failure list.
Note
No broadcast supported

◆ readMultipleLongInts()

readMultipleLongInts ( integer  slaveAddr,
integer  startRef,
integer []  int32Arr 
)
inherited

Modbus function 3 (03 hex) for 32-bit long int data types, Read Holding Registers/Read Multiple Registers as long int data.

Reads the contents of pairs of consecutive output registers (holding registers, 4:00000 table) into 32-bit long int values.

Remarks
Modbus does not know about any other data type than discretes and 16-bit registers. Because a long int value is of 32-bit length, it will be transferred as two consecutive 16-bit registers. This means that the amount of registers transferred with this function is twice the amount of int values passed to this function.
Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 1 - 255)
startRefStart reference (Range: 1 - 65536)
int32ArrBuffer which will be filled with the data read. The length of the array determines how many values are read (Range: 1-62).
Exceptions
EIllegalStateErrorPort or connection is closed
EInOutErrorAn I/O error occurred
EIllegalArgumentErrorA parameter is out of range
EBusProtocolExceptionA protocol failure occurred. See descendants of EBusProtocolException for a more detailed failure list.
Note
No broadcast supported

◆ readInputLongInts()

readInputLongInts ( integer  slaveAddr,
integer  startRef,
integer []  int32Arr 
)
inherited

Modbus function 4 (04 hex) for 32-bit long int data types, Read Input Registers as long int data.

Reads the contents of pairs of consecutive input registers (3:00000 table) into 32-bit long int values.

Remarks
Modbus does not know about any other data type than discretes and 16-bit registers. Because a long int value is of 32-bit length, it will be transferred as two consecutive 16-bit registers. This means that the amount of registers transferred with this function is twice the amount of int values passed to this function.
Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 1 - 255)
startRefStart reference (Range: 1 - 65536)
int32ArrBuffer which will be filled with the data read. The length of the array determines how many values are read (Range: 1-62).
Exceptions
EIllegalStateErrorPort or connection is closed
EInOutErrorAn I/O error occurred
EIllegalArgumentErrorA parameter is out of range
EBusProtocolExceptionA protocol failure occurred. See descendants of EBusProtocolException for a more detailed failure list.
Note
No broadcast supported

◆ writeMultipleLongInts()

writeMultipleLongInts ( integer  slaveAddr,
integer  startRef,
integer []  int32Arr 
)
inherited

Modbus function 16 (10 hex) for 32-bit long int data types, Preset Multiple Registers/Write Multiple Registers with long int data.

Writes long int values into pairs of output registers (holding registers, 4:00000 table).

Remarks
Modbus does not know about any other data type than discretes and 16-bit registers. Because a long int value is of 32-bit length, it will be transferred as two consecutive 16-bit registers. This means that the amount of registers transferred with this function is twice the amount of int values passed to this function.
Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 0 - 255)
startRefStart reference (Range: 1 - 65536)
int32ArrBuffer with the data to be sent. The length of the array determines how many values are read (Range: 1-61).
Exceptions
EIllegalStateErrorPort or connection is closed
EInOutErrorAn I/O error occurred
EIllegalArgumentErrorA parameter is out of range
EBusProtocolExceptionA protocol failure occurred. See descendants of EBusProtocolException for a more detailed failure list.
Note
Broadcast supported for serial protocols

◆ readMultipleFloats()

readMultipleFloats ( integer  slaveAddr,
integer  startRef,
single []  float32Arr 
)
inherited

Modbus function 3 (03 hex) for 32-bit float data types, Read Holding Registers/Read Multiple Registers as float data.

Reads the contents of pairs of consecutive output registers (holding registers, 4:00000 table) into float values.

Remarks
Modbus does not know about any other data type than discretes and 16-bit registers. Because a float value is of 32-bit length, it will be transferred as two consecutive 16-bit registers. This means that the amount of registers transferred with this function is twice the amount of float values passed to this function.
Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 1 - 255)
startRefStart reference (Range: 1 - 65536)
float32ArrBuffer which will be filled with the data read. The length of the array determines how many values are read (Range: 1-62).
Exceptions
EIllegalStateErrorPort or connection is closed
EInOutErrorAn I/O error occurred
EIllegalArgumentErrorA parameter is out of range
EBusProtocolExceptionA protocol failure occurred. See descendants of EBusProtocolException for a more detailed failure list.
Note
No broadcast supported

◆ readInputFloats()

readInputFloats ( integer  slaveAddr,
integer  startRef,
single []  float32Arr 
)
inherited

Modbus function 4 (04 hex) for 32-bit float data types, Read Input Registers as float data.

Reads the contents of pairs of consecutive input registers (3:00000 table) into float values.

Remarks
Modbus does not know about any other data type than discretes and 16-bit registers. Because a float value is of 32-bit length, it will be transferred as two consecutive 16-bit registers. This means that the amount of registers transferred with this function is twice the amount of float values passed to this function.
Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 1 - 255)
startRefStart reference (Range: 1 - 65536)
float32ArrBuffer which will be filled with the data read. The length of the array determines how many values are read (Range: 1-62).
Exceptions
EIllegalStateErrorPort or connection is closed
EInOutErrorAn I/O error occurred
EIllegalArgumentErrorA parameter is out of range
EBusProtocolExceptionA protocol failure occurred. See descendants of EBusProtocolException for a more detailed failure list.
Note
No broadcast supported

◆ writeMultipleFloats()

writeMultipleFloats ( integer  slaveAddr,
integer  startRef,
single []  float32Arr 
)
inherited

Modbus function 16 (10 hex) for 32-bit float data types, Preset Multiple Registers/Write Multiple Registers with float data.

Writes float values into pairs of output registers (holding registers, 4:00000 table).

Remarks
Modbus does not know about any other data type than discretes and 16-bit registers. Because a float value is of 32-bit length, it will be transferred as two consecutive 16-bit registers. This means that the amount of registers transferred with this function is twice the amount of float values passed to this function.
Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 0 - 255)
startRefStart reference (Range: 1 - 65536)
float32ArrBuffer with the data to be sent. The length of the array determines how many values are written (Range: 1-61).
Exceptions
EIllegalStateErrorPort or connection is closed
EInOutErrorAn I/O error occurred
EIllegalArgumentErrorA parameter is out of range
EBusProtocolExceptionA protocol failure occurred. See descendants of EBusProtocolException for a more detailed failure list.
Note
Broadcast supported for serial protocols

◆ readMultipleMod10000()

readMultipleMod10000 ( integer  slaveAddr,
integer  startRef,
integer []  int32Arr 
)
inherited

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.

Reads the contents of pairs of consecutive output registers (holding registers, 4:00000 table) representing a modulo-10000 long int value into 32-bit int values and performs number format conversion.

Remarks
Modbus does not know about any other data type than discretes and 16-bit registers. Because a modulo-10000 value is of 32-bit length, it will be transferred as two consecutive 16-bit registers. This means that the amount of registers transferred with this function is twice the amount of int values passed to this function.
Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 1 - 255)
startRefStart reference (Range: 1 - 65536)
int32ArrBuffer which will be filled with the data read. The length of the array determines how many values are read (Range: 1-62).
Exceptions
EIllegalStateErrorPort or connection is closed
EInOutErrorAn I/O error occurred
EIllegalArgumentErrorA parameter is out of range
EBusProtocolExceptionA protocol failure occurred. See descendants of EBusProtocolException for a more detailed failure list.
Note
No broadcast supported

◆ readInputMod10000()

readInputMod10000 ( integer  slaveAddr,
integer  startRef,
integer []  int32Arr 
)
inherited

Modbus function 4 (04 hex) for 32-bit modulo-10000 long int data types, Read Input Registers as modulo-10000 long int data.

Reads the contents of pairs of consecutive input registers (3:00000 table) representing a modulo-10000 long int value into 32-bit long int values and performs number format conversion.

Remarks
Modbus does not know about any other data type than discretes and 16-bit registers. Because an modulo-10000 value is of 32-bit length, it will be transferred as two consecutive 16-bit registers. This means that the amount of registers transferred with this function is twice the amount of int values passed to this function.
Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 1 - 255)
startRefStart reference (Range: 1 - 65536)
int32ArrBuffer which will be filled with the data read. The length of the array determines how many values are read (Range: 1-62).
Exceptions
EIllegalStateErrorPort or connection is closed
EInOutErrorAn I/O error occurred
EIllegalArgumentErrorA parameter is out of range
EBusProtocolExceptionA protocol failure occurred. See descendants of EBusProtocolException for a more detailed failure list.
Note
No broadcast supported

◆ writeMultipleMod10000()

writeMultipleMod10000 ( integer  slaveAddr,
integer  startRef,
integer []  int32Arr 
)
inherited

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.

Writes long int values into pairs of output registers (holding registers, 4:00000 table) representing a modulo-10000 long int value and performs number format conversion.

Remarks
Modbus does not know about any other data type than discretes and 16-bit registers. Because a modulo-10000 value is of 32-bit length, it will be transferred as two consecutive 16-bit registers. This means that the amount of registers transferred with this function is twice the amount of int values passed to this function.
Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 0 - 255)
startRefStart reference (Range: 1 - 65536)
int32ArrBuffer with the data to be sent. The length of the array determines how many values are written (Range: 1-61).
Exceptions
EIllegalStateErrorPort or connection is closed
EInOutErrorAn I/O error occurred
EIllegalArgumentErrorA parameter is out of range
EBusProtocolExceptionA protocol failure occurred. See descendants of EBusProtocolException for a more detailed failure list.
Note
Broadcast supported for serial protocols

◆ readHoldingRegistersI64()

readHoldingRegistersI64 ( integer  slaveAddr,
integer  startRef,
int64 []  int64Arr 
)
inherited

Modbus function 3 for 64-bit integer data, Read Holding Registers as int64_t type.

Reads the contents of quartets of consecutive holding registers (4:00000 table) into 64-bit integer values.

Remarks
Depending on the 32-bit Mode setting, an int64_t will be transferred as four consecutive 16-bit registers (Standard) or as two 32-bit registers (Daniel/Enron).
Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 1 - 255)
startRefStart reference (Range: 1 - 65536)
int64ArrBuffer which will be filled with the data read. The length of the array determines how many values are read (Range: 1-31).
Exceptions
EIllegalStateErrorPort or connection is closed
EInOutErrorAn I/O error occurred
EIllegalArgumentErrorA parameter is out of range
EBusProtocolExceptionA protocol failure occurred. See descendants of EBusProtocolException for a more detailed failure list.
Note
No broadcast supported

◆ readInputRegistersI64()

readInputRegistersI64 ( integer  slaveAddr,
integer  startRef,
int64 []  int64Arr 
)
inherited

Modbus function 4 for 64-bit integer data, Read Holding Registers as int64_t type.

Reads the contents of quartets of consecutive input registers (3:00000 table) into 64-bit integer values.

Remarks
Depending on the 32-bit Mode setting, an int64_t will be transferred as four consecutive 16-bit registers (Standard) or as two 32-bit registers (Daniel/Enron).
Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 1 - 255)
startRefStart reference (Range: 1 - 65536)
int64ArrBuffer which will be filled with the data read. The length of the array determines how many values are read (Range: 1-31).
Exceptions
EIllegalStateErrorPort or connection is closed
EInOutErrorAn I/O error occurred
EIllegalArgumentErrorA parameter is out of range
EBusProtocolExceptionA protocol failure occurred. See descendants of EBusProtocolException for a more detailed failure list.
Note
No broadcast supported

◆ writeMultipleRegistersI64()

writeMultipleRegistersI64 ( integer  slaveAddr,
integer  startRef,
int64 []  int64Arr 
)
inherited

Modbus function 16 (10 Hex) for 64-bit integer data, Write Multiple Registers as int64_t type.

Writes for 64-bit integer values into quartets of holding registers (4:00000 table).

Remarks
Depending on the 32-bit Mode setting, an int will be transferred as four consecutive 16-bit registers (Standard) or as two 32-bit registers (Daniel/Enron).
Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 0 - 255)
startRefStart reference (Range: 1 - 65536)
int64ArrBuffer with the data to be sent. The length of the array determines how many values are read (Range: 1-30).
Exceptions
EIllegalStateErrorPort or connection is closed
EInOutErrorAn I/O error occurred
EIllegalArgumentErrorA parameter is out of range
EBusProtocolExceptionA protocol failure occurred. See descendants of EBusProtocolException for a more detailed failure list.
Note
Broadcast supported for serial protocols

◆ readHoldingRegistersF64()

readHoldingRegistersF64 ( integer  slaveAddr,
integer  startRef,
double []  doubleArr 
)
inherited

Modbus function 3 for 64-bit floating point data, Read Input Registers as double type.

Reads the contents of quartets of consecutive input registers (4:00000 table) into 64-bit floating point values.

Remarks
Depending on the 32-bit Mode setting, a double will be transferred as four consecutive 16-bit registers (Standard) or as two 32-bit registers (Daniel/Enron).
Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 1 - 255)
startRefStart reference (Range: 1 - 65536)
double64ArrBuffer which will be filled with the data read. The length of the array determines how many values are read (Range: 1-31).
Exceptions
EIllegalStateErrorPort or connection is closed
EInOutErrorAn I/O error occurred
EIllegalArgumentErrorA parameter is out of range
EBusProtocolExceptionA protocol failure occurred. See descendants of EBusProtocolException for a more detailed failure list.
Note
No broadcast supported

◆ readInputRegistersF64()

readInputRegistersF64 ( integer  slaveAddr,
integer  startRef,
double []  doubleArr 
)
inherited

Modbus function 4 for 64-bit floating point data, Read Input Registers as double type.

Reads the contents of quartets of consecutive input registers (3:00000 table) into 64-bit floating point values.

Remarks
Depending on the 32-bit Mode setting, a double will be transferred as four consecutive 16-bit registers (Standard) or as two 32-bit registers (Daniel/Enron).
Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 1 - 255)
startRefStart reference (Range: 1 - 65536)
doubleArrBuffer which will be filled with the data read. The length of the array determines how many values are read (Range: 1-31).
Exceptions
EIllegalStateErrorPort or connection is closed
EInOutErrorAn I/O error occurred
EIllegalArgumentErrorA parameter is out of range
EBusProtocolExceptionA protocol failure occurred. See descendants of EBusProtocolException for a more detailed failure list.
Note
No broadcast supported

◆ writeMultipleRegistersF64()

writeMultipleRegistersF64 ( integer  slaveAddr,
integer  startRef,
double []  doubleArr 
)
inherited

Modbus function 16 (10 Hex) for 64-bit floating point data, Write Multiple Registers as double type.

Writes for 64-bit floating point values into quartets of holding registers (4:00000 table).

Remarks
Depending on the 32-bit Mode setting, a double will be transferred as four consecutive 16-bit registers (Standard) or as two 32-bit registers (Daniel/Enron).
Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 0 - 255)
startRefStart reference (Range: 1 - 65536)
double64ArrBuffer with the data to be sent. The length of the array determines how many values are written (Range: 1-30).
Exceptions
EIllegalStateErrorPort or connection is closed
EInOutErrorAn I/O error occurred
EIllegalArgumentErrorA parameter is out of range
EBusProtocolExceptionA protocol failure occurred. See descendants of EBusProtocolException for a more detailed failure list.
Note
Broadcast supported for serial protocols

◆ readExceptionStatus()

readExceptionStatus ( integer  slaveAddr,
byte &  statusByte 
)
inherited

Modbus function 7 (07 hex), Read Exception Status.

Reads the eight exception status coils within the slave device.

Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 1 - 255)
statusByteSlave status byte. The meaning of this status byte is slave specific and varies from device to device.
Exceptions
EIllegalStateErrorPort or connection is closed
EInOutErrorAn I/O error occurred
EIllegalArgumentErrorA parameter is out of range
EBusProtocolExceptionA protocol failure occurred. See descendants of EBusProtocolException for a more detailed failure list.
Note
No broadcast supported

◆ returnQueryData()

returnQueryData ( integer  slaveAddr,
byte []  queryArr,
byte []  echoArr 
)
inherited

Modbus function code 8, sub-function 00, Return Query Data.

Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 1 - 255)
queryArrData to be sent
echoArrBuffer which will contain the data read. Array must be of the same size as queryArr.
Exceptions
EIllegalStateErrorPort or connection is closed
EInOutErrorAn I/O error occurred
EIllegalArgumentErrorA parameter is out of range
EBusProtocolExceptionA protocol failure occurred. See descendants of EBusProtocolException for a more detailed failure list.
Note
No broadcast supported

◆ restartCommunicationsOption()

restartCommunicationsOption ( integer  slaveAddr,
boolean  clearEventLog 
)
inherited

Modbus function code 8, sub-function 01, Restart Communications Option.

Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 1 - 255)
clearEventLogFlag when set to one clears in addition the slave's communication even log.
Exceptions
EIllegalStateErrorPort or connection is closed
EInOutErrorAn I/O error occurred
EIllegalArgumentErrorA parameter is out of range
EBusProtocolExceptionA protocol failure occurred. See descendants of EBusProtocolException for a more detailed failure list.
Note
No broadcast supported

◆ setTimeout()

setTimeout ( const integer  timeOut)
inherited

Configures time-out.

This function sets the operation or socket time-out to the specified 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.
Note
A protocol must be closed in order to configure it.
Parameters
timeOutTimeout value in ms (Range: 1 - 100000)
Exceptions
EIllegalStateErrorProtocol is already open
EIllegalArgumentErrorA parameter is out of range

◆ getTimeout()

integer getTimeout ( )
inherited

Returns the time-out 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

◆ setPollDelay()

setPollDelay ( const integer  pollDelay)
inherited

Configures poll delay.

This function sets the delay time which applies between two consecutive Modbus read/write. A value of 0 disables the poll delay.

Remarks
The delay 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
A protocol must be closed in order to configure it.
Parameters
pollDelayDelay time in ms (Range: 0 - 100000), 0 disables poll delay
Exceptions
EIllegalStateErrorProtocol is already open
EIllegalArgumentErrorA parameter is out of range

◆ getPollDelay()

integer getPollDelay ( )
inherited

Returns the poll delay time.

Returns
Delay time in ms, 0 if poll delay is switched off

◆ setRetryCnt()

setRetryCnt ( const integer  retryCnt)
inherited

Configures the automatic retry setting.

A value of 0 disables any automatic retries.

Note
A protocol must be closed in order to configure it.
Parameters
retryCntRetry count (Range: 0 - 10), 0 disables retries
Exceptions
EIllegalStateErrorProtocol is already open
EIllegalArgumentErrorA parameter is out of range

◆ getRetryCnt()

integer getRetryCnt ( )
inherited

Returns the automatic retry count.

Returns
Retry count

◆ getTotalCounter()

cardinal getTotalCounter ( )
inherited

Returns how often a message transfer has been executed.

Returns
Counter value

◆ getSuccessCounter()

cardinal getSuccessCounter ( )
inherited

Returns how often a message transfer was successful.

Returns
Counter value

◆ configureBigEndianInts() [1/2]

configureBigEndianInts ( )
inherited

Configures int data type functions to do a word swap.

Modbus is using little-endian word order for 32-bit values. The data transfer functions operating upon 32-bit int data types can be configured to do a word swap which enables them to read 32-bit data correctly from a big-endian machine.

◆ configureBigEndianInts() [2/2]

configureBigEndianInts ( integer  slaveAddr)
inherited

Enables int data type functions to do a word swap on a per slave basis.

Modbus is using little-endian word order for 32-bit values. The data transfer functions operating upon 32-bit int data types can be configured to do a word swap which enables them to read 32-bit data correctly from a big-endian machine.

Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 1 - 255). A value of zero configures the behaviour for broadcasting.
Exceptions
EIllegalArgumentErrorA parameter is out of range

◆ configureSwappedFloats() [1/2]

configureSwappedFloats ( )
inherited

Configures float data type functions to do a word swap.

The data functions operating upon 32-bit float data types can be configured to do a word swap.

Note
Most platforms store floats in IEEE 754 little-endian order which does not need a word swap.

◆ configureSwappedFloats() [2/2]

configureSwappedFloats ( integer  slaveAddr)
inherited

Enables float data type functions to do a word swap on a per slave basis.

The data functions operating upon 32-bit float data types can be configured to do a word swap.

Note
Most platforms store floats in IEEE 754 little-endian order which does not need a word swap.
Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 1 - 255). A value of zero configures the behaviour for broadcasting.
Exceptions
EIllegalArgumentErrorA parameter is out of range

◆ configureLittleEndianInts() [1/2]

configureLittleEndianInts ( )
inherited

Configures int data type functions not to do a word swap.

This is the default.

◆ configureLittleEndianInts() [2/2]

configureLittleEndianInts ( integer  slaveAddr)
inherited

Disables word swapping for int data type functions on a per slave basis.

Modbus is using little-endian word order for 32-bit values. This setting assumes that the slave also serves 32-bit data in little little-endian word order.

Remarks
This is the default mode
Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 1 - 255). A value of zero configures the behaviour for broadcasting.
Exceptions
EIllegalArgumentErrorA parameter is out of range

◆ configureIeeeFloats() [1/2]

configureIeeeFloats ( )
inherited

Configures float data type functions not to do a word swap.

This is the default.

◆ configureIeeeFloats() [2/2]

configureIeeeFloats ( integer  slaveAddr)
inherited

Disables float data type functions to do a word swap on a per slave basis.

Modbus is using little-endian word order for 32-bit values. This setting assumes that the slave also serves 32-bit floats in little little-endian word order which is the most common case.

Remarks
This is the default mode
Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 1 - 255). A value of zero configures the behaviour for broadcasting.
Exceptions
EIllegalArgumentErrorA parameter is out of range

◆ configureStandard32BitMode() [1/2]

configureStandard32BitMode ( )
inherited

Configures all slaves for Standard 32-bit Mode.

In Standard 32-bit Register Mode a 32-bit value is transmitted as two consecutive 16-bit Modbus registers.

Remarks
This is the default mode

◆ configureStandard32BitMode() [2/2]

configureStandard32BitMode ( integer  slaveAddr)
inherited

Configures a slave for Standard 32-bit Register Mode.

In Standard 32-bit Register Mode a 32-bit value is transmitted as two consecutive 16-bit Modbus registers.

Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 1 - 255). A value of zero configures the behaviour for broadcasting.
Exceptions
EIllegalArgumentErrorA parameter is out of range

◆ configureEnron32BitMode() [1/2]

configureEnron32BitMode ( )
inherited

Configures all slaves for Daniel/ENRON 32-bit Mode.

Some Modbus flavours like the Daniel/Enron protocol represent a 32-bit value using one 32-bit Modbus register instead of two 16-bit registers.

◆ configureEnron32BitMode() [2/2]

configureEnron32BitMode ( integer  slaveAddr)
inherited

Configures all slaves for Daniel/ENRON 32-bit Mode.

Some Modbus flavours like the Daniel/Enron protocol represent a 32-bit value using one 32-bit Modbus register instead of two 16-bit registers.

Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 1 - 255). A value of zero configures the behaviour for broadcasting.
Exceptions
EIllegalArgumentErrorA parameter is out of range

◆ configureCountFromOne() [1/2]

configureCountFromOne ( )
inherited

Configures the reference counting scheme to start with one for all slaves.

This renders the reference range to be 1 to 65536 and register #0 is an illegal register.

Remarks
This is the default mode

◆ configureCountFromOne() [2/2]

configureCountFromOne ( integer  slaveAddr)
inherited

Configures a slave's reference counting scheme to start with one.

This renders the reference range to be 1 to 65536 and register #0 is an illegal register.

Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 1 - 255). A value of zero configures the behaviour for broadcasting.
Remarks
This is the default mode
Exceptions
EIllegalArgumentErrorA parameter is out of range

◆ configureCountFromZero() [1/2]

configureCountFromZero ( )
inherited

Configures the reference counting scheme to start with zero for all slaves.

This renders the valid reference range to be 0 to 65535.

This renders the first register to be #0 for all slaves.

◆ configureCountFromZero() [2/2]

configureCountFromZero ( integer  slaveAddr)
inherited

Configures a slave's reference counting scheme to start with zero.

This is also known as PDU addressing.

This renders the valid reference range to be 0 to 65535.

Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 1 - 255). A value of zero configures the behaviour for broadcasting.
Exceptions
EIllegalArgumentErrorA parameter is out of range

◆ isOpen()

boolean isOpen ( )
inherited

Returns whether the protocol is open or not.

Return values
true= open
false= closed

◆ getPackageVersion()

class string getPackageVersion ( )
inherited

Returns the package version number.

Returns
Package version string

Member Data Documentation

◆ hostName

string hostName
inherited

Host name property (eg '127.0.0.1')

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

◆ port

word port
inherited

TCP port property (eg 502)

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

◆ timeout

integer timeout
inherited

Time-out port property.

Note
A protocol must be closed in order to configure it.
See also
getTimeout For reading
setTimeout For writing

◆ pollDelay

integer pollDelay
inherited

Poll delay property.

Delay between two Modbus read/writes in ms

Note
A protocol must be closed in order to configure it.
See also
getPollDelay For reading
setPollDelay For writing

◆ retryCnt

integer retryCnt
inherited

Retry count property.

Note
A protocol must be closed in order to configure it.
See also
getRetryCnt For reading
setRetryCnt For writing