FieldTalk Modbus FAQ

General

Can we use the FieldTalk Modbus Master driver for multiple devices?

Yes. The master can talk to multiple slave devices which are identified by unique slave IDs or unit IDs. However if these slave devices are on the same serial line, they must be accessed sequentially because Modbus does not allow concurrent access. This means you query slave ID 1 first, then ID 2 and so forth.

Can we use multiple com ports for one driver?

Yes. The driver can be used with multiple interfaces on the same machine. The way this is accomplished is using multiple instances of the so called protocol objects — one instance for each interface. For example for a device with 4 COM ports, you would instantiate 4 MbusRtuProtocol objects and open them with COM1, COM2, COM3 and COM4 as parameter.

How much time is required to complete a Modbus query in RTU mode?

The library adds almost no overhead to the transaction time. The transaction time is determined by your baudrate, type of Modbus request (function code), number of values transferred and finally the slave response time.

What are the maximum number of data this Modbus Master library can query at one time?

The maximum number of data is limited by the Modbus specification, which requires a PDU not to exceed 253 bytes. This results in the following limits:

  • Read operation: 125 registers or 2000 coils
  • Write operation: 123 registers or 1968 coils

Can this product support multiple Modbus access to the same RS485 port at one time?

Yes, the library supports multi-drop on RS-485 ports. RS-485 allows up to 32 nodes on the bus. The number of RS-485 nodes can be extended using repeaters.

The library offers a RS-485 mode. In RS-485 mode, the RTS signal is used to enable and disable the transmitter of a RS232/RS485 converter. The RTS signal is asserted before sending data. It is cleared after the transmit buffer has been emptied and in addition a specified delay time has elapsed.

I have problems with COM ports larger than COM9 on Windows.

COM ports greater than nine are supported, but the naming must follow Microsoft's naming convention, which is for COM10:

\\.\COM10

When using this name in C++ or C# it needs escaping of the backslashes as follows:

openProtocol("\\\\.\\COM10")

A more technical explanation can be found here: http://support.microsoft.com/kb/115831

Addressing

How do I communicate with a sub-device using Modbus/TCP?

Assuming the sub-device is a serial Modbus device hanging off a bridge with a particular IP address (e.g. 192.168.0.104), the serial device will have a slave ID assigned which is passed as the first parameter. If the sub-device's slave ID is 5:

mbusProtocol.openProtocol("192.168.0.104");
mbusProtocol.readMultipleRegisters(5, 1, dataArr...

Does the slave address have any meaning when using Modbus/TCP?

In most situations it is not relevant. Most slave devices ignore this value completely. Only gateways and routers use it to identify the slave device connected on the serial network behind the gateway. If the value is not used, the Modbus standard recommends 255, however 1 also seems widely used.

Functions and Data Types

Why is readMultipleRegisters limited to 125 registers?

The limitation is imposed by the Modbus protocol specification:

The size of the MODBUS PDU is limited by the size constraint inherited from the first MODBUS implementation on Serial Line network (max. RS485 ADU = 256 bytes). Therefore: MODBUS PDU for serial line communication = 256 − Server address (1 byte) − CRC (2 bytes) = 253 bytes.

— Modbus Application Protocol Specification V1.1b, Modbus-IDA

This leads to the limitation of a maximum of 125 registers for the readMultipleRegisters function. To read more data, you have to split it up into two consecutive readMultipleRegisters calls.

Which FieldTalk function should I use for Modicon TSX Micro variables?

Variable Master Function Call
%M readCoils()
%M writeCoil()
%M forceMultipleCoils()
%I readInputDiscretes()
%IW readInputRegisters()
%MW writeMultipleRegisters()
%MW readMultipleRegisters()
%MW writeSingleRegister()
%MW maskWriteRegister()
%MW readWriteRegisters()

As the TSX uses 0-based numbering, you must add an offset of one to the register address used with FieldTalk functions. (FieldTalk uses 1-based numbering.)

What's the difference between ReadCoils and ReadInputDiscretes?

Both functions are very similar, however they operate on different data tables in the slave device:

  • Coils refer to a read/write data table (0:0000)
  • Input Discretes refer to a read-only data table (1:0000)
  • ReadCoils uses Modbus function 1 to retrieve the data
  • ReadInputDiscretes uses Modbus function 2 to retrieve the data

Refer to your slave device's documentation to determine which function to use. Some slave devices don't distinguish between the two data tables, in which case both functions do the same thing.

Does FieldTalk Modbus Master .NET support "UShort" in place of "Short" to read unsigned registers?

If your slave device uses unsigned data, use typecasting as follows:

VB.net

Dim dataArr(10) As UInt16

result = mbusProtocol.readMultipleRegisters(1, 100, CType(dataArr, System.Array))

C#

UInt16[] dataArr = new UInt16[10];

result = mbusProtocol.readMultipleRegisters(1, 100, (short[]) (System.Array) dataArr);

Error Return Codes and Exceptions

What normally causes error 68 "TCP/IP connection error"?

This return code indicates that the TCP/IP connection could not be established.

Typical reasons:

  • Issues with the physical network cabling
  • Wrong IP address or host name
  • Modbus slave device is not present on the network
  • Modbus slave device is not listening on TCP port 502
  • A firewall is enabled but not configured for Modbus data pass-through

How to diagnose and resolve:

  • Test if the IP address or host name can be pinged using the ping command.
  • Disable any firewall software to prevent interference. Most firewalls block port 502 by default. Once Modbus communication is working, configure the firewall for pass-through on port 502.
  • Test if port 502 can be reached using telnet:
    telnet slave_ip_address 502
    If telnet shows an error like the one below, the Modbus slave cannot be reached:
    Connecting To 127.0.0.1...Could not open connection to the host, on port 502:
    Connect failed
    If telnet starts and shows an empty screen, the connection was established and Modbus/TCP should work. (Exit telnet with Ctrl-]q)

Compilation Issues

I have linker errors LNK2028 and LNK2019 when compiling managed C++ code in a Windows Forms application.

  1. In Configuration → Properties → General, set Common Language Runtime Support to /clr (instead of /clr:pure)
  2. Add Ws2_32.lib as an additional dependency to the linker

Using both FieldTalk Modbus Master and Slave Library for .NET in the same application

When referencing the assemblies, change the alias for mbusmaster.net.dll from "global" to "Master" and for mbusslave.net.dll from "global" to "Slave".

Then in your code add the alias declaration as shown here:

extern alias Slave;
extern alias Master;
using Master::FieldTalk;
using Slave::FieldTalk;
using MasterErrors = Master::FieldTalk.BusProtocolErrors;
using SlaveErrors = Slave::FieldTalk.BusProtocolErrors;

And use the alias to differentiate between the two BusProtocolError classes:

if (result != MasterErrors.FTALK_SUCCESS) ...