• Libraries
  • Shop
  • Doc
  • Free Modbus
  • Support
  • Login
FieldTalk Modbus Master C++ Library  Library version 2.13.3
  • Introduction
  • Chapters
  • Modules
  • Classes
  • Class List
  • Class Hierarchy
  • Class Members
Classes | Public Member Functions | Protected Member Functions | List of all members
MbusMasterFunctions Class Referenceabstract

Base class which implements Modbus data and control functions. More...

Classes

struct  FileSubRequest
 File subrequest structure. More...
 

Public Member Functions

virtual ~MbusMasterFunctions ()
 Destructor. More...
 
virtual int isOpen ()=0
 
virtual void closeProtocol ()=0
 Closes an open protocol including any associated communication resources (com ports or sockets).
 

Protected Member Functions

 MbusMasterFunctions ()
 Constructs a MbusMasterFunctions object and initialises its data. More...
 

Bit Access

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

int readCoils (int slaveAddr, int startRef, int bitArr[], int refCnt)
 Modbus function 1, Read Coil Status/Read Coils. More...
 
int readInputDiscretes (int slaveAddr, int startRef, int bitArr[], int refCnt)
 Modbus function 2, Read Inputs Status/Read Input Discretes. More...
 
int writeCoil (int slaveAddr, int bitAddr, int bitVal)
 Modbus function 5, Force Single Coil/Write Coil. More...
 
int forceMultipleCoils (int slaveAddr, int startRef, const int bitArr[], int refCnt)
 Modbus function 15 (0F Hex), Force Multiple Coils. More...
 

16-bit Access

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

int readMultipleRegisters (int slaveAddr, int startRef, short regArr[], int refCnt)
 Modbus function 3, Read Holding Registers/Read Multiple Registers. More...
 
int readInputRegisters (int slaveAddr, int startRef, short regArr[], int refCnt)
 Modbus function 4, Read Input Registers. More...
 
int writeSingleRegister (int slaveAddr, int regAddr, short regVal)
 Modbus function 6, Preset Single Register/Write Single Register. More...
 
int writeMultipleRegisters (int slaveAddr, int startRef, const short regArr[], int refCnt)
 Modbus function 16 (10 Hex), Preset Multiple Registers/Write Multiple Registers. More...
 
int maskWriteRegister (int slaveAddr, int regAddr, short andMask, short orMask)
 Modbus function 22 (16 Hex), Mask Write Register. More...
 
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. More...
 

32-bit Access

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

int readMultipleLongInts (int slaveAddr, int startRef, int int32Arr[], int refCnt)
 Modbus function 3 for 32-bit long int data types, Read Holding Registers/Read Multiple Registers as long int data. More...
 
int readInputLongInts (int slaveAddr, int startRef, int int32Arr[], int refCnt)
 Modbus function 4 for 32-bit long int data types, Read Input Registers as long int data. More...
 
