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 a 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 require a PDU not to exceed 253 bytes. This requirement 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 Microsofts' 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 for this very confusing matter can be found here: http://support.microsoft.com/kb/115831
Addressing
-
I would like to find how do I communicate with a sub-device using your TCP/IP Modbus Master Protocol
I assume the sub device is a serial Modbus device hanging off a bridge device with a particluar IP address (e.g. 192.168.0.104). The serial Modbus device will have a so called slave ID assigned which is passed to the requests sent to the bridge device as the first parameter. If the subdevice' slave ID is 5, you would issue the following command sequence:
mbusProtocol.openProtocol("192.168.0.104"); mbusProtocol.readMultipleRegisters(5, 1, dataArr...
-
Does the slave address have any meaning when using Modbus/TCP protocol
In most situations it is not relevant. Most slave devices are ignoring this value completly. Only gateways and routers are using it to identify the slave device connected on the serial network behind the gateway. If the value is not used, the Modbus standard recommends to use the value 255, however the value of 1 seems also widley used.
Functions and data types
-
Why is readMultipleRegisters limited to 125 registers
The limitation is imposed by the Modbus protocol:
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-IDAThis 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 is using 0 based numbering, you must add an offset of one to the register address used with FieldTalk functions. (FieldTalk is using 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 is using Modbus function 1 to retrieve the data
-
ReadInputDiscretes is using Modbus function 2 to retrieve the data
Please refer to your slave device’s documentation on which of the function you are supposed to use. Some slave devices don’t make the distinction between the two data tables and in that case both functions will do the same thing.
-
-
Does FieldTalk Modbus Master .NET support "UShort" in place of "Short" in a function to read unsigned registers
If your slave device is using unsigned data, then please use typecasting as follow:
VB.netDim 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 from the command line. -
Disable any firewall software or Internet protection software to prevent interference with the communication. Most firewalls will block port 502 by default. Once Modbus communication is working, the firewall can be configured for pass-through of port 502 and re-enabled.
-
Test if port 502 can be reached by using the
telnet
command from the command line:telnet slave_ip_address 502
If telnet shows an error message similar to the one below, the Modbus slave cannot be reached due to network problems or firewalling. Check your network cabling and configuration.
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 as well. (You can exit telnet using the key combination
Ctrl-]q
)
-
Compilation Issues
-
I have linker errors LNK2028 and LNK2019 when compiling from managed C++ code in a Windows Forms application
-
In
Configuration→Properties→General
, setCommon Language Runtime Support
to/clr
(instead of/clr:pure
) -
Add
Ws2_32.lib
as an additional dependency to the linker
-
Documentation Issues
-
The Windows Help file (.chm) does not display any content
This problem is caused by security updates introduced with Windows XP.
To view the CHM file, try the following:
-
Clear the Always ask before opening this file check box in the Open File-Security Warning dialog box that Windows XP displays when opening the CHM file.
-
Right click on the property of the file and click Unblock.
-
CHM files cannot be viewed on a shared drive. Download or copy this file to a local drive on your PC, then it will view properly.
Refer to http://support.microsoft.com/kb/902225/ in the Microsoft knowledgebase.
-
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 like:
if (result != MasterErrors.FTALK_SUCCESS) ...