Protocol:Modbus

From Serious Documentation
Revision as of 12:58, 25 November 2012 by Admin (talk | contribs) (Created page with "== What is Modbus? == See References for more information and training on Modbus. Modbus is a very simple master/slave communications protocol operate...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

What is Modbus?

See References for more information and training on Modbus.

Modbus is a very simple master/slave communications protocol operated traditionally over point-to-point RS232 or multi-drop RS485 networks.

It is designed to be operated in half-duplex mode, with one device, and one device only, designated the master that is responsible for polling and directing all the slaves. Slaves cannot spontaneously initiate data messages: they must be polled by the masters. Similarly, slaves cannot talk peer-to-peer to another slave. The master must poll one slave, gather data, and re-send it to another.

Every slave on a given network must have a unique identification number (slave ID). Slaves may occupy more than one slave ID (acting as multiple slaves in one physical device), but no slave IDs can overlap. Typically slaves can be very simple devices, like sensors or actuators, with a tiny DIP switch to manually select from a range of slave IDs.

The master has no id (although in some networks 0 is reserved for the master). This is because the slaves to not need to address the master explicitly, they always just respond to requests from the master.

Modbus Protocol Options: ASCII or Binary (RTU)

Modbus is a very simple set of packet protocol. There are 2 different Modbus transmission methods for each packet: ASCII or Binary (called "RTU"). When the ASCII and RTU packets are decoded, they contain exactly the same message contents. A software decoder can be written with two decoder/encoder front ends (one for ASCII, one for RTU) and the rest of the software can be unified.

The whole network is either designated ASCII or RTU. You cannot mix packet types. There is no negotiation process or auto-baud capabilities. The type must be set by the network/system designer once and all devices on the network must be manually set to the correct speed.

= Modbus ASCII

Modbus ASCII is a human-readable ASCII transmission format. Every master-initiated packet looks like this:

Byte Offset Description
0x00 ":" start-of-packet character
0x01-0x02 ASCII of slave id (for example, slave id 0x2F is sent as two characters "2" and "F")
0x03-0x04 ASCII of command (called a "function code", or "FCxx" where xx is the code)
... Command specific data as a sequence of ASCII characters (2 per byte), in MSB format
last-3,last-2 Simple 8-bit checksum
last-1,last CR-LF sequence terminating packet

Its advantages:

  • easy to debug on a sniffer terminal device (a device that only listens but does not drive the RS232 or RS485 cable) since a terminal program would display the packets
  • easy to parse in software, with a unique start character (':') and end sequence (CR-LF)
  • smaller/simpler software for the 8-bit checksum calculation than the 16-bit CRC used in RTU mode

Disadvantages:

  • half the speed of RTU: every byte is sent as a hex-ASCII value , it is half the speed of a binary transmission protocol.
  • less robust than RTU: an 8-bit checksum is far more susceptible to missing errors than the RTU's 16-bit CRC


Modbus RTU

For more information on the protocol, see the list of modbus references.



Modbus Slave RTU and Modbus Slave ASCII Protocols

Modbus is a very simple set of packet protocol. There are 2 different Modbus transmission methods for each packet:

The network is either designated ASCII or RTU. You cannot mix packet types. There is no negotiation process or autobauding capabilities. The type must be set by the network/system designer once and all devices on the network must be manually set to the correct speed.

MODBUS_SLAVE_ASCII is a human-readable ASCII transmission format and is easy to debug on a sniffer terminal device (a device that only listens but does not drive the RS232 or RS485 cable) since a terminal program would display the packets . It is very easy to parse in software, with a unique start character (':') and end sequence (CR-LF), but because every byte is sent as a hex-ascii value (for example, an 'a' is sent as two bytes '2' and '1', representing hex 0x21 which is an 'a'), it is half the speed of a binary transmission protocol.

For more information on the protocol, see the list of modbus references.



As a Modbus slave, the SIM (and the GUI within the SIM is polled by a Master on the network.