Sei sulla pagina 1di 23

Sina Institute of Networks and Aesthetics Web: www.sina.edu.pk| Facebook: www.facebook.com/sina.edu.

pk
Sina Institute of Networks & Aesthetics

Sina Institute of Networks and Aesthetics Web: www.sina.edu.pk| Facebook: www.facebook.com/sina.edu.pk


Module 4
MODBUS
MODICON DATA BUS

Sina Institute of Networks and Aesthetics Web: www.sina.edu.pk| Facebook: www.facebook.com/sina.edu.pk


MODBUS

Sina Institute of Networks and Aesthetics Web: www.sina.edu.pk| Facebook: www.facebook.com/sina.edu.pk


Modbus
 MODBUS is an application layer messaging protocol
 Positioned at level 7 of the OSI model
 Provides client/server communication between devices connected on different types of buses or
networks
 Typically used for communication with I/O systems, including Programmable Logic Controllers
(PLCs)
 Supports following communication links:
 TCPTCP/IP using standard port 502.
 Serial RTU protocol, using RS-232, RS-422, or RS-485.
Directly transmits each byte as 8 data bits, so uses "binary" rather than ASCII encoding.
Start and end of message frames is detected by timing rather than by specific characters.
 Serial ASCII protocol, using RS-232, RS-422, or RS-485.
Encodes each byte as 2 ASCII characters.
Start and end of message frames is detected by specific characters (":" to start a message
and CR/LF to end a message).
Less efficient than RTU, but may be more reliable in some environments.

Sina Institute of Networks and Aesthetics Web: www.sina.edu.pk| Facebook: www.facebook.com/sina.edu.pk


Modbus Plus
MODBUS PLUS Is a higher speed network 1 Mbit/s token passing derivative that uses the MODBUS
messaging structure.

7 Application Modbus

6 Presentation
5
Session
4
Transport
3
Network
2

1 Link 802.4 Token passing

Physical RS485

Sina Institute of Networks and Aesthetics Web: www.sina.edu.pk| Facebook: www.facebook.com/sina.edu.pk


Modbus

• Data types
– Single bits
– 16-bit registers
• Modbus communications
– Request message sent from the Modbus client to the Modbus server.
– Server replies with a response message.
• Modbus request messages contain:
– An 8-bit Modbus function code that describes the type of data transfer to be performed.
– A 16-bit Modbus address that describes the location in the server to read or write data
from.
– For write operations, the data to be transferred.

Sina Institute of Networks and Aesthetics Web: www.sina.edu.pk| Facebook: www.facebook.com/sina.edu.pk


Modbus ASCII and Modbus RTU
The MODBUS protocol comes in 2 versions :

 ASCII transmission mode


Each eight-bit byte in a message is sent as 2 ASCII characters.

 RTU transmission mode


Each eight-bit byte in a message is sent as two four-bit hexadecimal
characters.

The main advantage of the RTU mode is that it achieves higher throughput.

ASCII mode allows time intervals of up to 1 second to occur between


characters without causing an error.

Sina Institute of Networks and Aesthetics Web: www.sina.edu.pk| Facebook: www.facebook.com/sina.edu.pk


Modbus Frame Structure

The Modbus frame structure is the same for requests (master to slave messages) and
réponses (slave to master messages).
Modbus RTU

silence Address Function Data Checksum silence Silence >= 3,5 caractères

Modbus ASCII

: Address Function Data Checksum CR LF

3A Hex 0D Hex 0A Hex

Sina Institute of Networks and Aesthetics Web: www.sina.edu.pk| Facebook: www.facebook.com/sina.edu.pk


Address Field

Address Function Data Checksum

Valid slave device addresses are in the range of 0 ... 247 decimal. The individual slave
devices are assigned addresses in the range of 1 ... 247. Value 0 is reserved for broadcast
messages (no response).
Request :
A master addresses a slave by placing the slave address in the address field of
the message.
Response :
When the slave sends its response, it places its own address in this address field
of the response to let the master know which slave is responding.

Sina Institute of Networks and Aesthetics Web: www.sina.edu.pk| Facebook: www.facebook.com/sina.edu.pk


Function Field
Address Function Data Checksum

Valid codes are in the range of 1 ... 255 decimal.

Request :
The function code field tells the slave what kind of action to perform.

Response :
For a normal response, the slave simply echoes the original function code.

For an exception response, the slave returns a code that is equivalent to


the original function code with its most significant bit set to a logic 1.

Sina Institute of Networks and Aesthetics Web: www.sina.edu.pk| Facebook: www.facebook.com/sina.edu.pk


Data Field
Address Function Data Checksum

