Modbus Rtu Pdf

  1. Modbus TCP/IP (also Modbus-TCP) is simply the Modbus RTU protocol with a TCP interface that runs on Ethernet. The Modbus messaging structure is the application protocol that defines the rules for organizing and interpreting the data independent of the data transmission medium.
  2. Controller, using the Modbus RTU (Remote Terminal Unit) protocol. For detailed information about Modbus communication, refer to Modbus Application Protocol Specifications V1.1b from www.modbus.org RS-485 Communication The Electronics Industry Association (EIA) established the RS-485 standard as a guide for developing a.
  3. 11: MODBUS/TCP MODBUS/TCP is a communication protocol designed to allow industrial equipment such as Programmable Logic Controllers, computers, operator panels, motors, sensors, and other types of physical input/output devices to communicate over a network. Modbus/TCP was invented by Modicon/Group Schneider and is today is one of the most popular.
  4. S7 OPEN MODBUS / TCP Communication via the integrated PN interface of the PLC Manual Edition 2.1 Preface, Table of Contents. The manuals are also available as PDF files on CD. Modbus MODBUS / TCP communication via the integrated PN interface of the CPU.
  5. The Modbus RTU is designed to communicate with any controller that supports the interfaces defined in this document. It is assumed that you have full knowledge of the capabilities and limitations of the controller. Modbus RTU Overview Modbus RTU (Remote Terminal Unit) protocol defines a message structure that controllers will recognise.
  6. In the MODBUS protocol the master can address individual slaves, or, using a special “Broadcast” address, can initiate a broadcast message to all slaves. The SPR and Integra products do not support the broadcast address. MODBUS Message Format The MODBUS protocol defines the format for the master’s query and the slave’s response.

Elsewhere we've used this same temperature sensor. Read a MODBUS temperature sensor through USB-RS485 adapter on Ubuntu and Raspberry Pi; Overview of a simple MODBUS/RTU RS-485 temperature sensor; This device is cheap enough that it's a small price-of-entry to experimenting with MODBUS on the Arduino.

Modbus Rtu Communication Protocol Pdf

MODBUS© Protocol is a messaging structure, widely used to establishmaster-slave communication between intelligent devices. A MODBUS message sentfrom a master to a slave contains the address of the slave, the 'command' (e.g.'read register' or 'write register'), the data, and a check sum (LRC or CRC).
Since Modbus protocol is just a messaging structure, it is independent of theunderlying physical layer. It is traditionally implemented using RS232, RS422,or RS485

The Request
The function code in the request tells the addressed slave device what kind ofaction to perform. The data bytes contains any additional information that theslave will need to perform the function. For example, function code 03 willrequest the slave to read holding registers and respond with their contents. Thedata field must contain the information telling the slave which register tostart at and how many registers to read. The error check field provides a methodfor the slave to validate the integrity of the message contents.

The Response
If the slave makes a normal response, the function code in the response is anecho of the function code in the request. The data bytes contain the datacollected by the slave, such as register values or status. If an error occurs,the function code is modified to indicate that the response is an errorresponse, and the data bytes contain a code that describes the error. The errorcheck field allows the master to confirm that the message contents are valid.

Controllers can be setup to communicate on standard Modbus networks usingeither of two transmission modes: ASCII or RTU.

ASCII Mode
When controllers are setup to communicate on a Modbus network using ASCII(American Standard Code for Information Interchange) mode, each eight-bit bytein a message is sent as two ASCII characters. The main advantage of this mode isthat it allows time intervals of up to one second to occur between characterswithout causing an error.

C# Modbus Rtu

Coding System
Hexadecimal ASCII printable characters 0 ... 9, A ... F
Bits per Byte
1 start bit
7 data bits, least significant bit sent first
1 bit for even / odd parity-no bit for no parity
1 stop bit if parity is used-2 bits if no parity
Error Checking
Longitudinal Redundancy Check (LRC)