int writeMultipleLongInts (int slaveAddr, int startRef, const int 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. More...
 
int readMultipleFloats (int slaveAddr, int startRef, float float32Arr[], int refCnt)
 Modbus function 3 for 32-bit float data types, Read Holding Registers/Read Multiple Registers as float data. More...
 
int readInputFloats (int slaveAddr, int startRef, float float32Arr[], int refCnt)
 Modbus function 4 for 32-bit float data types, Read Input Registers as float data. More...
 
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. More...
 
int readMultipleMod10000 (int slaveAddr, int startRef, int int32Arr[], int refCnt)
 Modbus function 3 for 32-bit modulo-10000 long int data types, Read Holding Registers/Read Multiple Registers as modulo-10000 long int data. More...
 
int readInputMod10000 (int slaveAddr, int startRef, int int32Arr[], int refCnt)
 Modbus function 4 for 32-bit modulo-10000 long int data types, Read Input Registers as modulo-10000 long int data. More...
 
int writeMultipleMod10000 (int slaveAddr, int startRef, const int 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. More...
 

64-bit Access

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

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

File Record Access

int readFileRecord (int slaveAddr, int refType, int fileNo, int recordNo, short recordArr[], int recordCnt)
 Modbus function 20, Read File Record. More...
 
int readFileRecord (int slaveAddr, FileSubRequest subReqArr[], int subReqCnt)
 Modbus function 20, Read File Record. More...
 
int writeFileRecord (int slaveAddr, int refType, int fileNo, int recordNo, const short recordArr[], int recordCnt)
 Modbus function 21, Write File Record. More...
 
int writeFileRecord (int slaveAddr, const FileSubRequest subReqArr[], int subReqCnt)
 Modbus function 21, Write File Record. More...
 

Diagnostics

int readExceptionStatus (int slaveAddr, unsigned char *statusBytePtr)
 Modbus function 7, Read Exception Status. More...
 
int returnQueryData (int slaveAddr, const unsigned char queryArr[], unsigned char echoArr[], int len)
 Modbus function code 8, sub-function 00, Return Query Data. More...
 
int restartCommunicationsOption (int slaveAddr, int clearEventLog)
 Modbus function code 8, sub-function 01, Restart Communications Option. More...
 
int readDeviceIdentification (int slaveAddr, int accessType, int objId, DeviceIdObjectList *objListPtr)
 Modbus function 43 (hex 2B) subfunction 14 (hex 0E), Read Device Identification. More...
 

Custom Function Codes

int customFunction (int slaveAddr, int functionCode, void *requestData, size_t requestLen, void *responseData, size_t *responseLenPtr)
 User Defined Function CodeThis method can be used to implement User Defined Function Codes. More...
 

Protocol Configuration

int setTimeout (int timeOut)
 Configures time-out. More...
 
int getTimeout ()
 Returns the time-out value. More...
 
int setPollDelay (int pollDelay)
 Configures poll delay. More...
 
int getPollDelay ()
 Returns the poll delay time. More...
 
int setRetryCnt (int retryCnt)
 Configures the automatic retry setting. More...
 
int getRetryCnt ()
 Returns the automatic retry count. More...
 

Transmission Statistic Functions

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

Slave Configuration

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

Utility Functions

static const TCHAR * getPackageVersion ()
 Returns the library version number. More...
 

Detailed Description

Base class which implements Modbus data and control functions.

The functions provided by this base class apply to all protocol flavours via inheritance. For a more detailed description see section Data and Control Functions for all Modbus Protocol Flavours.

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

Constructor & Destructor Documentation

◆ MbusMasterFunctions()

MbusMasterFunctions ( )
protected

Constructs a MbusMasterFunctions object and initialises its data.

It also detects the endianess of the machine it's running on and configures byte swapping if necessary.

◆ ~MbusMasterFunctions()

~MbusMasterFunctions ( )
virtual

Destructor.

Does clean-up and closes an open protocol including any associated communication resources (serial ports or sockets).

Member Function Documentation

◆ readCoils()

int readCoils ( int  slaveAddr,
int  startRef,
int  bitArr[],
int  refCnt 
)

Modbus function 1, 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
refCntNumber of coils to be read (Range: 1-2000)
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error codes.
Note
No broadcast supported

◆ readInputDiscretes()

int readInputDiscretes ( int  slaveAddr,
int  startRef,
int  bitArr[],
int  refCnt 
)

Modbus function 2, 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
refCntNumber of coils to be read (Range: 1-2000)
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error codes.
Note
No broadcast supported

◆ writeCoil()

int writeCoil ( int  slaveAddr,
int  bitAddr,
int  bitVal 
)

Modbus function 5, 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
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error codes.
Note
Broadcast supported for serial protocols

References FTALK_ILLEGAL_ARGUMENT_ERROR, FTALK_INVALID_REPLY_ERROR, and FTALK_SUCCESS.

◆ forceMultipleCoils()

int forceMultipleCoils ( int  slaveAddr,
int  startRef,
const int  bitArr[],
int  refCnt 
)

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: 0 - 255)
startRefStart reference (Range: 1 - 65536)
bitArrBuffer which contains the data to be sent
refCntNumber of coils to be written (Range: 1-1968)
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error codes.
Note
Broadcast supported for serial protocols

References FTALK_ILLEGAL_ARGUMENT_ERROR, FTALK_INVALID_REPLY_ERROR, and FTALK_SUCCESS.

◆ readMultipleRegisters()

int readMultipleRegisters ( int  slaveAddr,
int  startRef,
short  regArr[],
int  refCnt 
)

Modbus function 3, 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
refCntNumber of registers to be read (Range: 1-125)
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error codes.
Note
No broadcast supported

◆ readInputRegisters()

int readInputRegisters ( int  slaveAddr,
int  startRef,
short  regArr[],
int  refCnt 
)

Modbus function 4, 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.
refCntNumber of registers to be read (Range: 1-125)
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error codes.
Note
No broadcast supported

◆ writeSingleRegister()

int writeSingleRegister ( int  slaveAddr,
int  regAddr,
short  regVal 
)

Modbus function 6, 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
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error codes.
Note
Broadcast supported for serial protocols

References FTALK_ILLEGAL_ARGUMENT_ERROR, FTALK_INVALID_REPLY_ERROR, and FTALK_SUCCESS.

◆ writeMultipleRegisters()

int writeMultipleRegisters ( int  slaveAddr,
int  startRef,
const short  regArr[],
int  refCnt 
)

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.
refCntNumber of registers to be written (Range: 1-123)
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error codes.
Note
Broadcast supported for serial protocols

◆ maskWriteRegister()

int maskWriteRegister ( int  slaveAddr,
int  regAddr,
short  andMask,
short  orMask 
)

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 for serial, 0 - 255 for TCP)
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

