Modbus standard also defines Modbus over Serial Line, a protocol over the
data link layer of the OSI model for the Modbus application layer protocol to be communicated over a
serial bus. Modbus Serial Line protocol is a
master-slave protocol which supports one master and multiple slaves in the serial bus. With Modbus protocol on the application layer, client/server model is used for the devices on the communication channel. With Modbus over Serial Line,
client role is implemented by
master, and the
server role is implemented by
slave. The organization's naming convention inverts the common usage of having multiple clients and only one server. To avoid this confusion, the RS-485 transport layer uses the terms "node" or "device" instead of "server", and the "client" is not a "node". A serial bus for Modbus over Serial Line can have a maximum of 247 slaves communicating with one master. Those slaves have a unique address ranging from 1 to 247 (01hex to F7hex). The addresses from 248 to 255 (F8hex … FFhex) are reserved and must not be used. The master doesn't need to have an address. The communication process is initiated by the master, as only it can initiate a Modbus transaction. A slave will never transmit any data or perform any action without a request from the master, and slaves cannot communicate with each other. In Modbus over Serial Line, the master initiates requests to the slaves in
unicast or
broadcast modes. In
unicast mode, the master will initiate a request to a single slave with a specific address. Upon receiving and finishing the request, the slave will respond with a message to the master. In this mode, a Modbus transaction includes two messages: one request from the master and one reply from the slave. Each slave must have a unique address (from 1 to 247) to be addressed independently for the communication. In
broadcast mode, the master can send a request to all the slaves, using the broadcast address 0, which is the address reserved for broadcast exchanges (and not the master address). Slaves must accept broadcast exchanges but must not respond. The mapping of PDU of Modbus to the serial bus of Modbus over Serial Line protocol results in Modbus Serial Line PDU. Modbus Serial Line PDU = Address + PDU + CRC (or LRC) With PDU = Function code + data • Address is slave address • PDU is defined identically to the PDU of Modbus Application protocol • The Error check field with CRC/LRC: The error check methods depend on the protocol versions of the MODBUS over Serial Line, whether it is
Modbus RTU or
Modbus ASCII. On the
physical layer, MODBUS over Serial Line performs its communication on bit by
RS485 or
RS232, with TIA/EIA-485 Two-Wire interface as the most popular way. RS485 Four-Wire interface is also used. TIA/EIA-232-E (RS232) can also be used but is limited to point-to-point short-range communication. MODBUS over Serial Line has two transmission modes
RTU and
ASCII which are corresponded to two versions of the protocol, known as
Modbus RTU and
Modbus ASCII.
Modbus RTU Modbus RTU (Remote Terminal Unit), which is the most common implementation available for Modbus, makes use of a compact, binary representation of the data for protocol communication. The RTU format follows the commands/data with a
cyclic redundancy check checksum as an error check mechanism to ensure the reliability of data. A Modbus RTU message must be transmitted continuously without inter-character hesitations. Modbus messages are framed (separated) by idle (silent) periods. Each byte (8 bits) of data is sent as 11 bits: • 1 start bit • 8 bit data/message, least significant bit sent first • 1 bit parity • 1 stop bit The default is even parity, while odd or no parity may be implemented as additional options. A Modbus RTU frame then will be: The CRC calculation is widely known as CRC-16-MODBUS, whose polynomial is
x16 +
x15 +
x2 + 1 (normal hexadecimal algebraic polynomial being 8005 and reversed A001). Example of a Modbus RTU frame in hexadecimal: 01 04 02 FF FF B8 80 (CRC-16-MODBUS calculation for the 5 bytes from 01 to FF gives 80B8, which is transmitted least significant byte first). To ensure frame integrity during the transmission, the time interval between two frames must be at least the transmission time of 3.5 characters, and the time interval between two consecutive characters must be no more than the transmission time of 1.5 characters. For example, with the default data rate of 19200 bit/s, the transmission times of 3.5 (t3.5) and 1.5 (t1.5) 11-bit characters are: t3.5 = 3.5 \cdot \left( \frac{11 \cdot 1000}{19200} \right)= 2.005 \, \mathrm{ms} t1.5 = 1.5 \cdot \left( \frac{11 \cdot 10^6}{19200} \right)= 859.375 \, \mathrm{\mu s} For higher data rates, Modbus RTU recommends to use the fixed values 750 μs for t1.5 and 1.750 ms for t3.5.
Modbus ASCII Modbus ASCII makes use of
ASCII characters (chars) for protocol communication. The ASCII format uses a
longitudinal redundancy check checksum. Modbus ASCII messages are framed by a leading colon (":", ASCII value 3A16) and trailing newline (CR/LF, ASCII values 0D16 and 0A16). Modbus ASCII frame do not need to be sent in bursts like Modbus RTU, a delay up to 1 second is permitted between each character transmission by default. Each ASCII character is sent as 10 bits: • 1 start bit • 7 bit ASCII character, least significant bit sent first • 1 bit parity • 1 stop bit The default is even parity, while odd or no parity may be implemented as additional options. A Modbus ASCII frame includes: Address, Function, Data, and LRC are ASCII hexadecimal encoded values, whereby each byte (8 bits) of information is encoded as two human-readable ASCII characters from the ranges 0–9 and A–F. For example, a byte value of 122 ( or ) is encoded as two ASCII characters, "7" and "A", and transmitted as two bytes, 55 (3716, ASCII value for "7") and 65 (4116, ASCII value for "A"). LRC is calculated as the sum of 8-bit values (excluding the start and end characters), negated (
two's complement) and encoded as an 8-bit value. For example, if Address, Function, and Data are 247, 3, 19, 137, 0, and 10, the two's complement of their sum (416) is −416; this trimmed to 8 bits is 96 (256 × 2 − 416 = 6016), giving the following 17 ASCII character frame: :F7031389000A60␍␊. LRC is specified for use only as a checksum: because it is calculated on the encoded data rather than the transmitted characters, its 'longitudinal' characteristic is not available for use with parity bits to locate single-bit errors. == Modbus messaging on TCP/IP ==