RTU Mode
When controllers are setup to communicate on a Modbus network using RTU (RemoteTerminal Unit) mode, each eight-bit byte in a message contains two four-bithexadecimal characters. The main advantage of this mode is that its greatercharacter density allows better data throughput than ASCII for the same baudrate. Each message must be transmitted in a continuous stream.

Coding System
Eight-bit binary, hexadecimal 0 ... 9, A ... F
Two hexadecimal characters contained in each eight-bit field of the message
Bits per Byte
1 start bit
8 data bits, least significant bit sent first
1 bit for even / odd parity-no bit for no parity
1 stop bit if parity is used-2 bits if no parity
Error Check Field
Cyclical Redundancy Check (CRC)

In ASCII mode, messages start with a colon ( : ) character (ASCII 3A hex),and end with a carriage return-line feed (CRLF) pair (ASCII 0D and 0A hex).
The allowable characters transmitted for all other fields are hexadecimal 0 ...9, A ... F. Networked devices monitor the network bus continuously for the coloncharacter. When one is received, each device decodes the next field (the addressfield) to find out if it is the addressed device.
Intervals of up to one second can elapse between characters within the message.If a greater interval occurs, the receiving device assumes an error hasoccurred. A typical message frame is shown below.

StartAddressFunctionDataLRCEnd
:2 Chars2 CharsN Chars2 CharsCR LF


RTU Framing
In RTU mode, messages start with a silent interval of at least 3.5 charactertimes. This is most easily implemented as a multiple of character times at thebaud rate that is being used on the network (shown as T1-T2-T3-T4 in the figurebelow). The first field then transmitted is the device address.
The allowable characters transmitted for all fields are hexadecimal 0 ... 9, A... F. Networked devices monitor the network bus continuously, including duringthe silent intervals. When the first field (the address field) is received, eachdevice decodes it to find out if it is the addressed device.
Following the last transmitted character, a similar interval of at least 3.5character times marks the end of the message. A new message can begin after thisinterval.
The entire message frame must be transmitted as a continuous stream. If a silentinterval of more than 1.5 character times occurs before completion of the frame,the receiving device flushes the incomplete message and assumes that the nextbyte will be the address field of a new message.
Similarly, if a new message begins earlier than 3.5 character times following aprevious message, the receiving device will consider it a continuation of theprevious message. This will set an error, as the value in the final CRC fieldwill not be valid for the combined messages. A typical message frame is shownbelow.

StartAddressFunctionDataCRCEnd
3.5 Char time8 Bit8 BitN * 8Bit16 Bit3.5 Char time

Address Field
The address field of a message frame contains two characters (ASCII) or eightbits (RTU). The individual slave devices are assigned addresses in the range of1 ... 247.

Function Field

The Function Code field tells the addressed slave what function to perform.
The following functions are supported by Modbus poll

01 READ COIL STATUS
02 READ INPUT STATUS
03 READ HOLDING REGISTERS
04 READ INPUT REGISTERS
05 WRITE SINGLE COIL
06 WRITE SINGLE REGISTER
15 WRITE MULTIPLE COILS
16 WRITE MULTIPLE REGISTERS

The data field contains the requested or send data.

Contents of the Error Checking Field
Two kinds of error-checking methods are used for standard Modbus networks. Theerror checking field contents depend upon the method that is being used.

ASCII
When ASCII mode is used for character framing, the error-checking field containstwo ASCII characters. The error check characters are the result of aLongitudinal Redundancy Check (LRC) calculation that is performed on the messagecontents, exclusive of the beginning colon and terminating CRLF characters.
The LRC characters are appended to the message as the last field preceding theCRLF characters.
LRC Example Code

RTU
When RTU mode is used for character framing, the error-checking field contains a16-bit value implemented as two eight-bit bytes. The error check value is theresult of a Cyclical Redundancy Check calculation performed on the messagecontents.
The CRC field is appended to the message as the last field in the message. Whenthis is done, the low-order byte of the field is appended first, followed by thehigh-order byte. The CRC high-order byte is the last byte to be sent in themessage.
CRC Example Code