References FTALK_ILLEGAL_ARGUMENT_ERROR, FTALK_INVALID_REPLY_ERROR, and FTALK_SUCCESS.

◆ readWriteRegisters()

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.

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 for serial, 0 - 255 for TCP)
readRefStart register for reading (Range: 1 - 65536)
readArrBuffer which will contain the data read
readCntNumber of registers to be read (Range: 1-125)
writeRefStart register for writing (Range: 1 - 65536)
writeArrBuffer with data to be sent
writeCntNumber of registers to be written (Range: 1-121)
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error codes.
Note
No broadcast supported

References FTALK_ILLEGAL_ARGUMENT_ERROR, FTALK_INVALID_REPLY_ERROR, and FTALK_SUCCESS.

◆ readMultipleLongInts()

int readMultipleLongInts ( int  slaveAddr,
int  startRef,
int  int32Arr[],
int  refCnt 
)

Modbus function 3 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
Depending on the 32-bit Mode setting, an int will be transferred as two consecutive 16-bit registers (Standard) or as one 32-bit register (Daniel/Enron).
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
refCntNumber of values to be read (Range: 1-62)
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error codes.
Note
No broadcast supported

◆ readInputLongInts()

int readInputLongInts ( int  slaveAddr,
int  startRef,
int  int32Arr[],
int  refCnt 
)

Modbus function 4 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
Depending on the 32-bit Mode setting, an int will be transferred as two consecutive 16-bit registers (Standard) or as one 32-bit register (Daniel/Enron).
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
refCntNumber of values to be read (Range: 1-62)
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error codes.
Note
No broadcast supported

◆ writeMultipleLongInts()

int writeMultipleLongInts ( int  slaveAddr,
int  startRef,
const int  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.

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

Remarks
Depending on the 32-bit Mode setting, an int will be transferred as two consecutive 16-bit registers (Standard) or as one 32-bit register (Daniel/Enron).
Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 0 - 255)
startRefStart reference (Range: 1 - 65536)
int32ArrBuffer with the data to be sent
refCntNumber of values to be sent (Range: 1-61)
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error codes.
Note
Broadcast supported for serial protocols

References FTALK_ILLEGAL_ARGUMENT_ERROR.

◆ readMultipleFloats()

int readMultipleFloats ( int  slaveAddr,
int  startRef,
float  float32Arr[],
int  refCnt 
)

Modbus function 3 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
Depending on the 32-bit Mode setting, an int will be transferred as two consecutive 16-bit registers (Standard) or as one 32-bit register (Daniel/Enron).
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
refCntNumber of values to be read (Range: 1-62)
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error codes.
Note
No broadcast supported

◆ readInputFloats()

int readInputFloats ( int  slaveAddr,
int  startRef,
float  float32Arr[],
int  refCnt 
)

Modbus function 4 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
Depending on the 32-bit Mode setting, an int will be transferred as two consecutive 16-bit registers (Standard) or as one 32-bit register (Daniel/Enron).
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
refCntNumber of values to be read (Range: 1-62)
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error codes.
Note
No broadcast supported

