modbus_dgk.pptx

Upload: dgkanade72

Post on 14-Apr-2018

216 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/27/2019 MODBUS_DGK.pptx

    1/44

    MODBUS

    By

    KANADE D G

  • 7/27/2019 MODBUS_DGK.pptx

    2/44

    Introduction MODBUS Protocol is a messaging structure

    created by MODICON company to connect PLC to

    programming tools.

    It is now widely used to establish master-slave

    communication between intelligent devices.

    MODBUS is independent of the physical layer.

    It can be implemented using RS232, RS422, or RS485

    or over a variety of media (e.g. fiber, radio, cellular,

    etc..

  • 7/27/2019 MODBUS_DGK.pptx

    3/44

    MODBUS Serial line RS485

    Application

    Presentation

    Session

    Transport

    Network

    Link

    Physical

    7

    6

    5

    43

    2

    1

    Master - Slave

    Modbus

    RS485

    It is a low cost network

    Uses a master/slave medium access

    Transmission speed from 1,200bits to 115 Kbits/s.

  • 7/27/2019 MODBUS_DGK.pptx

    4/44

    MODBUS TCP/IP

    It uses TCP/IP and Ethernet 10 Mbit/s or 100 Mbits/s

    to carry the MODBUS messaging structure.

    Application

    Preentation

    Session

    Transport

    Network

    Link

    Physical

    7

    6

    5

    4

    3

    2

    1

    CSMA / CD

    ETHERNET V2 ou 802.3

    Modbus

    TCP

    IP

  • 7/27/2019 MODBUS_DGK.pptx

    5/44

    MODBUS PLUS

    It is a higher speed network

    1 Mbit/s token passing derivative that uses the MODBUS

    messaging structure.

    Application

    Presentation

    Session

    Transport

    Network

    Link

    Physical

    7

    6

    5

    43

    2

    1

    802.4 Token passing

    Modbus

    RS485

  • 7/27/2019 MODBUS_DGK.pptx

    6/44

    Types of MODBUS

    The MODBUS protocol comes in 2 versions

    ASCII transmission mode

    RTU (Remote Terminal Unit)transmission

    mode

  • 7/27/2019 MODBUS_DGK.pptx

    7/44

  • 7/27/2019 MODBUS_DGK.pptx

    8/44

    RTU 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 than ASCII for same baud rate.

    Coding System: 8bit binary, hexadecimal 09, AF

    Two hexadecimal characters contained in each 8bit field ofthe 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)

  • 7/27/2019 MODBUS_DGK.pptx

    9/44

    Modbus Message Framing

    For ASCII or RTU, a Modbus message is placed by the

    transmitting device into a frame that has a known beginningand ending point.

    This allows receiving devices to begin at the start of themessage, read the address portion and determine which

    device is addressed. Partial messages can be detected and errors can be set as a

    result.

    MAP or Modbus Plus: The network protocol handles the

    framing of messages with beginning and end delimiters thatare specific to the network.

    The Modbus address is converted to a network nodeaddress and routing path by the originating controller or itsnetwork adapter.

  • 7/27/2019 MODBUS_DGK.pptx

    10/44

  • 7/27/2019 MODBUS_DGK.pptx

    11/44

    ASCII Framing Messages start with a colon ( : ) character

    (ASCII 3A hex)

    End with a carriage return line feed (CRLF) pair

    (ASCII 0D and 0A hex).

    For all other fields are hexadecimal 09, AF.

    Networked devices monitor the network bus continuously forthe colon character.

    When one is received, each device decodes the next field

    (the address field) to find out if it is the addressed device.

    Intervals of up to one second can elapse betweencharacters within the message.

    If a greater interval occurs, the receiving device assumesan error has occurred.

  • 7/27/2019 MODBUS_DGK.pptx

    12/44

    ASCII Message Frame

  • 7/27/2019 MODBUS_DGK.pptx

    13/44

    RTU Framing

    In RTU mode, messages start with a silent interval of

    at least 3.5 character times.

    The first field then transmitted is the device address.

    The allowable characters transmitted for all fields are

    hexadecimal 09, AF. Networked devices monitor continuously the silent

    intervals.

    Each device decodes first field after silent intervals

    to find out if it is the addressed device.

  • 7/27/2019 MODBUS_DGK.pptx

    14/44

  • 7/27/2019 MODBUS_DGK.pptx

    15/44

    Address Field

    Address ChecksumDataFunction

    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).

  • 7/27/2019 MODBUS_DGK.pptx

    16/44

    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.

    Address Field(continued..)

  • 7/27/2019 MODBUS_DGK.pptx

    17/44

    Function Field

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

    Request :

    The function code field tells the slave what kind of actionto perform.

    Response :

    For a normal response, the slave simply echoes theoriginal 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.

    Address ChecksumDataFunction

  • 7/27/2019 MODBUS_DGK.pptx

    18/44

    Data Field

    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 functioncode.

    This can include items like register addresses, quantity of

    items to be handled, etc...

    Address ChecksumDataFunction

  • 7/27/2019 MODBUS_DGK.pptx

    19/44

    Data Field(continued)

    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.

    Address ChecksumDataFunction

  • 7/27/2019 MODBUS_DGK.pptx

    20/44

    Checksum Field

    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 byte)

    Request :

    The checksum is calculated by the master and sends to theslave.

    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.

    Address ChecksumDataFunction

  • 7/27/2019 MODBUS_DGK.pptx

    21/44

  • 7/27/2019 MODBUS_DGK.pptx

    22/44

    Frame Exemple in RTU Mode

    Request :

    Function code = 06 : Write Single Register

    Slave

    AddressCRC16

    Word

    address

    Function

    code = 06

    Value of

    word

    1 byte 1 byte 2 bytes 2 bytes 2 bytes

    Response :

    Slave

    Address

    CRC16Word

    address

    Function

    code = 06

    Value of

    word

    1 byte 1 byte 2 bytes 2 bytes 2 bytes

  • 7/27/2019 MODBUS_DGK.pptx

    23/44

    How Characters are Transmitted

    Serially

    With ASCII character framing, the bit sequence is:

  • 7/27/2019 MODBUS_DGK.pptx

    24/44

    How Characters are Transmitted

    Serially

    With RTU character framing, the bit sequence is:

  • 7/27/2019 MODBUS_DGK.pptx

    25/44

    Master-Slave Query Response Cycle

  • 7/27/2019 MODBUS_DGK.pptx

    26/44

    Error Checking Methods

    Standard Modbus serial networks use two kinds of

    error checking.

    Parity checking :-(even or odd) can be optionally

    applied to each character.

    Frame checking (LRC or CRC) is applied to the

    entire message.

    The master is configured by the user to wait for a

    predetermined timeout interval before aborting

    the transaction.

    message addressed to a nonexistent slave device

    will also cause a timeout.

  • 7/27/2019 MODBUS_DGK.pptx

    27/44

  • 7/27/2019 MODBUS_DGK.pptx

    28/44

    LRC Error Checking

    Used in ASCII mode of transmission.

    Checks the contents of the message, exclusive of

    the beginning colon and ending CRLF pair

    Applied regardless of any parity check method

    used for individual characters.

    The LRC field is one byte.

  • 7/27/2019 MODBUS_DGK.pptx

    29/44

    CRC Error Checking

    Used in RTU mode of transmission.

    The CRC field checks the contents of the entire

    message.

    Applied regardless of any parity check method

    used for the individual characters.

    Only the eight bits of data in each character

    are used for generating the CRC.

    The CRC field is two bytes.

    F i C d E l

  • 7/27/2019 MODBUS_DGK.pptx

    30/44

    Function Code Exemples

    Code Function

    01 (0x01) Read Coils

    02 (0x02) Read Discrete Inputs

    03 (0x03) Read Holding Registers

    04 (0x04) Read Input Registers

    05 (0x05) Write Single Coil

    06 (0x06) Write Single Register

    15 (0x0F) Write Multiple Coils

    16 (0x10) Write Multiple Registers

    23 (0x17) Read/Write Multiple Registers

    43 (0x2B) Read Device Identification

    The complete description of all Modbus request is freely available on the

    Modbus.org web site : http://www.modbus.org

    E Ch ki M th d

  • 7/27/2019 MODBUS_DGK.pptx

    31/44

    Error Checking Methods

    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 beforecompletion of the frame, the receiving device flushes the

    incomplete message and assumes that the next bytewill be the address field of a new message

  • 7/27/2019 MODBUS_DGK.pptx

    32/44

    Exception Responses

    Except for broadcast messages, when a master

    device sends a query to a slave device it expects a

    normal response.

  • 7/27/2019 MODBUS_DGK.pptx

    33/44

    Exception Responses

    One of four possible events can occur from themasters query:

    Slave device receives the query without a

    communication error. -Normal response Slave does not receive the query due to a

    communication error.-No response

    Slave receive the query with a communication

    error.(Parity,LRC or CRC)-No response

    Slave receives the query without a communication

    error, but cannot handle it.-Exception response.

  • 7/27/2019 MODBUS_DGK.pptx

    34/44

    Exception Response

    The exception response message has two fieldsthat differentiate it from a normal response:

    Function Code Field:

    In a normal response, the slave echoes the function

    code of the original query. In an exception response, the slave sets the MSB of the

    function code to 1.

    All function codes have a mostsignificant bit (MSB) of 0

    Data Field: In a normal response, the slave may return data.

    In an exception response, the slave returns anexception code in the data field.

    E ti H dli

  • 7/27/2019 MODBUS_DGK.pptx

    35/44

    Byte Contents Example

    1 Slave Address 0A

    2 Function 01

    3 Starting Address Hi 04

    4 Starting Address Lo A1

    5 No. of Coils Hi 00

    6 No. of Coils Lo 017 LRC 4F

    Exception Handling

    Byte Contents Example

    1 Slave Address 0A

    2 Function 81

    3 Exception Code 02

    4 LRC 73

  • 7/27/2019 MODBUS_DGK.pptx

    36/44

  • 7/27/2019 MODBUS_DGK.pptx

    37/44

    The master is configured by the user to wait for apredetermined 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.

    Error Checking Methods (continued...)

  • 7/27/2019 MODBUS_DGK.pptx

    38/44

    RS485 Physfical Layer

    RS485 is the most common physical layer used on Modbus.

    The RS485 standard allows variants of different characteristics :

    Polarisation

    Line terminator

    Distribution of a reference potential

    Number of slaves

    Length of the bus

  • 7/27/2019 MODBUS_DGK.pptx

    39/44

    The Various Versions of the RS485

    Physical Layer

    The new Telemecanique devices conform to the Modbus

    specification published in 2002 on the Modbus.org web

    site.

    But some Schneider older devices comply with earlier

    specifications :

    Uni-Telway

    Jbus

    N M db RS485 d d h i

  • 7/27/2019 MODBUS_DGK.pptx

    40/44

    New Modbus RS485 standard schematic

    Master

    Slave 1 Slave 2

    D1

    D0

    Common

    5 V

    650

    650

    120 1 nF

    120 1 nF

    Maximum length of Bus 1000m at 19200 bps

    Max. no of stations (without repeater) 32 (31 slaves)

    Max. length of Tap Link 20m for one tab link40 m divided by no. taps

    Bus polarization 650 at 5V and common for the MasterLine terminator 120 -0,25Wm in series with 1nF,10VCommon polarity Yes common connected to PG

    U i T l RS485 h i

  • 7/27/2019 MODBUS_DGK.pptx

    41/44

    Uni-Telway RS485 schematic

    Master

    Slave 1 Slave 2

    D(B)

    D(A)0 VL

    5 V

    4,7 K

    120 1 nF

    120 1 nF

    4,7 K

    4,7 K4,7 K4,7 K4,7 K5 V5 V

    Maximum length of Bus 1000m at 19200 bps

    Max. no of stations (without repeater) 28 (27 slaves)

    Max. length of Tap Link 20m for one tab link

    40 m divided by no. taps

    Bus polarization 4.7k at 5V and common for the Masterand slave

    Line terminator 120 -0,25Wm in series with 1nF,10VCommon polarity Yes (0 VL)High impedance between 0VL

    and ground in each station

    Jbus RS485 schematic

  • 7/27/2019 MODBUS_DGK.pptx

    42/44

    Jbus RS485 schematic

    Master

    Slave 1

    Slave 2

    L-(B/B )

    L+(A/A )

    5 V

    470 470

    150 150

    Maximum length of Bus 1300m at 19200 bps

    Max. no of stations (without repeater) 32 (31 slaves)

    Max. length of Tap Link 3m

    Bus polarization 470 at 5V and common for the MasterLine terminator 150Common polarity No

    Mixed RS485 schematic

  • 7/27/2019 MODBUS_DGK.pptx

    43/44

    Mixed RS485 schematic

    Master

    Slave 1 Slave 2

    D1

    D0

    Common

    5 V

    Rp

    120

    1 nF

    120 1 nF

    Rp

    4,7 K4,7 K

    5 V

    Suitable polarization Rpmust be calculated

    If the master is fitted with a 470 polarisation,it s possible to connect a maximum of

    18 slaves with 4,7 K polarisation

    Maximum length of Bus 1000m at 19200 bps

    Max. no of stations (without repeater) At most 32 (depending upon Rp and

    no.of 4.7k)

    Max. length of Tap Link 20m for one tab link40 m divided by no. taps

    Bus polarization 470 at 5V and common for the MasterLine terminator 120 -0,25Wm in series with 1nF,10VCommon polarity Yes common connected to PG

  • 7/27/2019 MODBUS_DGK.pptx

    44/44

    Thank You