Function 01 (01hex) Read Coils

Reads the ON/OFF status of discrete coils in the slave.

Request
The request message specifies the starting coil and quantity of coils to be read.

Example of a request to read 10...22 (Coil 11 to 23) from slave device address 4:

Field NameRTU (hex)ASCII Characters
HeaderNone: (Colon)
Slave Address040 4
Function010 1
Starting Address Hi000 0
Starting Address Lo0A0 A
Quantity of Coils Hi000 0
Quantity of Coils Lo0D0 D
Error Check LoDDLRC (E 4)
Error Check Hi98
TrailerNoneCR LF
Total Bytes817
Modbus Rtu Pdf

Response
The coil status response message is packed as one coil per bit of the data field. Status is indicated as: 1 is the value ON, and 0 is the value OFF. The LSB of the first data byte contains the coil addressed in therequest. The other coils follow toward the high-order end of this byte and from low order to high order in subsequent bytes. If the returned coil quantity is not a multiple of eight, the remaining bits in the final data byte will be padded with zeroes (toward the high-order end of the byte). The byte count field specifies the quantity of complete bytes of data.

Example of a response to the request:

Field NameRTU (hex)ASCII Characters
HeaderNone: (Colon)
Slave Address040 4
Function010 1
Byte Count020 2
Data (Coils 7...10)0A0 A
Data (Coils 27...20)111 1
Error Check LoB3LRC (D E)
Error Check Hi50None
TrailerNoneCR LF
Total Bytes715

Function 02(02hex) Read Discrete Inputs

Reads the ON/OFF status of discrete inputs in the slave.

Request
The request message specifies the starting input and quantity of inputs to be read.

Example of a request to read 10...22 (input 10011 to 10023) from slave device address 4:

Field NameRTU (hex)ASCII Characters
HeaderNone: (Colon)
Slave Address040 4
Function020 2
Starting Address Hi000 0
Starting Address Lo0A0 A
Quantity of inputs Hi000 0
Quantity of inputs Lo0D0 D
Error Check Lo99LRC (E 3)
Error Check Hi98
TrailerNoneCR LF
Total Bytes817

Response
The input status response message is packed as one input per bit of the data field. Status is indicated as: 1 is the value ON, and 0 is the value OFF. The LSB of the first data byte contains the input addressed in therequest. The other inputs follow toward the high-order end of this byte and from low order to high order in subsequent bytes. If the returned input quantity is not a multiple of eight, the remaining bits in the final data byte will be padded with zeroes (toward the high-order end of the byte). The byte count field specifies the quantity of complete bytes of data.

Example of a response to the request:

Field NameRTU (hex)ASCII Characters
HeaderNone: (Colon)
Slave Address040 4
Function020 2
Byte Count020 2
Data (Inputs 17...10)0A0 A
Data (Inputs 27...20)111 1
Error Check LoB3LRC (D D)
Error Check Hi14None
TrailerNoneCR LF
Total Bytes715

Function 03 (03hex) Read Holding Registers

Read the binary contents of holding registers in the slave.

Request
The request message specifies the starting register and quantity of registers to be read.

Example of a request to read 0...1 (register 40001 to 40002) from slave device 1:

Field NameRTU (hex)ASCII Characters
HeaderNone: (Colon)
Slave Address010 1
Function030 3
Starting Address Hi000 0
Starting Address Lo000 0
Quantity of Registers Hi000 0
Quantity of Registers Lo020 2
Error Check LoC4LRC (F A)
Error Check Hi0B
TrailerNoneCR LF
Total Bytes817

Response
The register data in the response message are packed as two bytes per register, with the binary contents right justified within each byte. For each register the first byte contains the high-order bits, and the second contains the low-order bits.