◆ writeMultipleFloats()

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.

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

Remarks
Depending on the 32-bit Mode setting, an int will be transferred as two consecutive 16-bit registers (Standard) or as one 32-bit register (Daniel/Enron).
Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 0 - 255)
startRefStart reference (Range: 1 - 65536)
float32ArrBuffer with the data to be sent
refCntNumber of values to be sent (Range: 1-61)
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error codes.
Note
Broadcast supported for serial protocols

References FTALK_ILLEGAL_ARGUMENT_ERROR.

◆ readMultipleMod10000()

int readMultipleMod10000 ( int  slaveAddr,
int  startRef,
int  int32Arr[],
int  refCnt 
)

Modbus function 3 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
Depending on the 32-bit Mode setting, an int will be transferred as two consecutive 16-bit registers (Standard) or as one 32-bit register (Daniel/Enron).
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
refCntNumber of M10K integers to be read (Range: 1-62)
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error codes.
Note
No broadcast supported

◆ readInputMod10000()

int readInputMod10000 ( int  slaveAddr,
int  startRef,
int  int32Arr[],
int  refCnt 
)

Modbus function 4 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
Depending on the 32-bit Mode setting, an int will be transferred as two consecutive 16-bit registers (Standard) or as one 32-bit register (Daniel/Enron).
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
refCntNumber of M10K integers to be read (Range: 1-62)
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error codes.
Note
No broadcast supported

◆ writeMultipleMod10000()

int writeMultipleMod10000 ( int  slaveAddr,
int  startRef,
const int  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.

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
Depending on the 32-bit Mode setting, an int will be transferred as two consecutive 16-bit registers (Standard) or as one 32-bit register (Daniel/Enron).
Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 0 - 255)
startRefStart reference (Range: 1 - 65536)
int32ArrBuffer with the data to be sent
refCntNumber of values values to be sent (Range: 1-61)
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error codes.
Note
Broadcast supported for serial protocols

References FTALK_ILLEGAL_ARGUMENT_ERROR.

◆ readHoldingRegistersI64()

int readHoldingRegistersI64 ( int  slaveAddr,
int  startRef,
int64_t  int64Arr[],
int  refCnt 
)

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
refCntNumber of values to be read (Range: 1-31)
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error codes.
Note
No broadcast supported

◆ readInputRegistersI64()

int readInputRegistersI64 ( int  slaveAddr,
int  startRef,
int64_t  int64Arr[],
int  refCnt 
)

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
refCntNumber of values to be read (Range: 1-31)
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error codes.
Note
No broadcast supported

◆ writeMultipleRegistersI64()

int writeMultipleRegistersI64 ( int  slaveAddr,
int  startRef,
const int64_t  int64Arr[],
int  refCnt 
)

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
refCntNumber of values to be sent (Range: 1-30)
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error codes.
Note
Broadcast supported for serial protocols

References FTALK_ILLEGAL_ARGUMENT_ERROR.

◆ readHoldingRegistersF64()

int readHoldingRegistersF64 ( int  slaveAddr,
int  startRef,
double  double64Arr[],
int  refCnt 
)

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
refCntNumber of values to be read (Range: 1-31)
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error codes.
Note
No broadcast supported

◆ readInputRegistersF64()

int readInputRegistersF64 ( int  slaveAddr,
int  startRef,
double  double64Arr[],
int  refCnt 
)

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)
double64ArrBuffer which will be filled with the data read
refCntNumber of values to be read (Range: 1-31)
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error codes.
Note
No broadcast supported

◆ writeMultipleRegistersF64()

int writeMultipleRegistersF64 ( int  slaveAddr,
int  startRef,
const double  double64Arr[],
int  refCnt 
)

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
refCntNumber of values to be sent (Range: 1-30)
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error codes.
Note
Broadcast supported for serial protocols

References FTALK_ILLEGAL_ARGUMENT_ERROR.

◆ readFileRecord() [1/2]

int readFileRecord ( int  slaveAddr,
int  refType,
int  fileNo,
int  recordNo,
short  recordArr[],
int  recordCnt 
)

Modbus function 20, Read File Record.

