[newbie] help regarding modbus communication

4 posts in this topic

I need help regarding setting up modbus communication between Allen bradley micrologix 1400 and Schneider altivar312 vfd and rslinx for pc. I am totally stuck with it. 

Share this post

Link to post
Share on other sites

You'll need to be more specific, there are many different versions of Modbus communication protocols.

RTU, TCP, etc...

Share this post

Link to post
Share on other sites
14 hours ago, pcmccartney1 said:

You'll need to be more specific, there are many different versions of Modbus communication protocols.

RTU, TCP, etc...

How should one determine whether to use modbus rtu, tcp, ascii...? 

Share this post

Link to post
Share on other sites

1) Modbus is a Project

Modbus is NOT plug-n-play; it is always a project.  It is not feasible to provide details about specific connections between this brand/model to that brand/model because of the number of possible combinations of the 100,000 Modbus-enabled devices out there.   

2) What is Modbus?

Modbus is a protocol, the set of rules for who talks when (who is silent), rules for packing the data, how to tell when transmission starts, when it ends, what constitutes an error.   Modbus does not define what kind of data is transmitted nor does it define the format of the data (the product vendor defines the data format).   Modbus has a specification for serial communications, which in some cases is ignored despite explicit requirements.

3)  ASCII vs RTU vs TCP

Modbus ASCII was widely used when telephone modems were used for the serial network link and it has very loose timing requirements, which fit the realities of modem communication.   It is NOT human readable ASCII, it uses binary values of the ASCII characters representing the hexadecimal characters that represent the 16 bits of a Modbus register.  The following ASCII string shows a Master query request to slave 17 for the analog output values in 3 holding registers starting at (4)0108 to prove this "non human readable" point:        : 1 1 0 3 0 0 6 B 0 0 0 3 7 E CR LF

Modbus ASCII takes almost double the number of bits to communicate the same amount of data.   In my opinion, the use for Modbus ASCII is in wireless which has many of the same timing delays that telephone communication had 25 years ago.

Modbus RTU is the dominant protocol used nowadays for serial communication over RS-232 point-to-point up to 15m or RS-485 for multidrop up to 1200m.  It has much stricter timing requirements that usually don't offer a stumbling block.  

Modbus over Ethernet is referred to as Modbus/TCP.
Ethernet, by design, has isolation, so it has a huge advantage over RS-485 which does not.
Ethernet, by design, is limited by spec to 100m of cable.  That can be exceeded in non-critical applications but it needs to be taken into account.  Extension by switches is feasible
Ethernet, by design, has standardized connectors with standardized wire connection.   Plug in the commercial cable and it works.
Ethernet, by design, supports infrastructure above and beyond the 485 multidrop limits.

If I have a choice, I'll use Modbus/TCP over Ethernet because it is usually easy to setup and get connected.

5) RS-485

RS-485's problems are
- 2 wire 485 is a misnomer.  A signal ground is needed.  So 2 wire 485 is really 3 wire 485.  But many products do not have a signal ground terminal.
- lack of a signal ground terminal so grounding devolves to case ground connections which has the issue of creating a common mode ground loop.  Ground loop problems are solved by adding an isolator module.
- RS-485 lacks isolation from ground  
- where does the bias come from or what is the access to the supply voltage or ground if a bias resistor is needed?  Mostly a mystery unless the system is designed from the ground up, like Profibus DP, which takes biasing and termination into account.
- no industry standard on data/drive line labeling (A/B, (+)/(-)).  Backwards connection does not damage the lines, but will not work.  Annoying, but easy to fix by swapping the lines.
- field implementation with cable that is not specifically communications cable.
- field implementation with spurs or a star topology which 485 can't handle
- Most Modbus masters cannot handle duplex (4 wire) communication so simplex (2 wire) works for the master/slave sequence in Modbus.
implementations of slave node ID address and serial comm settings (word size, baud rate, parity, stop bits) is all over the map.  Some mechanical (DIP or rotary switches or jumpers); some firmware setup.

6)  Who is Master?  Who is Slave?

A drive is always a Modbus slave.  So the PLC has to be the Modbus master.

Which network will you use?  RS-485?  Ethernet?
You need to check into what firmware/hardware/licensing is needed to get a Modbus Master for the hardware network you need to use.  It varies from vendor to vendor.
It pays to check the Modbus documentation.  Is it 1/2 a page or 20 pages with examples?  It's what you'll have to work with.  

7)  Slave

A slave is always silent until it is spoken to and then it interprets the master's command and either accepts data to be written internally or replies with the data requested.

The slave documentation needs to
- specify which Modbus commands (Function codes) it works with
- spell out what data is available
- at which register address the data resides
- the data format
- limitations, like a maximum number of values acceptable in one write transaction

Slaves frequently do not recognize serial setting changes until the power is cycled

All slaves need a unique network node ID address number

8)  Master
Master Tasks
- The master has to issue the instructions (Function Codes) and accept the replies.   
- It has interpret the binary bits, sometimes converting from one format to another.
- It has to do something with the data the Master receives, typically moving the data to working registers.

9)  Modbus in general

A) Register/addressing - the one offset issue.

Some devices start register/addressing at zero. Others start at one. So the holding register at (4)0109, might actually be at 0108.

The leading numeral in register references, the (4) in (4)0109, is not part of the Modbus message.  It is a convention used so that humans (and some software) can distinguish between memory areas served by different function codes.  For instance, Function code 03 reads holding registers in the (4)xxxxx memory area.  Function code 04 reads input registers in the (3)xxxxx memory area.    

I put the leading numeral in parentheses to indicate that it is not part of the message (the register address is part of the message)

Some master/client use the leading numeral to designate which Function Code to use. Others require defining which Function code and then (typically) only want the indexed value (minus the leading numeral).

B)  Floating point/real values

If your slave uses floating point, it is undoubtedly IEEE 754 formatted.  There are 4 different byte orders, but I've only ever seen two of those in popular use.  Somewhere in the master's software there's a setting for whether a floating point value is interpreted straight or swapped byte/word order. If the wrong choice is used the data value will be wildly wrong, like the value 156.32 will be a ridiculous value like 1.26842274 E11.

C)  Integer with decimal point

Integers (whole numbers) are frequently assigned a multiplier (by the slave's vendor).   For instance 156.32 will transmit as 15632 with an assigned multiplier of 0.01.   The assigned multiplier is not part of the Modbus message, it is defined in the slave documentation

D)  Generic master/client

I really recommend using a PC based generic Modbus master, something like Modscan 32, Modpoll or Simply Modbus to 'prove' a connection between the master and slave, because of the number of settings that can hinder a working connection. There are few settings in the generic masters. There are other freebie generics out there.

Start by reading a known value (non-zero) from a register. Make sure that the value is what you expect, to confirm that you're not reading one register off. Unused registers are frequently zeroed out, which makes zero a bad value to expect.

Most PLC vendors seem to have a documented example of setup as a master or slave somewhere on the web.



Edited by DanW
2 people like this

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now