Example of a response to the request:

Field NameRTU (hex)ASCII Characters
HeaderNone: (Colon)
Slave Address010 1
Function030 3
Byte Count040 4
Data Hi000 0
Data Lo060 6
Data Hi000 0
Data Lo050 5
Error Check LoDALRC (E D)
Error Check Hi31None
TrailerNoneCR LF
Total Bytes819

Function 04 (04hex) Read Input Registers

Read the binary contents of input registers in the slave.

Request
The request message specifies the starting register and quantity of registers to be read.

Example of a request to read 0...1 (register 30001 to 30002) from slave device 1:

Field NameRTU (hex)ASCII Characters
HeaderNone: (Colon)
Slave Address010 1
Function040
Starting Address Hi000 0
Starting Address Lo000 0
Quantity of Registers Hi000 0
Quantity of Registers Lo020 2
Error Check Lo71LRC (F 9)
Error Check HiCB
TrailerNoneCR LF
Total Bytes817

Response
The register data in the response message are packed as two bytes per register, with the binary contents right justified within each byte. For each register the first byte contains the high-order bits, and the second contains the low-order bits.

Example of a response to the request:

Field NameRTU (hex)ASCII Characters
HeaderNone: (Colon)
Slave Address010 1
Function040 4
Byte Count040 4
Data Hi000 0
Data Lo060 6
Data Hi000 0
Data Lo050 5
Error Check LoDBLRC (E C)
Error Check Hi86None
TrailerNoneCR LF
Total Bytes919

Function 05 (05hex) Write Single Coil

Writes a single coil to either ON or OFF.

Request
The request message specifies the coil reference to be written. Coils are addressed starting at zero-coil 1 is addressed as 0.

The requested ON / OFF state is specified by a constant in the request data field. A value of FF 00 hex requests the coil to be ON. A value of 00 00 requests it to be OFF. All other values are illegal and will not affect the coil.

Here is an example of a request to write coil 173 ON in slave device 17:

Field NameRTU (hex)ASCII Characters
HeaderNone: (Colon)
Slave Address111 1
Function050 5
Coil Address Hi000 0
Coil Address LoACA C
Write Data HiFF0 0
Write Data Lo00F F
Error Check Lo4ELRC (3 F)
Error Check Hi8B
TrailerNoneCR LF
Total Bytes817

Response
The normal response is an echo of the request, returned after the coil state has been written.
Example of a response to the request:

Field NameRTU (hex)ASCII Characters
HeaderNone: (Colon)
Slave Address111 1
Function050 5
Coil Address Hi000 0
Coil Address LoACA C
Write Data HiFF0 0
Write Data Lo00F F
Error Check Lo4ELRC (3 F)
Error Check Hi8B
TrailerNoneCR LF
Total Bytes817

Function 06 (06hex) Write Single Register

Writes a value into a single holding register.

Request
The request message specifies the register reference to be Written. Registers are addressed starting at zero-register 1 is addressed as 0.

The requested Write value is specified in the request data field. Here is an example of a request to Write register 40002 to 00 03 hex in slave device 17.

Field NameRTU (hex)ASCII Characters
HeaderNone: (Colon)
Slave Address111 1
Function060 6
Register Address Hi000 0
Register Address Lo010 1
Write Data Hi000 0
Write Data Lo030 3
Error Check Lo9ALRC (E 5)
Error Check Hi9B
TrailerNoneCR LF
Total Bytes817

Response
The normal response is an echo of the request, returned after the register contents have been written.

Field NameRTU (hex)ASCII Characters
HeaderNone: (Colon)
Slave Address111 1
Function060 6
Coil Address Hi000 0
Coil Address Lo010 1
Write Data Hi000 0
Write Data Lo030 3
Error Check Lo9ALRC (E 5)
Error Check Hi9B
TrailerNoneCR LF
Total Bytes817

Function 15 (0Fhex) Write Multiple Coils