Performs a file record read for a single subrequest.

Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 1 - 255)
refTypeReference type (Must be specified as 6).
fileNoFile number (Range 1-65535). 3 is the input registers file, 4 is the holding registers file.
recordNoRecord Number (Range: 0 - 65535). The first record to read from, 0-based numbering.
recordArrBuffer which will be filled with the data read
recordCntNumber of records to read (Range 1-125)
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error codes.
Note
No broadcast supported

◆ readFileRecord() [2/2]

int readFileRecord ( int  slaveAddr,
FileSubRequest  subReqArr[],
int  subReqCnt 
)

Modbus function 20, Read File Record.

Performs a file record read for a list of subrequests.

Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 1 - 255)
subReqArrArray with list of subrequests
subReqCntNumber of subrequests to read (Range 1-35)
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error codes.
Note
No broadcast supported

References FTALK_ILLEGAL_ARGUMENT_ERROR, FTALK_INVALID_REPLY_ERROR, FTALK_SUCCESS, and MbusMasterFunctions::FileSubRequest::recordCnt.

◆ writeFileRecord() [1/2]

int writeFileRecord ( int  slaveAddr,
int  refType,
int  fileNo,
int  recordNo,
const short  recordArr[],
int  recordCnt 
)

Modbus function 21, Write File Record.

Performs a file record write for a single subrequest.

Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 1 - 255)
refTypeReference type (Must be specified as 6).
fileNoFile number (Range 1-65535). 3 is the input registers file, 4 is the holding registers file.
recordNoRecord Number (Range: 0 - 65535). The first record to write to, 0-based numbering.
recordArrBuffer with the data to be sent.
recordCntNumber of records to write (Range 1-122)
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error codes.
Note
No broadcast supported

◆ writeFileRecord() [2/2]

int writeFileRecord ( int  slaveAddr,
const FileSubRequest  subReqArr[],
int  subReqCnt 
)

Modbus function 21, Write File Record.

Performs a file record write for a list of subrequests.

Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 1 - 255)
subReqArrArray with list of subrequests
subReqCntNumber of subrequests to write (Range 1-27)
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error codes.
Note
No broadcast supported

References FTALK_ILLEGAL_ARGUMENT_ERROR, FTALK_INVALID_REPLY_ERROR, FTALK_SUCCESS, and MbusMasterFunctions::FileSubRequest::recordCnt.

◆ readExceptionStatus()

int readExceptionStatus ( int  slaveAddr,
unsigned char *  statusBytePtr 
)

Modbus function 7, 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 for serial, 0 - 255 for TCP)
statusBytePtrSlave status byte. The meaning of this status byte is slave specific and varies from device to device.
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error codes.
Note
No broadcast supported

References FTALK_ILLEGAL_ARGUMENT_ERROR, and FTALK_SUCCESS.

◆ returnQueryData()

int returnQueryData ( int  slaveAddr,
const unsigned char  queryArr[],
unsigned char  echoArr[],
int  len 
)

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

Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 1 - 255 for serial, 0 - 255 for TCP)
queryArrBuffer with data to be sent
echoArrBuffer which will contain the data read
lenNumber of bytes send sent and read back
Returns
FTALK_SUCCESS on success, FTALK_INVALID_REPLY_ERROR if reply does not match query data or error code. See Error Management for a list of error codes.
Note
No broadcast supported

References FTALK_ILLEGAL_ARGUMENT_ERROR, FTALK_INVALID_REPLY_ERROR, and FTALK_SUCCESS.

◆ restartCommunicationsOption()

int restartCommunicationsOption ( int  slaveAddr,
int  clearEventLog 
)

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

Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 1 - 255 for serial, 0 - 255 for TCP)
clearEventLogFlag when set to one clears in addition the slave's communication even log.
Returns
FTALK_SUCCESS on success. See Error Management for a list of error codes.
Note
No broadcast supported

References FTALK_ILLEGAL_ARGUMENT_ERROR.

◆ readDeviceIdentification()

int readDeviceIdentification ( int  slaveAddr,
int  accessType,
int  objId,
DeviceIdObjectList *  objListPtr 
)

Modbus function 43 (hex 2B) subfunction 14 (hex 0E), Read Device Identification.

This function allows a master to retrieve various objects with meta information about a slave device. The data type of the objects returned is a 0-terminated ASCII string.

