FieldTalk Modbus Master C++ Library
FieldTalk Modbus Master C++ Library
Contents
1 Introduction 1
1.1 Library Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
6 Design Background 19
7 Module Documentation 20
7.1 Data and Control Functions for all Modbus Protocol Flavours . . . . . . . . 20
7.2 Serial Protocols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
7.2.1 Detailed Description . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
i
FieldTalk Modbus Master C++ Library: Software manual
ii
Contents
9 License 237
10 Support 240
11 Notices 241
iii
Introduction
1 Introduction
The FieldTalk™ Modbus® Master C++ Library provides connectivity to Modbus slave com-
patible devices and applications.
Industrial PC
C/C++
Control Software
Soft
PLC RTU
FieldTalk Library PLC
Typical applications are Modbus based Supervisory Control and Data Acquisition Systems
(SCADA), Modbus data concentrators, Modbus gateways, User Interfaces and Factory
Information Systems (FIS).
Features:
• Full implementation of Bit Access and 16 Bits Access Function Codes as well as a subset
of the most commonly used Diagnostics Function Codes
• Standard Modbus bit and 16-bit integer data types (coils, discretes & registers)
• Support for 32-bit integer, modulo-10000 and float data types, including Daniel/Enron
protocol extensions
• Support of Broadcasting
1
FieldTalk Modbus Master C++ Library: Software manual
MbusMasterFunctions
MbusSerialClientBase MbusIpClientBase
The base class MbusMasterFunctions contains all protocol unspecific functions, in partic-
ular the data and control functions defined by Modbus. All Modbus protocol flavours
inherit from this base class.
The class MbusAsciiMasterProtocol implements the Modbus ASCII protocol, the
class MbusRtuMasterProtocol implements the Modbus RTU protocol. The class
MbusTcpMasterProtocol implements the MODBUS/TCP protocol and the class MbusRtuOverTcpMaster
the Encapsulated Modbus RTU master protocol (also known as RTU over TCP or RTU/IP).
In order to use one of the four Modbus protocols, the desired Modbus protocol flavour
class has to be instantiated:
MbusRtuMasterProtocol mbusProtocol;
After a protocol object has been declared and opened, data and control functions can be
used:
2
What You should know about Modbus
Note
To utilise the multi-drop feature of Modbus, you need a multi-point network like
RS-485. In order to access a RS-485 network, you will need a protocol converter
which automatically switches between sending and transmitting operation. How-
ever some industrial hardware platforms have an embedded RS-485 line driver and
support enabling and disabling of the RS-485 transmitter via the RTS signal. Field←-
Talk supports this RTS driven RS-485 mode.
3
FieldTalk Modbus Master C++ Library: Software manual
4
What You should know about Modbus
The Modbus protocol defines these areas very loose. The distinction between inputs
and outputs and bit-addressable and register-addressable data items does not imply any
slave specific behaviour. It is very common that slave devices implement all tables as
overlapping memory area.
For each of those tables, the protocol allows a maximum of 65536 data items to be
accessed. It is slave dependant, which data items are accessible by a master. Typically a
slave implements only a small memory area, for example of 1024 bytes, to be accessed.
5
FieldTalk Modbus Master C++ Library: Software manual
• Reading and Writing 32-bit integers using Daniel/Enron single register transfers
• Reading and Writing 32-bit floats using Daniel/Enron single register transfers
Modbus registers are numbered starting from 1. This is different to the conventional
programming logic where the first reference is addressed by 0.
Modbus discretes are numbered starting from 1 which addresses the most significant bit
in a 16-bit word. This is very different to the conventional programming logic where the
first reference is addressed by 0 and the least significant bit is bit 0.
The following table shows the correlation between Discrete Numbers and Bit Numbers:
When exchanging register number and discrete number parameters with FieldTalk func-
tions and methdos you have to use the Modbus register and discrete numbering scheme.
(Internally the functions will deduct 1 from the start register value before transmitting
the value to the slave device.)
6
What You should know about Modbus
7
FieldTalk Modbus Master C++ Library: Software manual
# unzip FT-MBMP-WIN-ALL.2.8.0.zip
The archive will create the following directory structure in your project directory:
myprj
|
+-+ fieldtalk
|
+-- doc
+-- include
+-- lib
+-- src
+-- samples
+-- Visual Studio
3.2 Linux, UNIX and QNX Platforms: Unpacking and Compiling the
Source
1. Download and save the zipped tarball into your project directory.
2. Uncompress the zipped tarball using gzip:
# gunzip FT-MBMP-??-ALL.2.8.0.tar.gz
# tar xf FT-MBMP-??-ALL.2.8.0.tar
8
Installation and Source Code Compilation
The tarball will create the following directory structure in your project directory:
myprj
|
+-+ fieldtalk
|
+-- doc
+-- include
+-- src
+-- samples
4. Compile the library from the source code. Enter the FieldTalk src directory and run
make:
# cd fieldtalk/src
# make
Note: Previous versions used a shell script to build, this version now uses the make utility
to build.
The make file tries to detect your host platform and executes the compiler and linker com-
mands targeting the host platform. The compiler and linker configurations are contained
in the platform make files in the makefiles folder.
To cross-compile, pass the basename of the cross-compilation make file as parameter:
# make arm-linux
# make qnx6-ppcle
The cross compilation make files can be found in the makefiles directory and you can add
more by copying and editing the supplied files to match your toolchain setting.
5. The library will be compiled into one of the following platform specfic sub-directories:
myprj
|
+-+ fieldtalk
|
+-- doc
+-- src
+-- include
+-- samples
+-+ lib
9
FieldTalk Modbus Master C++ Library: Software manual
|
+-- {platform} (exact name depends on platform)
3.3.2 VxWorks
There is no make file or script supplied for VxWorks because VxWorks applications and
libraries are best compiled from the Tornado IDE.
To compile and link your applications against the FieldTalk library, add all the ∗.c and
∗.cpp files supplied in the src, src/hmlib/common, src/hmlib/posix4 and src/hmlib/vxworks
to your project.
10
Linking your Applications against the Library
myprj
|
+-- myapp.cpp
+-+ fieldtalk
+-- include
+-+ lib
|
+-+ win
|
+-+ Win32
|
+-- Release
cl -I fieldtalk/include -c myapp.cpp
Add the file name of the library to the dependency list passed to the linker. Make sure
the library chosen matches your CPU architecture (32-bit vs 64-bit). Use the Win32 library
11
FieldTalk Modbus Master C++ Library: Software manual
for 32-bit code and the x64 library for 64-bit code. Within Visual Studio you can use the
macro to automatically select the correct library architecture. You also must pass the
Winsock2 standard library Ws2_32.lib as additional dependency to the linker.
Visual Studio Example:
4.2 Linux, UNIX and QNX Platforms: Compiling and Linking Appli-
cations
Let's assume the following project directory structure:
myprj
|
+-- myapp.cpp
+-+ fieldtalk
|
+-- include
+-+ lib
|
+-- linux (exact name depends on your platform)
12
Linking your Applications against the Library
Add the file name of the library to the file list passed to the linker.
Example:
13
FieldTalk Modbus Master C++ Library: Software manual
#include "MbusRtuMasterProtocol.hpp"
short readRegSet[20];
short writeRegSet[20];
int readBitSet[20];
int writeBitSet[20];
float readFloatSet[10];
float writeFloatSet[10];
Note that because a float occupies two 16-bit registers the array size is half the size it
would be for 16-bit shorts!
If you are using 32-bit ints instead of 16-bit shorts define:
long readLongSet[10];
long writeLongSet[10];
Note that because a long occupies two 16-bit registers the array size is half the size it
would be for 16-bit shorts!
3. Declare and instantiate a protocol object
MbusRtuMasterProtocol mbusProtocol;
int result;
result = mbusProtocol.openProtocol(portName,
19200L, // Baudrate
8, // Databits
1, // Stopbits
14
How to integrate the Protocol in your Application
mbusProtocol.closeProtocol();
7. Error Handling
Serial protocol errors like slave device failures, transmission failures, checksum errors and
time-outs return an error code. The following code snippet can handle and report these
errors:
15
FieldTalk Modbus Master C++ Library: Software manual
int result;
#include "MbusTcpMasterProtocol.hpp"
short readRegSet[20];
short writeRegSet[20];
int readBitSet[10];
int writeBitSet[10];
float readFloatSet[10];
float writeFloatSet[10];
Note that because a float occupies two 16-bit registers the array size is half the size it
would be for 16-bit shorts!
If you are using 32-bit ints instead of 16-bit shorts define:
long readLongSet[10];
long writeLongSet[10];
Note that because a long occupies two 16-bit registers the array size is half the size it
would be for 16-bit shorts!
3. Declare and instantiate a protocol object
MbusTcpMasterProtocol mbusProtocol;
16
How to integrate the Protocol in your Application
mbusProtocol.openProtocol("10.0.0.11");
mbusProtocol.closeProtocol();
7. Error Handling
TCP/IP protocol errors like slave failures, TCP/IP connection failures and time-outs return
an error code. The following code snippet can handle these errors:
17
FieldTalk Modbus Master C++ Library: Software manual
int result;
18
Design Background
6 Design Background
FieldTalk is based on a programming language neutral but object oriented design model.
This design approach enables us to offer the protocol stack for the languages C++, C#,
Visual Basic .NET, Java and Object Pascal while maintaining similar functionality.
The C++ editions of the protocol stack have also been designed to support multiple
operating system and compiler platforms, including real-time operating systems. In order
to support this multi-platform approach, the C++ editions are built around a lightweight
OS abstraction layer called HMLIB.
During the course of implementation, the usability in automation, control and other in-
dustrial environments was always kept in mind.
19
FieldTalk Modbus Master C++ Library: Software manual
7 Module Documentation
7.1 Data and Control Functions for all Modbus Protocol Flavours
This Modbus protocol library implements the most commonly used data functions as well
as some control functions. The functions to perform PLC program download and other
device specific functions are outside the scope of this library.
All Bit Access and 16 Bits Access Modbus Function Codes have been implemented. In
addition the most frequently used Diagnostics Function Codes have been implemented.
This rich function set enables a user to solve nearly every Modbus data transfer problem.
The following table lists the supported Modbus function codes:
Remarks
When passing register numbers and discrete numbers to FieldTalk library functions
you have to use the the Modbus register and discrete numbering scheme. See
Register and Discrete Numbering Scheme. (Internally the functions will deduct 1
from the start register value before transmitting the value to the slave device.)
20
Module Documentation
21
FieldTalk Modbus Master C++ Library: Software manual
Functions
• const TCHAR ∗ getBusProtocolErrorText (int errCode)
Translates a numeric error code into a description string.
22
Module Documentation
• #define FTALK_IO_ERROR_CLASS 64
I/O error class.
• #define FTALK_IO_ERROR 65
I/O error.
• #define FTALK_OPEN_ERR 66
Port or socket open error.
• #define FTALK_PORT_ALREADY_OPEN 67
Serial port already open.
• #define FTALK_TCPIP_CONNECT_ERR 68
TCP/IP connection error.
• #define FTALK_CONNECTION_WAS_CLOSED 69
Remote peer closed TCP/IP connection.
• #define FTALK_SOCKET_LIB_ERROR 70
Socket library error.
• #define FTALK_PORT_ALREADY_BOUND 71
TCP port already bound.
• #define FTALK_LISTEN_FAILED 72
Listen failed.
• #define FTALK_FILEDES_EXCEEDED 73
File descriptors exceeded.
• #define FTALK_PORT_NO_ACCESS 74
No permission to access serial port or TCP port.
• #define FTALK_PORT_NOT_AVAIL 75
TCP port not available.
• #define FTALK_LINE_BUSY_ERROR 76
Serial line busy.
Communication Errors
Errors of this class indicate either communication faults or Modbus exceptions reported
by the slave device.
23
FieldTalk Modbus Master C++ Library: Software manual
24
Module Documentation
25
FieldTalk Modbus Master C++ Library: Software manual
26
Module Documentation
27
FieldTalk Modbus Master C++ Library: Software manual
28
Module Documentation
Signals that a Gateway Path Unavailable exception response (code 0A) was received. This
exception is typically sent by gateways if the gateway was unable to establish a connec-
tion with the target device.
Parameters
errCode FieldTalk error code
Returns
Error text string
29
FieldTalk Modbus Master C++ Library: Software manual
Note
Modbus functions usually have an implied response length and therefore the num-
ber of bytes expected to be received is known at the time when sending the request.
In case of a custom Modbus function with an open or unknown response length,
this function can not be used.
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255
for serial, 0 - 255 for TCP)
functionCode Custom function code to be used for Modbus transaction (1-127)
requestData Pointer to data sent as request (not including slave address or
function code)
requestLen Length of request data structure (0-252)
responseData Pointer to data structure which holds response data
responseLenPtr Length of response data (0-252). The number of bytes expected to
be sent as response must be known when submitting the request.
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error
codes.
30
Module Documentation
References FTALK_ILLEGAL_ARGUMENT_ERROR.
Parameters
commandSz Buffer which holds command string. Must not be longer than 255
characters.
responseSz Buffer which holds response string. Must be a buffer of 256 bytes. A
possible trailing CR is removed.
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error
codes.
Note
No broadcast supported
31
FieldTalk Modbus Master C++ Library: Software manual
Public Types
• MbusRtuMasterProtocol ()
Constructs a MbusRtuMasterProtocol object and initialises its data.
• virtual int openProtocol (const char ∗const portName, long baudRate, int dataBits, int
stopBits, int parity)
Opens a Modbus RTU protocol and the associated serial port with specific port parameters.
• virtual void closeProtocol ()
Closes an open protocol including any associated communication resources (com ports or
sockets).
• virtual int isOpen ()
Returns whether the protocol is open or not.
• virtual int enableRs485Mode (int rtsDelay)
Enables RS485 mode.
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.
• int readInputDiscretes (int slaveAddr, int startRef, int bitArr[ ], int refCnt)
Modbus function 2, Read Inputs Status/Read Input Discretes.
• int writeCoil (int slaveAddr, int bitAddr, int bitVal)
Modbus function 5, Force Single Coil/Write Coil.
• int forceMultipleCoils (int slaveAddr, int startRef, const int bitArr[ ], int refCnt)
Modbus function 15 (0F Hex), Force Multiple Coils.
32
C++ Class Documentation
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.
• int readInputRegisters (int slaveAddr, int startRef, short regArr[ ], int refCnt)
Modbus function 4, Read Input Registers.
• int writeSingleRegister (int slaveAddr, int regAddr, short regVal)
Modbus function 6, Preset Single Register/Write Single Register.
• int writeMultipleRegisters (int slaveAddr, int startRef, const short regArr[ ], int refCnt)
Modbus function 16 (10 Hex), Preset Multiple Registers/Write Multiple Registers.
• int maskWriteRegister (int slaveAddr, int regAddr, short andMask, short orMask)
Modbus function 22 (16 Hex), Mask Write Register.
• int readWriteRegisters (int slaveAddr, int readRef, short readArr[ ], int readCnt, int
writeRef, const short writeArr[ ], int writeCnt)
Modbus function 23 (17 Hex), Read/Write Registers.
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.
• 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.
• 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.
• int readMultipleFloats (int slaveAddr, int startRef, float float32Arr[ ], int refCnt)
Modbus function 3 for 32-bit float data types, Read Holding Registers/Read Multiple Regis-
ters as float data.
• 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.
• int writeMultipleFloats (int slaveAddr, int startRef, const float float32Arr[ ], int refCnt)
Modbus function 16 (10 Hex) for 32-bit float data types, Preset Multiple Registers/Write
Multiple Registers with float data.
• int 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.
• 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.
• 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.
33
FieldTalk Modbus Master C++ Library: Software manual
Diagnostics
• int readExceptionStatus (int slaveAddr, unsigned char ∗statusBytePtr)
Modbus function 7, Read Exception Status.
• int returnQueryData (int slaveAddr, const unsigned char queryArr[ ], unsigned char
echoArr[ ], int len)
Modbus function code 8, sub-function 00, Return Query Data.
• int restartCommunicationsOption (int slaveAddr, int clearEventLog)
Modbus function code 8, sub-function 01, Restart Communications Option.
Protocol Configuration
• int setTimeout (int timeOut)
Configures time-out.
• int getTimeout ()
Returns the time-out value.
• int setPollDelay (int pollDelay)
Configures poll delay.
• int getPollDelay ()
Returns the poll delay time.
• int setRetryCnt (int retryCnt)
Configures the automatic retry setting.
• int getRetryCnt ()
Returns the automatic retry count.
34
C++ Class Documentation
Slave Configuration
• void configureBigEndianInts ()
Configures 32-bit int data type functions to do a word swap.
• int configureBigEndianInts (int slaveAddr)
Enables int data type functions to do a word swap on a per slave basis.
• void configureLittleEndianInts ()
Configures 32-bit int data type functions not to do a word swap.
• int configureLittleEndianInts (int slaveAddr)
Disables word swapping for int data type functions on a per slave basis.
• void configureIeeeFloats ()
Configures float data type functions not to do a word swap.
• int configureIeeeFloats (int slaveAddr)
Disables float data type functions to do a word swap on a per slave basis.
• void configureSwappedFloats ()
Configures float data type functions to do a word swap.
• int configureSwappedFloats (int slaveAddr)
Enables float data type functions to do a word swap on a per slave basis.
• void configureStandard32BitMode ()
Configures all slaves for Standard 32-bit Mode.
• int configureStandard32BitMode (int slaveAddr)
Configures a slave for Standard 32-bit Register Mode.
• void configureEnron32BitMode ()
Configures all slaves for Daniel/ENRON 32-bit Mode.
• int configureEnron32BitMode (int slaveAddr)
Configures all slaves for Daniel/ENRON 32-bit Mode.
• void configureCountFromOne ()
Configures the reference counting scheme to start with one for all slaves.
• int configureCountFromOne (int slaveAddr)
Configures a slave's reference counting scheme to start with one.
• void configureCountFromZero ()
Configures the reference counting scheme to start with zero for all slaves.
• int configureCountFromZero (int slaveAddr)
Configures a slave's reference counting scheme to start with zero.
Utility Functions
35
FieldTalk Modbus Master C++ Library: Software manual
See also
Data and Control Functions for all Modbus Protocol Flavours, Serial Protocols
MbusRtuOverTcpMasterProtocol
Enumerator
SER_DATABITS←- 7 data bits
_7
SER_DATABITS←- 8 data bits
_8
Enumerator
SER_STOPBITS←- 1 stop bit
_1
SER_STOPBITS←- 2 stop bits
_2
36
C++ Class Documentation
Enumerator
No parity.
SER_PARITY_NONE
SER_PARITY_EVEN Even parity.
SER_PARITY_ODD Odd parity.
Opens a Modbus RTU protocol and the associated serial port with specific port parame-
ters.
This function opens the serial port. After a port has been opened, data and control
functions can be used.
Note
The default time-out for the data transfer is 1000 ms.
The default poll delay is 0 ms.
Automatic retries are switched off (retry count is 0).
The Modbus standard requires two stop bits if no parity is chosen. This library is
not enforcing this but it is a recommended configuration.
Parameters
portName Serial port identifier (e.g. ”COM1”, ”/dev/ser1” or ”/dev/ttyS0”)
baudRate The port baudRate in bps (typically 1200 - 115200, maximum value
depends on UART hardware)
dataBits Must be SER_DATABITS_8 for RTU
stopBits SER_STOPBITS_1: 1 stop bit, SER_STOPBITS_2: 2 stop bits
parity SER_PARITY_NONE: no parity, SER_PARITY_ODD: odd parity,
SER_PARITY_EVEN: even parity
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error
codes.
37
FieldTalk Modbus Master C++ Library: Software manual
Return values
true = open
false = closed
Implements MbusMasterFunctions.
Warning
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.
38
C++ Class Documentation
Parameters
rtsDelay Delay time in ms (Range: 0 - 100000) which applies after the transmit
buffer is empty. 0 disables this mode.
Return values
FTALK_SUCCESS Success
FTALK_ILLEGAL_ARGUMENT_ERR←- Argument out of range
OR
FTALK_ILLEGAL_STATE_ERROR Protocol is already open
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
bitArr Buffer which will contain the data read
refCnt Number 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
39
FieldTalk Modbus Master C++ Library: Software manual
int startRef,
int bitArr[ ],
int refCnt ) [inherited]
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
bitArr Buffer which will contain the data read
refCnt Number 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
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
bitAddr Coil address (Range: 1 - 65536)
bitVal true sets, false clears discrete output variable
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error
codes.
40
C++ Class Documentation
Note
Broadcast supported for serial protocols
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
startRef Start reference (Range: 1 - 65536)
bitArr Buffer which contains the data to be sent
refCnt Number 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
41
FieldTalk Modbus Master C++ Library: Software manual
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start register (Range: 1 - 65536)
regArr Buffer which will be filled with the data read
refCnt Number 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
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start register (Range: 1 - 65536)
regArr Buffer which will be filled with the data read.
refCnt Number 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
42
C++ Class Documentation
int regAddr,
short regVal ) [inherited]
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
regAddr Register address (Range: 1 - 65536)
regVal Data 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
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
startRef Start register (Range: 1 - 65536)
regArr Buffer with the data to be sent.
refCnt Number 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.
43
FieldTalk Modbus Master C++ Library: Software manual
Note
Broadcast supported for serial protocols
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255 for
serial, 0 - 255 for TCP)
regAddr Register address (Range: 1 - 65536)
andMask Mask to be applied as a logic AND to the register
orMask Mask to be applied as a logic OR to the register
Note
No broadcast supported
44
C++ Class Documentation
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255 for
serial, 0 - 255 for TCP)
readRef Start register for reading (Range: 1 - 65536)
readArr Buffer which will contain the data read
readCnt Number of registers to be read (Range: 1-125)
writeRef Start register for writing (Range: 1 - 65536)
writeArr Buffer with data to be sent
writeCnt Number 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
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer which will be filled with the data read
refCnt Number of long integers to be read (Range: 1-62)
45
FieldTalk Modbus Master C++ Library: Software manual
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error
codes.
Note
No broadcast supported
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer which will be filled with the data read
refCnt Number of long 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
46
C++ Class Documentation
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
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer with the data to be sent
refCnt Number of long integers 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.
Modbus function 3 for 32-bit float data types, Read Holding Registers/Read Multiple Reg-
isters 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).
47
FieldTalk Modbus Master C++ Library: Software manual
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
float32Arr Buffer which will be filled with the data read
refCnt Number of float 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
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
float32Arr Buffer which will be filled with the data read
refCnt Number of floats to be read (Range: 1-62)
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error
codes.
48
C++ Class Documentation
Note
No broadcast supported
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
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
startRef Start reference (Range: 1 - 65536)
float32Arr Buffer with the data to be sent
refCnt Number of float 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.
Modbus function 3 for 32-bit modulo-10000 long int data types, Read Holding
Registers/Read Multiple Registers as modulo-10000 long int data.
49
FieldTalk Modbus Master C++ Library: Software manual
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer which will be filled with the data read
refCnt Number 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
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer which will be filled with the data read
50 refCnt Number of M10K integers to be read (Range: 1-62)
C++ Class Documentation
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error
codes.
Note
No broadcast supported
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
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer with the data to be sent
refCnt Number of long integer 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.
51
FieldTalk Modbus Master C++ Library: Software manual
int slaveAddr,
unsigned char ∗ statusBytePtr ) [inherited]
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255 for
serial, 0 - 255 for TCP)
statusBytePtr Slave 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
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255 for
serial, 0 - 255 for TCP)
queryArr Buffer with data to be sent
echoArr Buffer which will contain the data read
len Number 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.
52
C++ Class Documentation
Note
No broadcast supported
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255 for
serial, 0 - 255 for TCP)
clearEventLog Flag 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.
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.
53
FieldTalk Modbus Master C++ Library: Software manual
Parameters
msTime Timeout value in ms (Range: 1 - 100000)
Return values
FTALK_SUCCESS Success
FTALK_ILLEGAL_ARGUMENT_ERR←- Argument out of range
OR
FTALK_ILLEGAL_STATE_ERROR Protocol is already open
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
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.
54
C++ Class Documentation
Parameters
msTime Delay time in ms (Range: 0 - 100000), 0 disables poll delay
Return values
FTALK_SUCCESS Success
FTALK_ILLEGAL_ARGUMENT_ERR←- Argument out of range
OR
FTALK_ILLEGAL_STATE_ERROR Protocol is already open
Returns
Delay time in ms, 0 if poll delay is switched off
Note
A protocol must be closed in order to configure it.
Parameters
retries Retry count (Range: 0 - 10), 0 disables retries
Return values
FTALK_SUCCESS Success
FTALK_ILLEGAL_ARGUMENT_ERR←- Argument out of range
OR
FTALK_ILLEGAL_STATE_ERROR Protocol is already open
55
FieldTalk Modbus Master C++ Library: Software manual
Returns
Retry count
Returns
Counter value
Returns
Counter value
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.
56
C++ Class Documentation
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
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.
57
FieldTalk Modbus Master C++ Library: Software manual
Remarks
This is the default mode
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
Note
Most platforms store floats in IEEE 754 little-endian order which does not need a
word swap.
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
58
C++ Class Documentation
Note
This function call also re-configures the endianess to default little-endian for 32-bit
values!
Remarks
This is the default mode
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
Return values
FTALK_SUCCESS Success
FTALK_ILLEGAL_ARGUMENT_ERR←- Argument out of range
OR
Remarks
This is the default mode
Note
This function call also re-configures the endianess to default little-endian for 32-bit
values!
59
FieldTalk Modbus Master C++ Library: Software manual
Note
This function call also re-configures the endianess to big-endian for 32-bit values
as defined by the Daniel/ENRON protocol!
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
Return values
FTALK_SUCCESS Success
FTALK_ILLEGAL_ARGUMENT_ERR←- Argument out of range
OR
Note
This function call also re-configures the endianess to big-endian for 32-bit values
as defined by the Daniel/ENRON protocol!
60
C++ Class Documentation
Remarks
This is the default mode
Parameters
slaveAddr Modbus 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
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
61
FieldTalk Modbus Master C++ Library: Software manual
Returns
Library version string
Public Types
• enum { SER_DATABITS_7 = 7, SER_DATABITS_8 = 8 }
• enum { SER_STOPBITS_1 = 1, SER_STOPBITS_2 = 2 }
• enum { SER_PARITY_NONE = 0, SER_PARITY_EVEN = 2, SER_PARITY_ODD = 1 }
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.
• int readInputDiscretes (int slaveAddr, int startRef, int bitArr[ ], int refCnt)
Modbus function 2, Read Inputs Status/Read Input Discretes.
• int writeCoil (int slaveAddr, int bitAddr, int bitVal)
Modbus function 5, Force Single Coil/Write Coil.
• int forceMultipleCoils (int slaveAddr, int startRef, const int bitArr[ ], int refCnt)
Modbus function 15 (0F Hex), Force Multiple Coils.
62
C++ Class Documentation
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.
• int readInputRegisters (int slaveAddr, int startRef, short regArr[ ], int refCnt)
Modbus function 4, Read Input Registers.
• int writeSingleRegister (int slaveAddr, int regAddr, short regVal)
Modbus function 6, Preset Single Register/Write Single Register.
• int writeMultipleRegisters (int slaveAddr, int startRef, const short regArr[ ], int refCnt)
Modbus function 16 (10 Hex), Preset Multiple Registers/Write Multiple Registers.
• int maskWriteRegister (int slaveAddr, int regAddr, short andMask, short orMask)
Modbus function 22 (16 Hex), Mask Write Register.
• int readWriteRegisters (int slaveAddr, int readRef, short readArr[ ], int readCnt, int
writeRef, const short writeArr[ ], int writeCnt)
Modbus function 23 (17 Hex), Read/Write Registers.
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.
• 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.
• 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.
• int readMultipleFloats (int slaveAddr, int startRef, float float32Arr[ ], int refCnt)
Modbus function 3 for 32-bit float data types, Read Holding Registers/Read Multiple Regis-
ters as float data.
• 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.
• int writeMultipleFloats (int slaveAddr, int startRef, const float float32Arr[ ], int refCnt)
Modbus function 16 (10 Hex) for 32-bit float data types, Preset Multiple Registers/Write
Multiple Registers with float data.
• int 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.
• 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.
• 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.
63
FieldTalk Modbus Master C++ Library: Software manual
Diagnostics
• int readExceptionStatus (int slaveAddr, unsigned char ∗statusBytePtr)
Modbus function 7, Read Exception Status.
• int returnQueryData (int slaveAddr, const unsigned char queryArr[ ], unsigned char
echoArr[ ], int len)
Modbus function code 8, sub-function 00, Return Query Data.
• int restartCommunicationsOption (int slaveAddr, int clearEventLog)
Modbus function code 8, sub-function 01, Restart Communications Option.
Protocol Configuration
• int setTimeout (int timeOut)
Configures time-out.
• int getTimeout ()
Returns the time-out value.
• int setPollDelay (int pollDelay)
Configures poll delay.
• int getPollDelay ()
Returns the poll delay time.
• int setRetryCnt (int retryCnt)
Configures the automatic retry setting.
• int getRetryCnt ()
Returns the automatic retry count.
64
C++ Class Documentation
Slave Configuration
• void configureBigEndianInts ()
Configures 32-bit int data type functions to do a word swap.
• int configureBigEndianInts (int slaveAddr)
Enables int data type functions to do a word swap on a per slave basis.
• void configureLittleEndianInts ()
Configures 32-bit int data type functions not to do a word swap.
• int configureLittleEndianInts (int slaveAddr)
Disables word swapping for int data type functions on a per slave basis.
• void configureIeeeFloats ()
Configures float data type functions not to do a word swap.
• int configureIeeeFloats (int slaveAddr)
Disables float data type functions to do a word swap on a per slave basis.
• void configureSwappedFloats ()
Configures float data type functions to do a word swap.
• int configureSwappedFloats (int slaveAddr)
Enables float data type functions to do a word swap on a per slave basis.
• void configureStandard32BitMode ()
Configures all slaves for Standard 32-bit Mode.
• int configureStandard32BitMode (int slaveAddr)
Configures a slave for Standard 32-bit Register Mode.
• void configureEnron32BitMode ()
Configures all slaves for Daniel/ENRON 32-bit Mode.
• int configureEnron32BitMode (int slaveAddr)
Configures all slaves for Daniel/ENRON 32-bit Mode.
• void configureCountFromOne ()
Configures the reference counting scheme to start with one for all slaves.
• int configureCountFromOne (int slaveAddr)
Configures a slave's reference counting scheme to start with one.
• void configureCountFromZero ()
Configures the reference counting scheme to start with zero for all slaves.
• int configureCountFromZero (int slaveAddr)
Configures a slave's reference counting scheme to start with zero.
Utility Functions
65
FieldTalk Modbus Master C++ Library: Software manual
See also
Data and Control Functions for all Modbus Protocol Flavours, Serial Protocols
MbusAsciiOverTcpMasterProtocol
Enumerator
SER_DATABITS←- 7 data bits
_7
SER_DATABITS←- 8 data bits
_8
Enumerator
SER_STOPBITS←- 1 stop bit
_1
SER_STOPBITS←- 2 stop bits
_2
66
C++ Class Documentation
Enumerator
No parity.
SER_PARITY_NONE
SER_PARITY_EVEN Even parity.
SER_PARITY_ODD Odd parity.
Opens a serial Modbus protocol and the associated serial port with specific port param-
eters.
This function opens the serial port. After a port has been opened, data and control
functions can be used.
Note
The default time-out for the data transfer is 1000 ms.
The default poll delay is 0 ms.
Automatic retries are switched off (retry count is 0).
The Modbus standard requires two stop bits if no parity is chosen. This library is
not enforcing this but it is a recommended configuration.
Parameters
portName Serial port identifier (e.g. ”COM1”, ”/dev/ser1” or ”/dev/ttyS0”)
baudRate The port baudRate in bps (typically 1200 - 115200, maximum value
depends on UART hardware)
dataBits SER_DATABITS_7: 7 data bits (ASCII protocol only), SER_DATABITS_8:
data bits
stopBits SER_STOPBITS_1: 1 stop bit, SER_STOPBITS_2: 2 stop bits
parity SER_PARITY_NONE: no parity, SER_PARITY_ODD: odd parity,
SER_PARITY_EVEN: even parity
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error
codes.
67
FieldTalk Modbus Master C++ Library: Software manual
Reimplemented in MbusRtuMasterProtocol.
References FTALK_ILLEGAL_ARGUMENT_ERROR, FTALK_ILLEGAL_STATE_ERROR, FTALK←-
_OPEN_ERR, FTALK_PORT_ALREADY_OPEN, FTALK_PORT_NO_ACCESS, FTALK_SUCCESS,
and MbusSerialClientBase::isOpen().
Return values
true = open
false = closed
Implements MbusMasterFunctions.
Warning
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.
68
C++ Class Documentation
Parameters
rtsDelay Delay time in ms (Range: 0 - 100000) which applies after the transmit
buffer is empty. 0 disables this mode.
Return values
FTALK_SUCCESS Success
FTALK_ILLEGAL_ARGUMENT_ERR←- Argument out of range
OR
FTALK_ILLEGAL_STATE_ERROR Protocol is already open
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
bitArr Buffer which will contain the data read
refCnt Number 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
69
FieldTalk Modbus Master C++ Library: Software manual
int startRef,
int bitArr[ ],
int refCnt ) [inherited]
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
bitArr Buffer which will contain the data read
refCnt Number 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
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
bitAddr Coil address (Range: 1 - 65536)
bitVal true sets, false clears discrete output variable
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error
codes.
70
C++ Class Documentation
Note
Broadcast supported for serial protocols
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
startRef Start reference (Range: 1 - 65536)
bitArr Buffer which contains the data to be sent
refCnt Number 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
71
FieldTalk Modbus Master C++ Library: Software manual
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start register (Range: 1 - 65536)
regArr Buffer which will be filled with the data read
refCnt Number 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
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start register (Range: 1 - 65536)
regArr Buffer which will be filled with the data read.
refCnt Number 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
72
C++ Class Documentation
int regAddr,
short regVal ) [inherited]
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
regAddr Register address (Range: 1 - 65536)
regVal Data 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
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
startRef Start register (Range: 1 - 65536)
regArr Buffer with the data to be sent.
refCnt Number 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.
73
FieldTalk Modbus Master C++ Library: Software manual
Note
Broadcast supported for serial protocols
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255 for
serial, 0 - 255 for TCP)
regAddr Register address (Range: 1 - 65536)
andMask Mask to be applied as a logic AND to the register
orMask Mask to be applied as a logic OR to the register
Note
No broadcast supported
74
C++ Class Documentation
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255 for
serial, 0 - 255 for TCP)
readRef Start register for reading (Range: 1 - 65536)
readArr Buffer which will contain the data read
readCnt Number of registers to be read (Range: 1-125)
writeRef Start register for writing (Range: 1 - 65536)
writeArr Buffer with data to be sent
writeCnt Number 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
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer which will be filled with the data read
refCnt Number of long integers to be read (Range: 1-62)
75
FieldTalk Modbus Master C++ Library: Software manual
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error
codes.
Note
No broadcast supported
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer which will be filled with the data read
refCnt Number of long 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
76
C++ Class Documentation
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
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer with the data to be sent
refCnt Number of long integers 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.
Modbus function 3 for 32-bit float data types, Read Holding Registers/Read Multiple Reg-
isters 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).
77
FieldTalk Modbus Master C++ Library: Software manual
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
float32Arr Buffer which will be filled with the data read
refCnt Number of float 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
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
float32Arr Buffer which will be filled with the data read
refCnt Number of floats to be read (Range: 1-62)
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error
codes.
78
C++ Class Documentation
Note
No broadcast supported
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
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
startRef Start reference (Range: 1 - 65536)
float32Arr Buffer with the data to be sent
refCnt Number of float 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.
Modbus function 3 for 32-bit modulo-10000 long int data types, Read Holding
Registers/Read Multiple Registers as modulo-10000 long int data.
79
FieldTalk Modbus Master C++ Library: Software manual
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer which will be filled with the data read
refCnt Number 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
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer which will be filled with the data read
80 refCnt Number of M10K integers to be read (Range: 1-62)
C++ Class Documentation
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error
codes.
Note
No broadcast supported
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
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer with the data to be sent
refCnt Number of long integer 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.
81
FieldTalk Modbus Master C++ Library: Software manual
int slaveAddr,
unsigned char ∗ statusBytePtr ) [inherited]
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255 for
serial, 0 - 255 for TCP)
statusBytePtr Slave 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
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255 for
serial, 0 - 255 for TCP)
queryArr Buffer with data to be sent
echoArr Buffer which will contain the data read
len Number 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.
82
C++ Class Documentation
Note
No broadcast supported
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255 for
serial, 0 - 255 for TCP)
clearEventLog Flag 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.
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.
83
FieldTalk Modbus Master C++ Library: Software manual
Parameters
msTime Timeout value in ms (Range: 1 - 100000)
Return values
FTALK_SUCCESS Success
FTALK_ILLEGAL_ARGUMENT_ERR←- Argument out of range
OR
FTALK_ILLEGAL_STATE_ERROR Protocol is already open
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
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.
84
C++ Class Documentation
Parameters
msTime Delay time in ms (Range: 0 - 100000), 0 disables poll delay
Return values
FTALK_SUCCESS Success
FTALK_ILLEGAL_ARGUMENT_ERR←- Argument out of range
OR
FTALK_ILLEGAL_STATE_ERROR Protocol is already open
Returns
Delay time in ms, 0 if poll delay is switched off
Note
A protocol must be closed in order to configure it.
Parameters
retries Retry count (Range: 0 - 10), 0 disables retries
Return values
FTALK_SUCCESS Success
FTALK_ILLEGAL_ARGUMENT_ERR←- Argument out of range
OR
FTALK_ILLEGAL_STATE_ERROR Protocol is already open
85
FieldTalk Modbus Master C++ Library: Software manual
Returns
Retry count
Returns
Counter value
Returns
Counter value
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.
86
C++ Class Documentation
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
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.
87
FieldTalk Modbus Master C++ Library: Software manual
Remarks
This is the default mode
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
Note
Most platforms store floats in IEEE 754 little-endian order which does not need a
word swap.
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
88
C++ Class Documentation
Note
This function call also re-configures the endianess to default little-endian for 32-bit
values!
Remarks
This is the default mode
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
Return values
FTALK_SUCCESS Success
FTALK_ILLEGAL_ARGUMENT_ERR←- Argument out of range
OR
Remarks
This is the default mode
Note
This function call also re-configures the endianess to default little-endian for 32-bit
values!
89
FieldTalk Modbus Master C++ Library: Software manual
Note
This function call also re-configures the endianess to big-endian for 32-bit values
as defined by the Daniel/ENRON protocol!
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
Return values
FTALK_SUCCESS Success
FTALK_ILLEGAL_ARGUMENT_ERR←- Argument out of range
OR
Note
This function call also re-configures the endianess to big-endian for 32-bit values
as defined by the Daniel/ENRON protocol!
90
C++ Class Documentation
Remarks
This is the default mode
Parameters
slaveAddr Modbus 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
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
91
FieldTalk Modbus Master C++ Library: Software manual
Returns
Library version string
Public Types
• enum { SER_DATABITS_7 = 7, SER_DATABITS_8 = 8 }
• enum { SER_STOPBITS_1 = 1, SER_STOPBITS_2 = 2 }
• enum { SER_PARITY_NONE = 0, SER_PARITY_EVEN = 2, SER_PARITY_ODD = 1 }
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.
• int readInputDiscretes (int slaveAddr, int startRef, int bitArr[ ], int refCnt)
Modbus function 2, Read Inputs Status/Read Input Discretes.
• int writeCoil (int slaveAddr, int bitAddr, int bitVal)
Modbus function 5, Force Single Coil/Write Coil.
• int forceMultipleCoils (int slaveAddr, int startRef, const int bitArr[ ], int refCnt)
Modbus function 15 (0F Hex), Force Multiple Coils.
92
C++ Class Documentation
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.
• int readInputRegisters (int slaveAddr, int startRef, short regArr[ ], int refCnt)
Modbus function 4, Read Input Registers.
• int writeSingleRegister (int slaveAddr, int regAddr, short regVal)
Modbus function 6, Preset Single Register/Write Single Register.
• int writeMultipleRegisters (int slaveAddr, int startRef, const short regArr[ ], int refCnt)
Modbus function 16 (10 Hex), Preset Multiple Registers/Write Multiple Registers.
• int maskWriteRegister (int slaveAddr, int regAddr, short andMask, short orMask)
Modbus function 22 (16 Hex), Mask Write Register.
• int readWriteRegisters (int slaveAddr, int readRef, short readArr[ ], int readCnt, int
writeRef, const short writeArr[ ], int writeCnt)
Modbus function 23 (17 Hex), Read/Write Registers.
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.
• 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.
• 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.
• int readMultipleFloats (int slaveAddr, int startRef, float float32Arr[ ], int refCnt)
Modbus function 3 for 32-bit float data types, Read Holding Registers/Read Multiple Regis-
ters as float data.
• 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.
• int writeMultipleFloats (int slaveAddr, int startRef, const float float32Arr[ ], int refCnt)
Modbus function 16 (10 Hex) for 32-bit float data types, Preset Multiple Registers/Write
Multiple Registers with float data.
• int 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.
• 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.
• 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.
93
FieldTalk Modbus Master C++ Library: Software manual
Diagnostics
• int readExceptionStatus (int slaveAddr, unsigned char ∗statusBytePtr)
Modbus function 7, Read Exception Status.
• int returnQueryData (int slaveAddr, const unsigned char queryArr[ ], unsigned char
echoArr[ ], int len)
Modbus function code 8, sub-function 00, Return Query Data.
• int restartCommunicationsOption (int slaveAddr, int clearEventLog)
Modbus function code 8, sub-function 01, Restart Communications Option.
Protocol Configuration
• int setTimeout (int timeOut)
Configures time-out.
• int getTimeout ()
Returns the time-out value.
• int setPollDelay (int pollDelay)
Configures poll delay.
• int getPollDelay ()
Returns the poll delay time.
• int setRetryCnt (int retryCnt)
Configures the automatic retry setting.
• int getRetryCnt ()
Returns the automatic retry count.
94
C++ Class Documentation
Slave Configuration
• void configureBigEndianInts ()
Configures 32-bit int data type functions to do a word swap.
• int configureBigEndianInts (int slaveAddr)
Enables int data type functions to do a word swap on a per slave basis.
• void configureLittleEndianInts ()
Configures 32-bit int data type functions not to do a word swap.
• int configureLittleEndianInts (int slaveAddr)
Disables word swapping for int data type functions on a per slave basis.
• void configureIeeeFloats ()
Configures float data type functions not to do a word swap.
• int configureIeeeFloats (int slaveAddr)
Disables float data type functions to do a word swap on a per slave basis.
• void configureSwappedFloats ()
Configures float data type functions to do a word swap.
• int configureSwappedFloats (int slaveAddr)
Enables float data type functions to do a word swap on a per slave basis.
• void configureStandard32BitMode ()
Configures all slaves for Standard 32-bit Mode.
• int configureStandard32BitMode (int slaveAddr)
Configures a slave for Standard 32-bit Register Mode.
• void configureEnron32BitMode ()
Configures all slaves for Daniel/ENRON 32-bit Mode.
• int configureEnron32BitMode (int slaveAddr)
Configures all slaves for Daniel/ENRON 32-bit Mode.
• void configureCountFromOne ()
Configures the reference counting scheme to start with one for all slaves.
• int configureCountFromOne (int slaveAddr)
Configures a slave's reference counting scheme to start with one.
• void configureCountFromZero ()
Configures the reference counting scheme to start with zero for all slaves.
• int configureCountFromZero (int slaveAddr)
Configures a slave's reference counting scheme to start with zero.
Utility Functions
95
FieldTalk Modbus Master C++ Library: Software manual
See also
Data and Control Functions for all Modbus Protocol Flavours, Serial Protocols
MbusRtuMasterProtocol
Enumerator
SER_DATABITS←- 7 data bits
_7
SER_DATABITS←- 8 data bits
_8
Enumerator
SER_STOPBITS←- 1 stop bit
_1
SER_STOPBITS←- 2 stop bits
_2
96
C++ Class Documentation
Enumerator
No parity.
SER_PARITY_NONE
SER_PARITY_EVEN Even parity.
SER_PARITY_ODD Odd parity.
Opens a Modbus RTU protocol and the associated serial port with specific port parame-
ters.
This function opens the serial port. After a port has been opened, data and control
functions can be used.
Note
The default time-out for the data transfer is 1000 ms.
The default poll delay is 0 ms.
Automatic retries are switched off (retry count is 0).
The Modbus standard requires two stop bits if no parity is chosen. This library is
not enforcing this but it is a recommended configuration.
Parameters
portName Serial port identifier (e.g. ”COM1”, ”/dev/ser1” or ”/dev/ttyS0”)
baudRate The port baudRate in bps (typically 1200 - 115200, maximum value
depends on UART hardware)
dataBits Must be SER_DATABITS_8 for RTU
stopBits SER_STOPBITS_1: 1 stop bit, SER_STOPBITS_2: 2 stop bits
parity SER_PARITY_NONE: no parity, SER_PARITY_ODD: odd parity,
SER_PARITY_EVEN: even parity
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error
codes.
97
FieldTalk Modbus Master C++ Library: Software manual
Return values
true = open
false = closed
Implements MbusMasterFunctions.
Warning
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.
98
C++ Class Documentation
Parameters
rtsDelay Delay time in ms (Range: 0 - 100000) which applies after the transmit
buffer is empty. 0 disables this mode.
Return values
FTALK_SUCCESS Success
FTALK_ILLEGAL_ARGUMENT_ERR←- Argument out of range
OR
FTALK_ILLEGAL_STATE_ERROR Protocol is already open
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
bitArr Buffer which will contain the data read
refCnt Number 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
99
FieldTalk Modbus Master C++ Library: Software manual
int startRef,
int bitArr[ ],
int refCnt ) [inherited]
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
bitArr Buffer which will contain the data read
refCnt Number 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
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
bitAddr Coil address (Range: 1 - 65536)
bitVal true sets, false clears discrete output variable
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error
codes.
100
C++ Class Documentation
Note
Broadcast supported for serial protocols
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
startRef Start reference (Range: 1 - 65536)
bitArr Buffer which contains the data to be sent
refCnt Number 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
101
FieldTalk Modbus Master C++ Library: Software manual
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start register (Range: 1 - 65536)
regArr Buffer which will be filled with the data read
refCnt Number 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
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start register (Range: 1 - 65536)
regArr Buffer which will be filled with the data read.
refCnt Number 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
102
C++ Class Documentation
int regAddr,
short regVal ) [inherited]
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
regAddr Register address (Range: 1 - 65536)
regVal Data 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
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
startRef Start register (Range: 1 - 65536)
regArr Buffer with the data to be sent.
refCnt Number 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.
103
FieldTalk Modbus Master C++ Library: Software manual
Note
Broadcast supported for serial protocols
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255 for
serial, 0 - 255 for TCP)
regAddr Register address (Range: 1 - 65536)
andMask Mask to be applied as a logic AND to the register
orMask Mask to be applied as a logic OR to the register
Note
No broadcast supported
104
C++ Class Documentation
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255 for
serial, 0 - 255 for TCP)
readRef Start register for reading (Range: 1 - 65536)
readArr Buffer which will contain the data read
readCnt Number of registers to be read (Range: 1-125)
writeRef Start register for writing (Range: 1 - 65536)
writeArr Buffer with data to be sent
writeCnt Number 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
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer which will be filled with the data read
refCnt Number of long integers to be read (Range: 1-62)
105
FieldTalk Modbus Master C++ Library: Software manual
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error
codes.
Note
No broadcast supported
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer which will be filled with the data read
refCnt Number of long 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
106
C++ Class Documentation
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
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer with the data to be sent
refCnt Number of long integers 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.
Modbus function 3 for 32-bit float data types, Read Holding Registers/Read Multiple Reg-
isters 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).
107
FieldTalk Modbus Master C++ Library: Software manual
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
float32Arr Buffer which will be filled with the data read
refCnt Number of float 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
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
float32Arr Buffer which will be filled with the data read
refCnt Number of floats to be read (Range: 1-62)
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error
codes.
108
C++ Class Documentation
Note
No broadcast supported
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
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
startRef Start reference (Range: 1 - 65536)
float32Arr Buffer with the data to be sent
refCnt Number of float 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.
Modbus function 3 for 32-bit modulo-10000 long int data types, Read Holding
Registers/Read Multiple Registers as modulo-10000 long int data.
109
FieldTalk Modbus Master C++ Library: Software manual
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer which will be filled with the data read
refCnt Number 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
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer which will be filled with the data read
110 refCnt Number of M10K integers to be read (Range: 1-62)
C++ Class Documentation
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error
codes.
Note
No broadcast supported
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
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer with the data to be sent
refCnt Number of long integer 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.
111
FieldTalk Modbus Master C++ Library: Software manual
int slaveAddr,
unsigned char ∗ statusBytePtr ) [inherited]
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255 for
serial, 0 - 255 for TCP)
statusBytePtr Slave 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
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255 for
serial, 0 - 255 for TCP)
queryArr Buffer with data to be sent
echoArr Buffer which will contain the data read
len Number 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.
112
C++ Class Documentation
Note
No broadcast supported
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255 for
serial, 0 - 255 for TCP)
clearEventLog Flag 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.
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.
113
FieldTalk Modbus Master C++ Library: Software manual
Parameters
msTime Timeout value in ms (Range: 1 - 100000)
Return values
FTALK_SUCCESS Success
FTALK_ILLEGAL_ARGUMENT_ERR←- Argument out of range
OR
FTALK_ILLEGAL_STATE_ERROR Protocol is already open
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
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.
114
C++ Class Documentation
Parameters
msTime Delay time in ms (Range: 0 - 100000), 0 disables poll delay
Return values
FTALK_SUCCESS Success
FTALK_ILLEGAL_ARGUMENT_ERR←- Argument out of range
OR
FTALK_ILLEGAL_STATE_ERROR Protocol is already open
Returns
Delay time in ms, 0 if poll delay is switched off
Note
A protocol must be closed in order to configure it.
Parameters
retries Retry count (Range: 0 - 10), 0 disables retries
Return values
FTALK_SUCCESS Success
FTALK_ILLEGAL_ARGUMENT_ERR←- Argument out of range
OR
FTALK_ILLEGAL_STATE_ERROR Protocol is already open
115
FieldTalk Modbus Master C++ Library: Software manual
Returns
Retry count
Returns
Counter value
Returns
Counter value
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.
116
C++ Class Documentation
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
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.
117
FieldTalk Modbus Master C++ Library: Software manual
Remarks
This is the default mode
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
Note
Most platforms store floats in IEEE 754 little-endian order which does not need a
word swap.
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
118
C++ Class Documentation
Note
This function call also re-configures the endianess to default little-endian for 32-bit
values!
Remarks
This is the default mode
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
Return values
FTALK_SUCCESS Success
FTALK_ILLEGAL_ARGUMENT_ERR←- Argument out of range
OR
Remarks
This is the default mode
Note
This function call also re-configures the endianess to default little-endian for 32-bit
values!
119
FieldTalk Modbus Master C++ Library: Software manual
Note
This function call also re-configures the endianess to big-endian for 32-bit values
as defined by the Daniel/ENRON protocol!
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
Return values
FTALK_SUCCESS Success
FTALK_ILLEGAL_ARGUMENT_ERR←- Argument out of range
OR
Note
This function call also re-configures the endianess to big-endian for 32-bit values
as defined by the Daniel/ENRON protocol!
120
C++ Class Documentation
Remarks
This is the default mode
Parameters
slaveAddr Modbus 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
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
121
FieldTalk Modbus Master C++ Library: Software manual
Returns
Library version string
• MbusTcpMasterProtocol ()
Constructs a MbusTcpMasterProtocol object and initialises its data.
• int openProtocol (const char ∗const hostName)
Connects to a MODBUS/TCP slave.
• int setPort (unsigned short portNo)
Sets the TCP port number to be used by the protocol.
• virtual void closeProtocol ()
Closes a TCP/IP connection to a slave and releases any system resources associated with the
connection.
• virtual int isOpen ()
Returns whether the protocol is open or not.
• unsigned short getPort ()
Returns the TCP port number used by the protocol.
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.
• int readInputDiscretes (int slaveAddr, int startRef, int bitArr[ ], int refCnt)
Modbus function 2, Read Inputs Status/Read Input Discretes.
• int writeCoil (int slaveAddr, int bitAddr, int bitVal)
Modbus function 5, Force Single Coil/Write Coil.
• int forceMultipleCoils (int slaveAddr, int startRef, const int bitArr[ ], int refCnt)
Modbus function 15 (0F Hex), Force Multiple Coils.
122
C++ Class Documentation
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.
• int readInputRegisters (int slaveAddr, int startRef, short regArr[ ], int refCnt)
Modbus function 4, Read Input Registers.
• int writeSingleRegister (int slaveAddr, int regAddr, short regVal)
Modbus function 6, Preset Single Register/Write Single Register.
• int writeMultipleRegisters (int slaveAddr, int startRef, const short regArr[ ], int refCnt)
Modbus function 16 (10 Hex), Preset Multiple Registers/Write Multiple Registers.
• int maskWriteRegister (int slaveAddr, int regAddr, short andMask, short orMask)
Modbus function 22 (16 Hex), Mask Write Register.
• int readWriteRegisters (int slaveAddr, int readRef, short readArr[ ], int readCnt, int
writeRef, const short writeArr[ ], int writeCnt)
Modbus function 23 (17 Hex), Read/Write Registers.
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.
• 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.
• 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.
• int readMultipleFloats (int slaveAddr, int startRef, float float32Arr[ ], int refCnt)
Modbus function 3 for 32-bit float data types, Read Holding Registers/Read Multiple Regis-
ters as float data.
• 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.
• int writeMultipleFloats (int slaveAddr, int startRef, const float float32Arr[ ], int refCnt)
Modbus function 16 (10 Hex) for 32-bit float data types, Preset Multiple Registers/Write
Multiple Registers with float data.
• int 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.
• 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.
• 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.
123
FieldTalk Modbus Master C++ Library: Software manual
Diagnostics
• int readExceptionStatus (int slaveAddr, unsigned char ∗statusBytePtr)
Modbus function 7, Read Exception Status.
• int returnQueryData (int slaveAddr, const unsigned char queryArr[ ], unsigned char
echoArr[ ], int len)
Modbus function code 8, sub-function 00, Return Query Data.
• int restartCommunicationsOption (int slaveAddr, int clearEventLog)
Modbus function code 8, sub-function 01, Restart Communications Option.
Protocol Configuration
• int setTimeout (int timeOut)
Configures time-out.
• int getTimeout ()
Returns the time-out value.
• int setPollDelay (int pollDelay)
Configures poll delay.
• int getPollDelay ()
Returns the poll delay time.
• int setRetryCnt (int retryCnt)
Configures the automatic retry setting.
• int getRetryCnt ()
Returns the automatic retry count.
124
C++ Class Documentation
Slave Configuration
• void configureBigEndianInts ()
Configures 32-bit int data type functions to do a word swap.
• int configureBigEndianInts (int slaveAddr)
Enables int data type functions to do a word swap on a per slave basis.
• void configureLittleEndianInts ()
Configures 32-bit int data type functions not to do a word swap.
• int configureLittleEndianInts (int slaveAddr)
Disables word swapping for int data type functions on a per slave basis.
• void configureIeeeFloats ()
Configures float data type functions not to do a word swap.
• int configureIeeeFloats (int slaveAddr)
Disables float data type functions to do a word swap on a per slave basis.
• void configureSwappedFloats ()
Configures float data type functions to do a word swap.
• int configureSwappedFloats (int slaveAddr)
Enables float data type functions to do a word swap on a per slave basis.
• void configureStandard32BitMode ()
Configures all slaves for Standard 32-bit Mode.
• int configureStandard32BitMode (int slaveAddr)
Configures a slave for Standard 32-bit Register Mode.
• void configureEnron32BitMode ()
Configures all slaves for Daniel/ENRON 32-bit Mode.
• int configureEnron32BitMode (int slaveAddr)
Configures all slaves for Daniel/ENRON 32-bit Mode.
• void configureCountFromOne ()
Configures the reference counting scheme to start with one for all slaves.
• int configureCountFromOne (int slaveAddr)
Configures a slave's reference counting scheme to start with one.
• void configureCountFromZero ()
Configures the reference counting scheme to start with zero for all slaves.
• int configureCountFromZero (int slaveAddr)
Configures a slave's reference counting scheme to start with zero.
Utility Functions
• static const TCHAR ∗ getPackageVersion ()
Returns the library version number.
125
FieldTalk Modbus Master C++ Library: Software manual
See also
Data and Control Functions for all Modbus Protocol Flavours, IP based Protocols
Note
The default time-out for the connection is 1000 ms.
Parameters
hostName String with IP address or host name
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error
codes.
Note
The default TCP port number is 502.
126
C++ Class Documentation
Parameters
port←- Port number to be used when opening the connection
No
Return values
FTALK_SUCCESS Success
FTALK_ILLEGAL_STATE_ERR←- Protocol already open
OR
Note
Defaults to 502.
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 differ-
ent from 502 this function must be called before opening the connection with
openProtocol().
Return values
true = open
false = closed
Implements MbusMasterFunctions.
127
FieldTalk Modbus Master C++ Library: Software manual
Returns
Port number used by the protocol
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
bitArr Buffer which will contain the data read
refCnt Number 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
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
bitArr Buffer which will contain the data read
refCnt Number of coils to be read (Range: 1-2000)
128
C++ Class Documentation
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error
codes.
Note
No broadcast supported
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
bitAddr Coil address (Range: 1 - 65536)
bitVal true 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
129
FieldTalk Modbus Master C++ Library: Software manual
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
startRef Start reference (Range: 1 - 65536)
bitArr Buffer which contains the data to be sent
refCnt Number 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
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start register (Range: 1 - 65536)
regArr Buffer which will be filled with the data read
refCnt Number 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
130
C++ Class Documentation
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start register (Range: 1 - 65536)
regArr Buffer which will be filled with the data read.
refCnt Number 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
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
regAddr Register address (Range: 1 - 65536)
regVal Data to be sent
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error
codes.
131
FieldTalk Modbus Master C++ Library: Software manual
Note
Broadcast supported for serial protocols
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
startRef Start register (Range: 1 - 65536)
regArr Buffer with the data to be sent.
refCnt Number 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
132
C++ Class Documentation
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255 for
serial, 0 - 255 for TCP)
regAddr Register address (Range: 1 - 65536)
andMask Mask to be applied as a logic AND to the register
orMask Mask to be applied as a logic OR to the register
Note
No broadcast supported
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255 for
serial, 0 - 255 for TCP)
readRef Start register for reading (Range: 1 - 65536)
readArr Buffer which will contain the data read
readCnt Number of registers to be read (Range: 1-125)
writeRef Start register for writing (Range: 1 - 65536)
writeArr Buffer with data to be sent
writeCnt Number 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.
133
FieldTalk Modbus Master C++ Library: Software manual
Note
No broadcast supported
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer which will be filled with the data read
refCnt Number of long 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
134
C++ Class Documentation
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer which will be filled with the data read
refCnt Number of long 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
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
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer with the data to be sent
refCnt Number of long integers to be sent (Range: 1-61)
135
FieldTalk Modbus Master C++ Library: Software manual
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.
Modbus function 3 for 32-bit float data types, Read Holding Registers/Read Multiple Reg-
isters 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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
float32Arr Buffer which will be filled with the data read
refCnt Number of float 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
136
C++ Class Documentation
int startRef,
float float32Arr[ ],
int refCnt ) [inherited]
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
float32Arr Buffer which will be filled with the data read
refCnt Number of floats 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
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
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
137
FieldTalk Modbus Master C++ Library: Software manual
Parameters
startRef Start reference (Range: 1 - 65536)
float32Arr Buffer with the data to be sent
refCnt Number of float 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.
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer which will be filled with the data read
refCnt Number 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.
138
C++ Class Documentation
Note
No broadcast supported
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer which will be filled with the data read
refCnt Number 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
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.
139
FieldTalk Modbus Master C++ Library: Software manual
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
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer with the data to be sent
refCnt Number of long integer 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.
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255 for
serial, 0 - 255 for TCP)
statusBytePtr Slave 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.
140
C++ Class Documentation
Note
No broadcast supported
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255 for
serial, 0 - 255 for TCP)
queryArr Buffer with data to be sent
echoArr Buffer which will contain the data read
len Number 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
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255 for
serial, 0 - 255 for TCP)
clearEventLog Flag when set to one clears in addition the slave's communication
even log.
141
FieldTalk Modbus Master C++ Library: Software manual
Returns
FTALK_SUCCESS on success. See Error Management for a list of error codes.
Note
No broadcast supported
References FTALK_ILLEGAL_ARGUMENT_ERROR.
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
msTime Timeout value in ms (Range: 1 - 100000)
Return values
FTALK_SUCCESS Success
FTALK_ILLEGAL_ARGUMENT_ERR←- Argument out of range
OR
FTALK_ILLEGAL_STATE_ERROR Protocol is already open
142
C++ Class Documentation
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
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
msTime Delay time in ms (Range: 0 - 100000), 0 disables poll delay
Return values
FTALK_SUCCESS Success
FTALK_ILLEGAL_ARGUMENT_ERR←- Argument out of range
OR
FTALK_ILLEGAL_STATE_ERROR Protocol is already open
143
FieldTalk Modbus Master C++ Library: Software manual
Returns
Delay time in ms, 0 if poll delay is switched off
Note
A protocol must be closed in order to configure it.
Parameters
retries Retry count (Range: 0 - 10), 0 disables retries
Return values
FTALK_SUCCESS Success
FTALK_ILLEGAL_ARGUMENT_ERR←- Argument out of range
OR
FTALK_ILLEGAL_STATE_ERROR Protocol is already open
Returns
Retry count
144
C++ Class Documentation
Returns
Counter value
Returns
Counter value
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
Disables word swapping for int data type functions on a per slave basis.
145
FieldTalk Modbus Master C++ Library: Software manual
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
146
C++ Class Documentation
Note
Most platforms store floats in IEEE 754 little-endian order which does not need a
word swap.
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
Note
This function call also re-configures the endianess to default little-endian for 32-bit
values!
Remarks
This is the default mode
147
FieldTalk Modbus Master C++ Library: Software manual
In Standard 32-bit Register Mode a 32-bit value is transmitted as two consecutive 16-bit
Modbus registers.
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
Return values
FTALK_SUCCESS Success
FTALK_ILLEGAL_ARGUMENT_ERR←- Argument out of range
OR
Remarks
This is the default mode
Note
This function call also re-configures the endianess to default little-endian for 32-bit
values!
Note
This function call also re-configures the endianess to big-endian for 32-bit values
as defined by the Daniel/ENRON protocol!
148
C++ Class Documentation
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
Return values
FTALK_SUCCESS Success
FTALK_ILLEGAL_ARGUMENT_ERR←- Argument out of range
OR
Note
This function call also re-configures the endianess to big-endian for 32-bit values
as defined by the Daniel/ENRON protocol!
Remarks
This is the default mode
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
149
FieldTalk Modbus Master C++ Library: Software manual
Remarks
This is the default mode
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
Returns
Library version string
150
C++ Class Documentation
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.
• int readInputDiscretes (int slaveAddr, int startRef, int bitArr[ ], int refCnt)
Modbus function 2, Read Inputs Status/Read Input Discretes.
• int writeCoil (int slaveAddr, int bitAddr, int bitVal)
Modbus function 5, Force Single Coil/Write Coil.
• int forceMultipleCoils (int slaveAddr, int startRef, const int bitArr[ ], int refCnt)
Modbus function 15 (0F Hex), Force Multiple Coils.
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.
• int readInputRegisters (int slaveAddr, int startRef, short regArr[ ], int refCnt)
Modbus function 4, Read Input Registers.
• int writeSingleRegister (int slaveAddr, int regAddr, short regVal)
Modbus function 6, Preset Single Register/Write Single Register.
• int writeMultipleRegisters (int slaveAddr, int startRef, const short regArr[ ], int refCnt)
Modbus function 16 (10 Hex), Preset Multiple Registers/Write Multiple Registers.
• int maskWriteRegister (int slaveAddr, int regAddr, short andMask, short orMask)
Modbus function 22 (16 Hex), Mask Write Register.
• int readWriteRegisters (int slaveAddr, int readRef, short readArr[ ], int readCnt, int
writeRef, const short writeArr[ ], int writeCnt)
Modbus function 23 (17 Hex), Read/Write Registers.
151
FieldTalk Modbus Master C++ Library: Software manual
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.
• 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.
• 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.
• int readMultipleFloats (int slaveAddr, int startRef, float float32Arr[ ], int refCnt)
Modbus function 3 for 32-bit float data types, Read Holding Registers/Read Multiple Regis-
ters as float data.
• 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.
• int writeMultipleFloats (int slaveAddr, int startRef, const float float32Arr[ ], int refCnt)
Modbus function 16 (10 Hex) for 32-bit float data types, Preset Multiple Registers/Write
Multiple Registers with float data.
• int 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.
• 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.
• 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.
Diagnostics
• int readExceptionStatus (int slaveAddr, unsigned char ∗statusBytePtr)
Modbus function 7, Read Exception Status.
• int returnQueryData (int slaveAddr, const unsigned char queryArr[ ], unsigned char
echoArr[ ], int len)
Modbus function code 8, sub-function 00, Return Query Data.
• int restartCommunicationsOption (int slaveAddr, int clearEventLog)
Modbus function code 8, sub-function 01, Restart Communications Option.
152
C++ Class Documentation
Protocol Configuration
• int setTimeout (int timeOut)
Configures time-out.
• int getTimeout ()
Returns the time-out value.
• int setPollDelay (int pollDelay)
Configures poll delay.
• int getPollDelay ()
Returns the poll delay time.
• int setRetryCnt (int retryCnt)
Configures the automatic retry setting.
• int getRetryCnt ()
Returns the automatic retry count.
Slave Configuration
• void configureBigEndianInts ()
Configures 32-bit int data type functions to do a word swap.
• int configureBigEndianInts (int slaveAddr)
Enables int data type functions to do a word swap on a per slave basis.
• void configureLittleEndianInts ()
Configures 32-bit int data type functions not to do a word swap.
• int configureLittleEndianInts (int slaveAddr)
Disables word swapping for int data type functions on a per slave basis.
• void configureIeeeFloats ()
Configures float data type functions not to do a word swap.
• int configureIeeeFloats (int slaveAddr)
Disables float data type functions to do a word swap on a per slave basis.
• void configureSwappedFloats ()
Configures float data type functions to do a word swap.
• int configureSwappedFloats (int slaveAddr)
153
FieldTalk Modbus Master C++ Library: Software manual
Enables float data type functions to do a word swap on a per slave basis.
• void configureStandard32BitMode ()
Configures all slaves for Standard 32-bit Mode.
• int configureStandard32BitMode (int slaveAddr)
Configures a slave for Standard 32-bit Register Mode.
• void configureEnron32BitMode ()
Configures all slaves for Daniel/ENRON 32-bit Mode.
• int configureEnron32BitMode (int slaveAddr)
Configures all slaves for Daniel/ENRON 32-bit Mode.
• void configureCountFromOne ()
Configures the reference counting scheme to start with one for all slaves.
• int configureCountFromOne (int slaveAddr)
Configures a slave's reference counting scheme to start with one.
• void configureCountFromZero ()
Configures the reference counting scheme to start with zero for all slaves.
• int configureCountFromZero (int slaveAddr)
Configures a slave's reference counting scheme to start with zero.
Utility Functions
• static const TCHAR ∗ getPackageVersion ()
Returns the library version number.
See also
Data and Control Functions for all Modbus Protocol Flavours, IP based Protocols
MbusRtuMasterProtocol
154
C++ Class Documentation
Note
The default time-out for the connection is 1000 ms.
Parameters
hostName String with IP address or host name
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error
codes.
Note
The default TCP port number is 1100.
Sets the TCP port number used to connect to the Modbus RTU slave device.
Usually the port number remains unchanged from its default. In this case no call to this
function is necessary. However if the port number has to be different, this function must
be called before opening the connection with openProtocol().
Parameters
port←- Port number to be used when opening the connection
No
Return values
FTALK_SUCCESS Success
FTALK_ILLEGAL_STATE_ERR←- Protocol already open
OR
155
FieldTalk Modbus Master C++ Library: Software manual
Note
Defaults to 1100.
Return values
true = open
false = closed
Implements MbusMasterFunctions.
Returns
Port number used by the protocol
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
bitArr Buffer which will contain the data read
refCnt Number 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.
156
C++ Class Documentation
Note
No broadcast supported
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
bitArr Buffer which will contain the data read
refCnt Number 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
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
bitAddr Coil address (Range: 1 - 65536)
bitVal true sets, false clears discrete output variable
157
FieldTalk Modbus Master C++ Library: Software manual
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error
codes.
Note
Broadcast supported for serial protocols
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
startRef Start reference (Range: 1 - 65536)
bitArr Buffer which contains the data to be sent
refCnt Number 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
158
C++ Class Documentation
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start register (Range: 1 - 65536)
regArr Buffer which will be filled with the data read
refCnt Number 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
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start register (Range: 1 - 65536)
regArr Buffer which will be filled with the data read.
refCnt Number 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
159
FieldTalk Modbus Master C++ Library: Software manual
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
regAddr Register address (Range: 1 - 65536)
regVal Data 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
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
startRef Start register (Range: 1 - 65536)
regArr Buffer with the data to be sent.
refCnt Number 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.
160
C++ Class Documentation
Note
Broadcast supported for serial protocols
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255 for
serial, 0 - 255 for TCP)
regAddr Register address (Range: 1 - 65536)
andMask Mask to be applied as a logic AND to the register
orMask Mask to be applied as a logic OR to the register
Note
No broadcast supported
161
FieldTalk Modbus Master C++ Library: Software manual
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255 for
serial, 0 - 255 for TCP)
readRef Start register for reading (Range: 1 - 65536)
readArr Buffer which will contain the data read
readCnt Number of registers to be read (Range: 1-125)
writeRef Start register for writing (Range: 1 - 65536)
writeArr Buffer with data to be sent
writeCnt Number 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
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer which will be filled with the data read
refCnt Number of long integers to be read (Range: 1-62)
162
C++ Class Documentation
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error
codes.
Note
No broadcast supported
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer which will be filled with the data read
refCnt Number of long 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
163
FieldTalk Modbus Master C++ Library: Software manual
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
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer with the data to be sent
refCnt Number of long integers 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.
Modbus function 3 for 32-bit float data types, Read Holding Registers/Read Multiple Reg-
isters 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).
164
C++ Class Documentation
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
float32Arr Buffer which will be filled with the data read
refCnt Number of float 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
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
float32Arr Buffer which will be filled with the data read
refCnt Number of floats to be read (Range: 1-62)
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error
codes.
165
FieldTalk Modbus Master C++ Library: Software manual
Note
No broadcast supported
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
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
startRef Start reference (Range: 1 - 65536)
float32Arr Buffer with the data to be sent
refCnt Number of float 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.
Modbus function 3 for 32-bit modulo-10000 long int data types, Read Holding
Registers/Read Multiple Registers as modulo-10000 long int data.
166
C++ Class Documentation
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer which will be filled with the data read
refCnt Number 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
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer which will be filled with the data read
refCnt Number of M10K integers to be read (Range: 1-62) 167
FieldTalk Modbus Master C++ Library: Software manual
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error
codes.
Note
No broadcast supported
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
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer with the data to be sent
refCnt Number of long integer 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.
168
C++ Class Documentation
int slaveAddr,
unsigned char ∗ statusBytePtr ) [inherited]
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255 for
serial, 0 - 255 for TCP)
statusBytePtr Slave 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
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255 for
serial, 0 - 255 for TCP)
queryArr Buffer with data to be sent
echoArr Buffer which will contain the data read
len Number 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.
169
FieldTalk Modbus Master C++ Library: Software manual
Note
No broadcast supported
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255 for
serial, 0 - 255 for TCP)
clearEventLog Flag 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.
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.
170
C++ Class Documentation
Parameters
msTime Timeout value in ms (Range: 1 - 100000)
Return values
FTALK_SUCCESS Success
FTALK_ILLEGAL_ARGUMENT_ERR←- Argument out of range
OR
FTALK_ILLEGAL_STATE_ERROR Protocol is already open
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
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.
171
FieldTalk Modbus Master C++ Library: Software manual
Parameters
msTime Delay time in ms (Range: 0 - 100000), 0 disables poll delay
Return values
FTALK_SUCCESS Success
FTALK_ILLEGAL_ARGUMENT_ERR←- Argument out of range
OR
FTALK_ILLEGAL_STATE_ERROR Protocol is already open
Returns
Delay time in ms, 0 if poll delay is switched off
Note
A protocol must be closed in order to configure it.
Parameters
retries Retry count (Range: 0 - 10), 0 disables retries
Return values
FTALK_SUCCESS Success
FTALK_ILLEGAL_ARGUMENT_ERR←- Argument out of range
OR
FTALK_ILLEGAL_STATE_ERROR Protocol is already open
172
C++ Class Documentation
Returns
Retry count
Returns
Counter value
Returns
Counter value
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.
173
FieldTalk Modbus Master C++ Library: Software manual
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
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.
174
C++ Class Documentation
Remarks
This is the default mode
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
Note
Most platforms store floats in IEEE 754 little-endian order which does not need a
word swap.
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
175
FieldTalk Modbus Master C++ Library: Software manual
Note
This function call also re-configures the endianess to default little-endian for 32-bit
values!
Remarks
This is the default mode
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
Return values
FTALK_SUCCESS Success
FTALK_ILLEGAL_ARGUMENT_ERR←- Argument out of range
OR
Remarks
This is the default mode
Note
This function call also re-configures the endianess to default little-endian for 32-bit
values!
176
C++ Class Documentation
Note
This function call also re-configures the endianess to big-endian for 32-bit values
as defined by the Daniel/ENRON protocol!
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
Return values
FTALK_SUCCESS Success
FTALK_ILLEGAL_ARGUMENT_ERR←- Argument out of range
OR
Note
This function call also re-configures the endianess to big-endian for 32-bit values
as defined by the Daniel/ENRON protocol!
177
FieldTalk Modbus Master C++ Library: Software manual
Remarks
This is the default mode
Parameters
slaveAddr Modbus 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
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
178
C++ Class Documentation
Returns
Library version string
• MbusAsciiOverTcpMasterProtocol ()
Constructs a MbusAsciiOverTcpMasterProtocol object and initialises its data.
• int openProtocol (const char ∗const hostName)
Connects to a Modbus ASCII slave via TCP/IP.
• int setPort (unsigned short portNo)
Sets the TCP port number used to connect to the Modbus ASCII slave device.
• virtual void closeProtocol ()
Closes a TCP/IP connection to a slave and releases any system resources associated with the
connection.
• virtual int isOpen ()
Returns whether the protocol is open or not.
• unsigned short getPort ()
Returns the TCP port number used by the protocol.
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.
• int readInputDiscretes (int slaveAddr, int startRef, int bitArr[ ], int refCnt)
Modbus function 2, Read Inputs Status/Read Input Discretes.
• int writeCoil (int slaveAddr, int bitAddr, int bitVal)
Modbus function 5, Force Single Coil/Write Coil.
• int forceMultipleCoils (int slaveAddr, int startRef, const int bitArr[ ], int refCnt)
Modbus function 15 (0F Hex), Force Multiple Coils.
179
FieldTalk Modbus Master C++ Library: Software manual
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.
• int readInputRegisters (int slaveAddr, int startRef, short regArr[ ], int refCnt)
Modbus function 4, Read Input Registers.
• int writeSingleRegister (int slaveAddr, int regAddr, short regVal)
Modbus function 6, Preset Single Register/Write Single Register.
• int writeMultipleRegisters (int slaveAddr, int startRef, const short regArr[ ], int refCnt)
Modbus function 16 (10 Hex), Preset Multiple Registers/Write Multiple Registers.
• int maskWriteRegister (int slaveAddr, int regAddr, short andMask, short orMask)
Modbus function 22 (16 Hex), Mask Write Register.
• int readWriteRegisters (int slaveAddr, int readRef, short readArr[ ], int readCnt, int
writeRef, const short writeArr[ ], int writeCnt)
Modbus function 23 (17 Hex), Read/Write Registers.
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.
• 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.
• 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.
• int readMultipleFloats (int slaveAddr, int startRef, float float32Arr[ ], int refCnt)
Modbus function 3 for 32-bit float data types, Read Holding Registers/Read Multiple Regis-
ters as float data.
• 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.
• int writeMultipleFloats (int slaveAddr, int startRef, const float float32Arr[ ], int refCnt)
Modbus function 16 (10 Hex) for 32-bit float data types, Preset Multiple Registers/Write
Multiple Registers with float data.
• int 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.
• 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.
• 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.
180
C++ Class Documentation
Diagnostics
• int readExceptionStatus (int slaveAddr, unsigned char ∗statusBytePtr)
Modbus function 7, Read Exception Status.
• int returnQueryData (int slaveAddr, const unsigned char queryArr[ ], unsigned char
echoArr[ ], int len)
Modbus function code 8, sub-function 00, Return Query Data.
• int restartCommunicationsOption (int slaveAddr, int clearEventLog)
Modbus function code 8, sub-function 01, Restart Communications Option.
Protocol Configuration
• int setTimeout (int timeOut)
Configures time-out.
• int getTimeout ()
Returns the time-out value.
• int setPollDelay (int pollDelay)
Configures poll delay.
• int getPollDelay ()
Returns the poll delay time.
• int setRetryCnt (int retryCnt)
Configures the automatic retry setting.
• int getRetryCnt ()
Returns the automatic retry count.
181
FieldTalk Modbus Master C++ Library: Software manual
Slave Configuration
• void configureBigEndianInts ()
Configures 32-bit int data type functions to do a word swap.
• int configureBigEndianInts (int slaveAddr)
Enables int data type functions to do a word swap on a per slave basis.
• void configureLittleEndianInts ()
Configures 32-bit int data type functions not to do a word swap.
• int configureLittleEndianInts (int slaveAddr)
Disables word swapping for int data type functions on a per slave basis.
• void configureIeeeFloats ()
Configures float data type functions not to do a word swap.
• int configureIeeeFloats (int slaveAddr)
Disables float data type functions to do a word swap on a per slave basis.
• void configureSwappedFloats ()
Configures float data type functions to do a word swap.
• int configureSwappedFloats (int slaveAddr)
Enables float data type functions to do a word swap on a per slave basis.
• void configureStandard32BitMode ()
Configures all slaves for Standard 32-bit Mode.
• int configureStandard32BitMode (int slaveAddr)
Configures a slave for Standard 32-bit Register Mode.
• void configureEnron32BitMode ()
Configures all slaves for Daniel/ENRON 32-bit Mode.
• int configureEnron32BitMode (int slaveAddr)
Configures all slaves for Daniel/ENRON 32-bit Mode.
• void configureCountFromOne ()
Configures the reference counting scheme to start with one for all slaves.
• int configureCountFromOne (int slaveAddr)
Configures a slave's reference counting scheme to start with one.
• void configureCountFromZero ()
Configures the reference counting scheme to start with zero for all slaves.
• int configureCountFromZero (int slaveAddr)
Configures a slave's reference counting scheme to start with zero.
Utility Functions
182
C++ Class Documentation
See also
Data and Control Functions for all Modbus Protocol Flavours, IP based Protocols
MbusAsciiMasterProtocol
Note
The default time-out for the connection is 1000 ms.
Parameters
hostName String with IP address or host name
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error
codes.
Note
The default TCP port number is Telnet port 23.
183
FieldTalk Modbus Master C++ Library: Software manual
Sets the TCP port number used to connect to the Modbus ASCII slave device.
Usually the port number remains unchanged from its default. In this case no call to this
function is necessary. However if the port number has to be different, this function must
be called before opening the connection with openProtocol().
Parameters
port←- Port number to be used when opening the connection
No
Return values
FTALK_SUCCESS Success
FTALK_ILLEGAL_STATE_ERR←- Protocol already open
OR
Note
Defaults to 23 (Telnet port).
Return values
true = open
false = closed
Implements MbusMasterFunctions.
Returns
Port number used by the protocol
184
C++ Class Documentation
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
bitArr Buffer which will contain the data read
refCnt Number 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
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
bitArr Buffer which will contain the data read
refCnt Number 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.
185
FieldTalk Modbus Master C++ Library: Software manual
Note
No broadcast supported
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
bitAddr Coil address (Range: 1 - 65536)
bitVal true 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
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
startRef Start reference (Range: 1 - 65536)
bitArr Buffer which contains the data to be sent
refCnt Number of coils to be written (Range: 1-1968)
186
C++ Class Documentation
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error
codes.
Note
Broadcast supported for serial protocols
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start register (Range: 1 - 65536)
regArr Buffer which will be filled with the data read
refCnt Number 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
187
FieldTalk Modbus Master C++ Library: Software manual
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start register (Range: 1 - 65536)
regArr Buffer which will be filled with the data read.
refCnt Number 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
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
regAddr Register address (Range: 1 - 65536)
regVal Data 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
188
C++ Class Documentation
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
startRef Start register (Range: 1 - 65536)
regArr Buffer with the data to be sent.
refCnt Number 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
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255 for
serial, 0 - 255 for TCP)
regAddr Register address (Range: 1 - 65536)
andMask Mask to be applied as a logic AND to the register
orMask Mask to be applied as a logic OR to the register
189
FieldTalk Modbus Master C++ Library: Software manual
Note
No broadcast supported
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255 for
serial, 0 - 255 for TCP)
readRef Start register for reading (Range: 1 - 65536)
readArr Buffer which will contain the data read
readCnt Number of registers to be read (Range: 1-125)
writeRef Start register for writing (Range: 1 - 65536)
writeArr Buffer with data to be sent
writeCnt Number 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
190
C++ Class Documentation
int startRef,
int int32Arr[ ],
int refCnt ) [inherited]
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer which will be filled with the data read
refCnt Number of long 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
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).
191
FieldTalk Modbus Master C++ Library: Software manual
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer which will be filled with the data read
refCnt Number of long 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
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
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer with the data to be sent
refCnt Number of long integers to be sent (Range: 1-61)
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error
codes.
192
C++ Class Documentation
Note
Broadcast supported for serial protocols
References FTALK_ILLEGAL_ARGUMENT_ERROR.
Modbus function 3 for 32-bit float data types, Read Holding Registers/Read Multiple Reg-
isters 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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
float32Arr Buffer which will be filled with the data read
refCnt Number of float 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
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.
193
FieldTalk Modbus Master C++ Library: Software manual
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
float32Arr Buffer which will be filled with the data read
refCnt Number of floats 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
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
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
startRef Start reference (Range: 1 - 65536)
float32Arr Buffer with the data to be sent
refCnt Number of float values to be sent (Range: 1-61)
194
C++ Class Documentation
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.
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer which will be filled with the data read
refCnt Number 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
195
FieldTalk Modbus Master C++ Library: Software manual
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer which will be filled with the data read
refCnt Number 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
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.
196
C++ Class Documentation
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).
197
FieldTalk Modbus Master C++ Library: Software manual
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer with the data to be sent
refCnt Number of long integer 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.
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255 for
serial, 0 - 255 for TCP)
statusBytePtr Slave 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
198
C++ Class Documentation
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255 for
serial, 0 - 255 for TCP)
queryArr Buffer with data to be sent
echoArr Buffer which will contain the data read
len Number 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
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255 for
serial, 0 - 255 for TCP)
clearEventLog Flag 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.
199
FieldTalk Modbus Master C++ Library: Software manual
Note
No broadcast supported
References FTALK_ILLEGAL_ARGUMENT_ERROR.
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
msTime Timeout value in ms (Range: 1 - 100000)
Return values
FTALK_SUCCESS Success
FTALK_ILLEGAL_ARGUMENT_ERR←- Argument out of range
OR
FTALK_ILLEGAL_STATE_ERROR Protocol is already open
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.
200
C++ Class Documentation
Returns
Timeout value in ms
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
msTime Delay time in ms (Range: 0 - 100000), 0 disables poll delay
Return values
FTALK_SUCCESS Success
FTALK_ILLEGAL_ARGUMENT_ERR←- Argument out of range
OR
FTALK_ILLEGAL_STATE_ERROR Protocol is already open
Returns
Delay time in ms, 0 if poll delay is switched off
201
FieldTalk Modbus Master C++ Library: Software manual
Note
A protocol must be closed in order to configure it.
Parameters
retries Retry count (Range: 0 - 10), 0 disables retries
Return values
FTALK_SUCCESS Success
FTALK_ILLEGAL_ARGUMENT_ERR←- Argument out of range
OR
FTALK_ILLEGAL_STATE_ERROR Protocol is already open
Returns
Retry count
Returns
Counter value
202
C++ Class Documentation
Returns
Counter value
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
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
203
FieldTalk Modbus Master C++ Library: Software manual
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
Note
Most platforms store floats in IEEE 754 little-endian order which does not need a
word swap.
204
C++ Class Documentation
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
Note
This function call also re-configures the endianess to default little-endian for 32-bit
values!
Remarks
This is the default mode
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
205
FieldTalk Modbus Master C++ Library: Software manual
Return values
FTALK_SUCCESS Success
FTALK_ILLEGAL_ARGUMENT_ERR←- Argument out of range
OR
Remarks
This is the default mode
Note
This function call also re-configures the endianess to default little-endian for 32-bit
values!
Note
This function call also re-configures the endianess to big-endian for 32-bit values
as defined by the Daniel/ENRON protocol!
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
Return values
FTALK_SUCCESS Success
206
C++ Class Documentation
Return values
FTALK_ILLEGAL_ARGUMENT_ERR←- Argument out of range
OR
Note
This function call also re-configures the endianess to big-endian for 32-bit values
as defined by the Daniel/ENRON protocol!
Remarks
This is the default mode
Parameters
slaveAddr Modbus 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
207
FieldTalk Modbus Master C++ Library: Software manual
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.
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
Returns
Library version string
208
C++ Class Documentation
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.
• int readInputDiscretes (int slaveAddr, int startRef, int bitArr[ ], int refCnt)
Modbus function 2, Read Inputs Status/Read Input Discretes.
• int writeCoil (int slaveAddr, int bitAddr, int bitVal)
Modbus function 5, Force Single Coil/Write Coil.
• int forceMultipleCoils (int slaveAddr, int startRef, const int bitArr[ ], int refCnt)
Modbus function 15 (0F Hex), Force Multiple Coils.
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.
• int readInputRegisters (int slaveAddr, int startRef, short regArr[ ], int refCnt)
Modbus function 4, Read Input Registers.
• int writeSingleRegister (int slaveAddr, int regAddr, short regVal)
Modbus function 6, Preset Single Register/Write Single Register.
• int writeMultipleRegisters (int slaveAddr, int startRef, const short regArr[ ], int refCnt)
Modbus function 16 (10 Hex), Preset Multiple Registers/Write Multiple Registers.
• int maskWriteRegister (int slaveAddr, int regAddr, short andMask, short orMask)
Modbus function 22 (16 Hex), Mask Write Register.
• int readWriteRegisters (int slaveAddr, int readRef, short readArr[ ], int readCnt, int
writeRef, const short writeArr[ ], int writeCnt)
Modbus function 23 (17 Hex), Read/Write Registers.
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.
• 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.
• 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.
• int readMultipleFloats (int slaveAddr, int startRef, float float32Arr[ ], int refCnt)
209
FieldTalk Modbus Master C++ Library: Software manual
Modbus function 3 for 32-bit float data types, Read Holding Registers/Read Multiple Regis-
ters as float data.
• 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.
• int writeMultipleFloats (int slaveAddr, int startRef, const float float32Arr[ ], int refCnt)
Modbus function 16 (10 Hex) for 32-bit float data types, Preset Multiple Registers/Write
Multiple Registers with float data.
• int 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.
• 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.
• 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.
Diagnostics
• int readExceptionStatus (int slaveAddr, unsigned char ∗statusBytePtr)
Modbus function 7, Read Exception Status.
• int returnQueryData (int slaveAddr, const unsigned char queryArr[ ], unsigned char
echoArr[ ], int len)
Modbus function code 8, sub-function 00, Return Query Data.
• int restartCommunicationsOption (int slaveAddr, int clearEventLog)
Modbus function code 8, sub-function 01, Restart Communications Option.
Protocol Configuration
• int setTimeout (int timeOut)
Configures time-out.
• int getTimeout ()
Returns the time-out value.
• int setPollDelay (int pollDelay)
Configures poll delay.
• int getPollDelay ()
Returns the poll delay time.
210
C++ Class Documentation
Slave Configuration
• void configureBigEndianInts ()
Configures 32-bit int data type functions to do a word swap.
• int configureBigEndianInts (int slaveAddr)
Enables int data type functions to do a word swap on a per slave basis.
• void configureLittleEndianInts ()
Configures 32-bit int data type functions not to do a word swap.
• int configureLittleEndianInts (int slaveAddr)
Disables word swapping for int data type functions on a per slave basis.
• void configureIeeeFloats ()
Configures float data type functions not to do a word swap.
• int configureIeeeFloats (int slaveAddr)
Disables float data type functions to do a word swap on a per slave basis.
• void configureSwappedFloats ()
Configures float data type functions to do a word swap.
• int configureSwappedFloats (int slaveAddr)
Enables float data type functions to do a word swap on a per slave basis.
• void configureStandard32BitMode ()
Configures all slaves for Standard 32-bit Mode.
• int configureStandard32BitMode (int slaveAddr)
Configures a slave for Standard 32-bit Register Mode.
• void configureEnron32BitMode ()
Configures all slaves for Daniel/ENRON 32-bit Mode.
• int configureEnron32BitMode (int slaveAddr)
Configures all slaves for Daniel/ENRON 32-bit Mode.
• void configureCountFromOne ()
211
FieldTalk Modbus Master C++ Library: Software manual
Configures the reference counting scheme to start with one for all slaves.
• int configureCountFromOne (int slaveAddr)
Configures a slave's reference counting scheme to start with one.
• void configureCountFromZero ()
Configures the reference counting scheme to start with zero for all slaves.
• int configureCountFromZero (int slaveAddr)
Configures a slave's reference counting scheme to start with zero.
Utility Functions
• static const TCHAR ∗ getPackageVersion ()
Returns the library version number.
See also
Data and Control Functions for all Modbus Protocol Flavours, IP based Protocols
Note
The default time-out for the connection is 1000 ms.
212
C++ Class Documentation
Parameters
hostName String with IP address or host name
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error
codes.
Return values
true = open
false = closed
Implements MbusMasterFunctions.
Parameters
port←- Port number to be used when opening the connection
No
Return values
FTALK_SUCCESS Success
FTALK_ILLEGAL_STATE_ERR←- Protocol already open
OR
213
FieldTalk Modbus Master C++ Library: Software manual
Returns
Port number used by the protocol
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
bitArr Buffer which will contain the data read
refCnt Number 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
214
C++ Class Documentation
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
bitArr Buffer which will contain the data read
refCnt Number 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
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
bitAddr Coil address (Range: 1 - 65536)
bitVal true 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
215
FieldTalk Modbus Master C++ Library: Software manual
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
startRef Start reference (Range: 1 - 65536)
bitArr Buffer which contains the data to be sent
refCnt Number 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
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start register (Range: 1 - 65536)
regArr Buffer which will be filled with the data read
refCnt Number of registers to be read (Range: 1-125)
216
C++ Class Documentation
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error
codes.
Note
No broadcast supported
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start register (Range: 1 - 65536)
regArr Buffer which will be filled with the data read.
refCnt Number 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
217
FieldTalk Modbus Master C++ Library: Software manual
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
regAddr Register address (Range: 1 - 65536)
regVal Data 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
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
startRef Start register (Range: 1 - 65536)
regArr Buffer with the data to be sent.
refCnt Number 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
218
C++ Class Documentation
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255 for
serial, 0 - 255 for TCP)
regAddr Register address (Range: 1 - 65536)
andMask Mask to be applied as a logic AND to the register
orMask Mask to be applied as a logic OR to the register
Note
No broadcast supported
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255 for
serial, 0 - 255 for TCP)
readRef Start register for reading (Range: 1 - 65536)
readArr Buffer which will contain the data read
readCnt Number of registers to be read (Range: 1-125)
writeRef Start register for writing (Range: 1 - 65536)
219
FieldTalk Modbus Master C++ Library: Software manual
Parameters
writeArr Buffer with data to be sent
writeCnt Number 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
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer which will be filled with the data read
refCnt Number of long integers to be read (Range: 1-62)
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error
codes.
220
C++ Class Documentation
Note
No broadcast supported
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer which will be filled with the data read
refCnt Number of long 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
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).
221
FieldTalk Modbus Master C++ Library: Software manual
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
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer with the data to be sent
refCnt Number of long integers 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.
Modbus function 3 for 32-bit float data types, Read Holding Registers/Read Multiple Reg-
isters 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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
float32Arr Buffer which will be filled with the data read
refCnt Number of float values to be read (Range: 1-62)
222
C++ Class Documentation
Returns
FTALK_SUCCESS on success or error code. See Error Management for a list of error
codes.
Note
No broadcast supported
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
float32Arr Buffer which will be filled with the data read
refCnt Number of floats 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
223
FieldTalk Modbus Master C++ Library: Software manual
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
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
startRef Start reference (Range: 1 - 65536)
float32Arr Buffer with the data to be sent
refCnt Number of float 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.
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).
224
C++ Class Documentation
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer which will be filled with the data read
refCnt Number 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
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer which will be filled with the data read
refCnt Number 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.
225
FieldTalk Modbus Master C++ Library: Software manual
Note
No broadcast supported
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
slaveAddr Modbus address of slave device or unit identifier (Range: 0 - 255)
startRef Start reference (Range: 1 - 65536)
int32Arr Buffer with the data to be sent
refCnt Number of long integer 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.
226
C++ Class Documentation
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255 for
serial, 0 - 255 for TCP)
statusBytePtr Slave 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
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255 for
serial, 0 - 255 for TCP)
queryArr Buffer with data to be sent
echoArr Buffer which will contain the data read
len Number 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
227
FieldTalk Modbus Master C++ Library: Software manual
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255 for
serial, 0 - 255 for TCP)
clearEventLog Flag 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.
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
msTime Timeout value in ms (Range: 1 - 100000)
Return values
FTALK_SUCCESS Success
228
C++ Class Documentation
Return values
FTALK_ILLEGAL_ARGUMENT_ERR←- Argument out of range
OR
FTALK_ILLEGAL_STATE_ERROR Protocol is already open
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
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
msTime Delay time in ms (Range: 0 - 100000), 0 disables poll delay
229
FieldTalk Modbus Master C++ Library: Software manual
Return values
FTALK_SUCCESS Success
FTALK_ILLEGAL_ARGUMENT_ERR←- Argument out of range
OR
FTALK_ILLEGAL_STATE_ERROR Protocol is already open
Returns
Delay time in ms, 0 if poll delay is switched off
Note
A protocol must be closed in order to configure it.
Parameters
retries Retry count (Range: 0 - 10), 0 disables retries
Return values
FTALK_SUCCESS Success
FTALK_ILLEGAL_ARGUMENT_ERR←- Argument out of range
OR
FTALK_ILLEGAL_STATE_ERROR Protocol is already open
230
C++ Class Documentation
Returns
Retry count
Returns
Counter value
Returns
Counter value
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
231
FieldTalk Modbus Master C++ Library: Software manual
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
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
232
C++ Class Documentation
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
Note
Most platforms store floats in IEEE 754 little-endian order which does not need a
word swap.
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
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
233
FieldTalk Modbus Master C++ Library: Software manual
Note
This function call also re-configures the endianess to default little-endian for 32-bit
values!
Remarks
This is the default mode
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
Return values
FTALK_SUCCESS Success
FTALK_ILLEGAL_ARGUMENT_ERR←- Argument out of range
OR
Remarks
This is the default mode
Note
This function call also re-configures the endianess to default little-endian for 32-bit
values!
234
C++ Class Documentation
Note
This function call also re-configures the endianess to big-endian for 32-bit values
as defined by the Daniel/ENRON protocol!
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
Return values
FTALK_SUCCESS Success
FTALK_ILLEGAL_ARGUMENT_ERR←- Argument out of range
OR
Note
This function call also re-configures the endianess to big-endian for 32-bit values
as defined by the Daniel/ENRON protocol!
Remarks
This is the default mode
235
FieldTalk Modbus Master C++ Library: Software manual
Parameters
slaveAddr Modbus 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
Parameters
slaveAddr Modbus address of slave device or unit identifier (Range: 1 - 255). A
value of zero configures the behaviour for broadcasting.
Returns
Library version string
236
License
9 License
Library License
proconX Pty Ltd, Brisbane/Australia, ACN 104 080 935
Definitions
"Software" refers to the collection of files and any part hereof,
including, but not limited to, source code, programs, binary
executables, object files, libraries, images, and scripts, which are
distributed by proconX.
License Terms
237
FieldTalk Modbus Master C++ Library: Software manual
it on.
4. You are not required to accept this License, since You have not
signed it. However, nothing else grants You permission to use or
distribute the Software or its derivative works. These actions are
prohibited by law if You do not accept this License. Therefore, by
using or distributing the Software (or any work based on the
Software), You indicate your acceptance of this License to do so,
and all its terms and conditions for copying, distributing or
using the Software or works based on it.
5. You may not use the Software to develop products which can be used
as a replacement or a directly competing product of this Software.
6. Where source code is provided as part of the Software, You may
modify the source code for the purpose of improvements and defect
fixes. If any modifications are made to any the source code, You
will put an additional banner into the code which indicates that
modifications were made by You.
7. You may not disclose the Software's software design, source code
and documentation or any part thereof to any third party without
the expressed written consent from proconX.
8. This License does not grant You any title, ownership rights,
rights to patents, copyrights, trade secrets, trademarks, or any
other rights in respect to the Software.
9. You may not use, copy, modify, sublicense, or distribute the
Software except as expressly provided under this License. Any
attempt otherwise to use, copy, modify, sublicense or distribute
the Software is void, and will automatically terminate your rights
under this License.
10. The License is not transferable without written permission from
proconX.
11. proconX may create, from time to time, updated versions of the
Software. Updated versions of the Software will be subject to the
terms and conditions of this agreement and reference to the
Software in this agreement means and includes any version update.
12. THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING PROCONX,
THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE
"AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE
RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
13. ANY LIABILITY OF PROCONX WILL BE LIMITED EXCLUSIVELY TO REFUND OF
PURCHASE PRICE. IN ADDITION, IN NO EVENT UNLESS REQUIRED BY
APPLICABLE LAW OR AGREED TO IN WRITING WILL PROCONX OR ITS
PRINCIPALS, SHAREHOLDERS, OFFICERS, EMPLOYEES, AFFILIATES,
CONTRACTORS, SUBSIDIARIES, PARENT ORGANIZATIONS AND ANY COPYRIGHT
HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE
SOFTWARE AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL
DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE
(INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED
INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN
IF SUCH PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
14. IN ADDITION, IN NO EVENT DOES PROCONX AUTHORIZE YOU TO USE THIS
SOFTWARE IN APPLICATIONS OR SYSTEMS WHERE IT'S FAILURE TO PERFORM
CAN REASONABLY BE EXPECTED TO RESULT IN A SIGNIFICANT PHYSICAL
INJURY, OR IN LOSS OF LIFE. ANY SUCH USE BY YOU IS ENTIRELY AT
YOUR OWN RISK, AND YOU AGREE TO HOLD PROCONX HARMLESS FROM ANY
CLAIMS OR LOSSES RELATING TO SUCH UNAUTHORIZED USE.
15. This agreement constitutes the entire agreement between proconX
238
License
and You in relation to your use of the Software. Any change will
be effective only if in writing signed by proconX and you.
16. This License is governed by the laws of Queensland, Australia,
excluding choice of law rules. If any part of this License is
found to be in conflict with the law, that part shall be
interpreted in its broadest meaning consistent with the law, and
no other parts of the License shall be affected.
_________________________________________________________________
239
FieldTalk Modbus Master C++ Library: Software manual
10 Support
We provide electronic support and feedback for our FieldTalk products.
Please use the Support web page at: http://www.modbusdriver.com/support
Your feedback is always welcome. It helps improving this product.
240
Notices
11 Notices
Disclaimer:
proconX Pty Ltd makes no warranty for the use of its products, other than those expressly
contained in the Company's standard warranty which is detailed in the Terms and Condi-
tions located on the Company's Website. The Company assumes no responsibility for any
errors which may appear in this document, reserves the right to change devices or speci-
fications detailed herein at any time without notice, and does not make any commitment
to update the information contained herein. No licenses to patents or other intellectual
property of proconX are granted by the Company in connection with the sale of proconX
products, expressly or by implication. proconX products are not authorized for use as
critical components in life support devices or systems.
This FieldTalk™ library was developed by:
proconX Pty Ltd, Australia.
Copyright © 2002-2018. All rights reserved.
proconX and FieldTalk are trademarks of proconX Pty Ltd. Modbus is a registered trade-
mark of Schneider Automation Inc. All other product and brand names mentioned in this
document may be trademarks or registered trademarks of their respective owners.
241