Writes each coil in a sequence of coils to either ON or OFF.

Request
The request message specifies the coil references to be written. Coils are addressed starting at zero-coil 1 is addressed as 0.

The requested ON / OFF states are specified by contents of the request data field. A logical 1 in a bit position of the field requests the corresponding coils to be ON. A logical 0 requests it to be OFF.

Below is an example of a request to write a series of ten coils starting at coil 20 (addressed as 19, or 13 hex) in slave device 17.

The request data contents are two bytes: CD 01 hex (1100 1101 0000 0001 binary). The binary bits correspond to the coils in the following way:

Bit: 1 1 0 0 1 1 0 1 0 0 0 0 0 0 0 1

Modbus Rtu Pdf

Coil: 27 26 25 24 23 22 21 20 - - - - - - 29 28

The first byte transmitted (CD hex) addresses coils 27 ... 20, with the least significant bit addressing the lowest coil (20) in this set.

The next byte transmitted (01 hex) addresses coils 29 and 28, with the least significant bit addressing the lowest coil (28) in this set. Unused bits in the last data byte should be zero-filled.

Field NameRTU (hex)ASCII Characters
HeaderNone: (Colon)
Slave Address111 1
Function0F0 F
Coil Address Hi000 0
Coil Address Lo131 3
Quantity of Coils Hi000 0
Quantity of Coils Lo0A0 A
Byte Count020 2
Write Data HiCDC D
Write Data Lo010 1
Error Check LoBFLRC (F 3)
Error Check Hi0B
TrailerNoneCR LF
Total Bytes1123

Response
The normal response returns the slave address, function code, starting address, and number of coils written. Here is an example of a response to therequest shown above

Field NameRTU (hex)ASCII Characters
HeaderNone: (Colon)
Slave Address111 1
Function0F0 F
Coil Address Hi000 0
Coil Address Lo131 3
Quantity of Coils Hi000 0
Quantity of Coils Lo0A0 A
Error Check Lo26LRC (C 3)
Error Check Hi99
TrailerNoneCR LF
Total Bytes817

Function 16 (10hex) Write Multiple Registers

Writes values into a sequence of holding registers

Request
The request message specifies the register references to be written. Registers are addressed starting at zero-register 1 is addressed as 0.

Modbus Rtu For Compactlogix

The requested write values are specified in the request data field. Data is packed as two bytes per register.

Here is an example of a request to write two registers starting at 40002 to 00 0A and 01 02 hex, in slave device 17:

Field NameRTU (hex)ASCII Characters
HeaderNone: (Colon)
Slave Address111 1
Function101 0
Starting Address Hi000 0
Starting Address Lo010 1
Quantity of Registers Hi000 0
Quantity of Registers Lo020 2
Byte Count040 4
Data Hi000 0
Data Lo0A0 A
Data Hi010 1
Data Lo020 2
Error Check LoC6LRC (C B)
Error Check HiF0
TrailerNoneCR LF
Total Bytes1323

Response
The normal response returns the slave address, function code, starting address, and quantity of registers written. Here is an example of a response to therequest shown above.

Field NameRTU (hex)ASCII Characters
HeaderNone: (Colon)
Slave Address111 1
Function101 0
Starting Address Hi000 0
Starting Address Lo010 1
Quantity of Registers Hi000 0
Quantity of Registers Lo020 2
Error Check Lo12LRC (D C)
Error Check Hi98
TrailerNoneCR LF
Total Bytes817

LRC Example Code

This function is an example how to calculate a LRC BYTE using the C language.
BYTE LRC (BYTE *nData, WORD wLength)
{
BYTE nLRC = 0 ; // LRC char initialized
for (int i = 0; i < wLength; i++)
nLRC += *nData++;
return (BYTE)(-nLRC);
} // End: LRC

CRC Example Code

This function is an example how to calculate a CRC word using the C language.

} // End: CRC16