Object IdObject Name / Description
0x00VendorName
0x01ProductCode
0x02MajorMinorRevision
0x03VendorUrl
0x04ProductName
0x05ModelName
0x06UserApplicationName
0x07 - 0x7FReserved
0x80 - 0xFFVendor specific private objects
Parameters
slaveAddrModbus address of slave device or unit identifier (Range: 1 - 255 for serial, 0 - 255 for TCP)
accessTypeCategory type (1=only mandatory basic objects, 2=all regular objects, 3=include vendor specfic objects, 4=single object)
objIdAn object ID from above table
objListPtrA pointer to a object list container which will receive the retrieved objects.
Returns
FTALK_SUCCESS on success. See Error Management for a list of error codes.
Note
No broadcast supported

Example retrieving all Device ID strings of basic device identification level (level 1):

DeviceIdObjectList objs;
int objId = 0; // Start with object 0
do
{
result = mbusProtocol.readDeviceIdentification(1, 1, objId, &objs);
if (result != FTALK_SUCCESS)
{
fprintf(stderr, "Error: %s!\n", getBusProtocolErrorText(result));
exit(EXIT_FAILURE);
}
else
{
size_t objLen;
char* objData;
while (objs.getNext(&objId, &objData, &objLen))
{
printf("obj[%d] = '%s', len = %u\n", objId, objData, objLen);
}
}
}
while (objs.moreToFollow());

References FTALK_ILLEGAL_ARGUMENT_ERROR, FTALK_INVALID_FRAME_ERROR, FTALK_INVALID_REPLY_ERROR, and FTALK_SUCCESS.

◆ setTimeout()

int setTimeout ( int  msTime)

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
msTimeTimeout value in ms (Range: 1 - 100000)
Return values
FTALK_SUCCESSSuccess
FTALK_ILLEGAL_ARGUMENT_ERRORArgument out of range
FTALK_ILLEGAL_STATE_ERRORProtocol is already open

References FTALK_ILLEGAL_ARGUMENT_ERROR, FTALK_ILLEGAL_STATE_ERROR, FTALK_SUCCESS, and isOpen().

◆ getTimeout()

int getTimeout ( )
inline

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()

int setPollDelay ( int  msTime)

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
msTimeDelay time in ms (Range: 0 - 100000), 0 disables poll delay
Return values
FTALK_SUCCESSSuccess
FTALK_ILLEGAL_ARGUMENT_ERRORArgument out of range
FTALK_ILLEGAL_STATE_ERRORProtocol is already open

References FTALK_ILLEGAL_ARGUMENT_ERROR, FTALK_ILLEGAL_STATE_ERROR, FTALK_SUCCESS, and isOpen().

◆ getPollDelay()

int getPollDelay ( )
inline

Returns the poll delay time.

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

◆ setRetryCnt()

int setRetryCnt ( int  retries)

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
retriesRetry count (Range: 0 - 10), 0 disables retries
Return values
FTALK_SUCCESSSuccess
FTALK_ILLEGAL_ARGUMENT_ERRORArgument out of range
FTALK_ILLEGAL_STATE_ERRORProtocol is already open

References FTALK_ILLEGAL_ARGUMENT_ERROR, FTALK_ILLEGAL_STATE_ERROR, FTALK_SUCCESS, and isOpen().

◆ getRetryCnt()

int getRetryCnt ( )
inline

Returns the automatic retry count.

Returns
Retry count

◆ getTotalCounter()

long getTotalCounter ( )
inline

Returns how often a message transfer has been executed.

Returns
Counter value

◆ getSuccessCounter()

long getSuccessCounter ( )
inline

Returns how often a message transfer was successful.

Returns
Counter value

◆ configureBigEndianInts() [1/2]

void configureBigEndianInts ( )

Configures 32-bit 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 slave.

◆ configureLittleEndianInts() [1/2]

void configureLittleEndianInts ( )

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

This is the default.

◆ configureIeeeFloats() [1/2]

void configureIeeeFloats ( )

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

This is the default.

◆ configureSwappedFloats() [1/2]

void configureSwappedFloats ( )

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.

◆ configureStandard32BitMode() [1/2]

void configureStandard32BitMode ( )

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.

Note
This function call also re-configures the endianess to default little-endian for 32-bit values!
Remarks
This is the default mode