Valid codes are in the range of 0 ... 255 decimal.

Request :
The data field contains additional information which the slave must use to take the action defined
by the function code. This can include items like register addresses, quantity of items to be
handled, etc...

Response :
If no error occurs, the data field contains the data requested.

If an error occurs, the field contains an exception code that the master
application can use to determine the next action to be taken.

Sina Institute of Networks and Aesthetics Web: www.sina.edu.pk| Facebook: www.facebook.com/sina.edu.pk


Checksum Field
Address Function Data Checksum

Valid codes are in the range of 0 ... 255 decimal.

Modbus RTU uses CRC : Cyclycal Reduncy Check (2 byte)


Modbus ASCII uses LRC : Longitudinal Redundancy Check (1 bytes)

Request :
The checksum is calculated by the master and sends to the slave.

Response :
The checksum is re-calculated by the slave and compared to the value sent
by the master.
If a difference is detected, the slave will not construct a response to the master.

Sina Institute of Networks and Aesthetics Web: www.sina.edu.pk| Facebook: www.facebook.com/sina.edu.pk


Frame Example in RTU Mode
 Function code = 3 : Read n words

Request :

1 byte 1 byte 2 bytes 2 bytes 2 bytes


Slave Function First word Number of
CRC16
Address code = 3 address words to read

Response :

1 byte 1 byte 2 bytes 2 bytes 2 bytes 2 bytes


Slave Function Number of Value of the Value of the
CRC16
Address code = 3 bytes read first word last word

Sina Institute of Networks and Aesthetics Web: www.sina.edu.pk| Facebook: www.facebook.com/sina.edu.pk


Function Code Example
Code Type

01 Read n consecutive output bits


02 Read n consecutive input bits
03 Read n consecutive output words
04 Read n consecutive input words
05 Write 1 output bit
06 Write 1 output word
07 Read exception status
08 Access diagnostic counters
11 Read event counter
12 Read connection events
15 Write n output bits
16 Write n output words
17 Read identification

Sina Institute of Networks and Aesthetics Web: www.sina.edu.pk| Facebook: www.facebook.com/sina.edu.pk


Error Checking Method

 Parity checking
Even or odd can be optionally applied to each character.

 Frame checking
LRC or CRC is applied to the entire message.

 Continuous stream
The entire message frame must be transmitted as a continuous stream.
If a silent interval (more than 1.5 character times RTU mode or 1 second ASCII mode) occurs
before completion of the frame, the receiving device flushes the incomplete message and
assumes that the next byte will be the address field of a new message.

Sina Institute of Networks and Aesthetics Web: www.sina.edu.pk| Facebook: www.facebook.com/sina.edu.pk


Error Checking Method

The master is configured by the user to wait for a predetermined timeout interval before
aborting the transaction.
This interval is set to be long enough for any slave to respond normally.
If the slave detects a transmission error, the message will not be acted upon.
The slave will not construct a response to the master.
Thus the timeout will expire and allow the master's program to handle the error.

Sina Institute of Networks and Aesthetics Web: www.sina.edu.pk| Facebook: www.facebook.com/sina.edu.pk


RS485 Physical Layer

is the most physical layer used on Modbus.

32 devices included the master can be connected on the bus.

This is a bus topology with line terminations.

Sina Institute of Networks and Aesthetics Web: www.sina.edu.pk| Facebook: www.facebook.com/sina.edu.pk


Main Characteristics Resume

Topology: Bus with line terminations

Maximum distance: With RS485 : 1300 m without repeater

Data rate: 19200 bits/s maximum

Max. no. of devices: With RS485 : 32 master included

Sina Institute of Networks and Aesthetics Web: www.sina.edu.pk| Facebook: www.facebook.com/sina.edu.pk


Main Characteristics Resume

Method of accessing the medium: Master slave

Transmission method: Messaging

Max. useful data size: 120 words

Transmission security: LRC or CRC


Start and stop delimiters
Parity bit
Continuous stream

Sina Institute of Networks and Aesthetics Web: www.sina.edu.pk| Facebook: www.facebook.com/sina.edu.pk


CRC CALCULATION
Example of CRC calculation (frame 02 07)
02

Sina Institute of Networks and Aesthetics Web: www.sina.edu.pk| Facebook: www.facebook.com/sina.edu.pk


CRC CALCULATION
Example of CRC calculation (frame 02 07)
07

Sina Institute of Networks and Aesthetics Web: www.sina.edu.pk| Facebook: www.facebook.com/sina.edu.pk


Sina Institute of Networks and Aesthetics Web: www.sina.edu.pk| Facebook: www.facebook.com/sina.edu.pk

Potrebbero piacerti anche