◆ configureEnron32BitMode() [1/2]

void configureEnron32BitMode ( )

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.

Note
This function call also re-configures the endianess to big-endian for 32-bit values as defined by the Daniel/ENRON protocol!

◆ configureCountFromOne() [1/2]

void configureCountFromOne ( )

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

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

Remarks
This is the default mode

◆ configureCountFromZero() [1/2]

void configureCountFromZero ( )

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

This renders the valid reference range to be 0 to 65535 (0xFFFF).

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

◆ configureBigEndianInts() [2/2]

int configureBigEndianInts ( int  slaveAddr)

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.

References FTALK_ILLEGAL_ARGUMENT_ERROR, and FTALK_SUCCESS.

◆ configureLittleEndianInts() [2/2]

int configureLittleEndianInts ( int  slaveAddr)

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.

References FTALK_ILLEGAL_ARGUMENT_ERROR, and FTALK_SUCCESS.

◆ configureIeeeFloats() [2/2]

int configureIeeeFloats ( int  slaveAddr)

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.

References FTALK_ILLEGAL_ARGUMENT_ERROR, and FTALK_SUCCESS.

◆ configureSwappedFloats() [2/2]

int configureSwappedFloats ( int  slaveAddr)

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.

References FTALK_ILLEGAL_ARGUMENT_ERROR, and FTALK_SUCCESS.

◆ configureStandard32BitMode() [2/2]

int configureStandard32BitMode ( int  slaveAddr)

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.
Return values
FTALK_SUCCESSSuccess
FTALK_ILLEGAL_ARGUMENT_ERRORArgument out of range
Remarks
This is the default mode
Note
This function call also re-configures the endianess to default little-endian for 32-bit values!

References configureIeeeFloats(), configureLittleEndianInts(), FTALK_ILLEGAL_ARGUMENT_ERROR, and FTALK_SUCCESS.

◆ configureEnron32BitMode() [2/2]

int configureEnron32BitMode ( int  slaveAddr)

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.
Return values
FTALK_SUCCESSSuccess
FTALK_ILLEGAL_ARGUMENT_ERRORArgument out of range
Note
This function call also re-configures the endianess to big-endian for 32-bit values as defined by the Daniel/ENRON protocol!

References configureBigEndianInts(), configureSwappedFloats(), FTALK_ILLEGAL_ARGUMENT_ERROR, and FTALK_SUCCESS.

◆ configureCountFromOne() [2/2]

int configureCountFromOne ( int  slaveAddr)

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

This renders the reference range to be 1 to 65536 (0x10000) 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

References FTALK_ILLEGAL_ARGUMENT_ERROR, and FTALK_SUCCESS.

◆ configureCountFromZero() [2/2]

int configureCountFromZero ( int  slaveAddr)

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 (0xFFFF).

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

References FTALK_ILLEGAL_ARGUMENT_ERROR, and FTALK_SUCCESS.

◆ isOpen()

virtual int isOpen ( )
pure virtual
Deprecated:
Returns whether the protocol is open or not.

This simply returns the state of an internal flag whether openProtocol() has been called or not.

Note
This function does not report the state of the underlaying transport network, in particular it does not report whether the TCP connection is still in 'established' state or in fully 'closed' state.
Return values
true= open
false= closed

Implemented in MbusSerialClientBase, and MbusIpClientBase.

◆ getPackageVersion()

const TCHAR * getPackageVersion ( )
static

Returns the library version number.

Returns
Library version string
  • MbusMasterFunctions
  • FieldTalk Modbus Master C++ Library Library version 2.13.3
Speak to the Experts
Modbus Organization Member logo

We are member of the Modbus Organization, Inc.

Buy with Confidence
30-day money back guarantee All our FieldTalk web sales are backed by a 30-day Money Back Guarantee.
We Accept
Bank VISA MasterCard PayPal
Customer Info
  • Info & Contact
  • Customer Login
  • Terms of Service
  • Terms of Sale
  • Privacy Policy
© 2005-2025 proconX Pty Ltd. All rights reserved. proconX and FieldTalk are trademarks of proconX Pty Ltd.
All other trademarks and registered trademarks appearing on www.modbusdriver.com are the property of their respective owners.