Sie sind auf Seite 1von 32

Modbus on serial line

Being able to approach the implementation of Modbus products on Serial Line

Implementation Classes

The Three Standardised Physical Layers

Modbus RTU and Modbus ASCII

Operating Principles

Duration : 40 min.

Training expert: Philippe WARIN Production : Scneider-Electric

Modbus on serial line - January 2006

TOLED

OPERATING PRINCIPLES

Implementation Classes

The Three Standardised Physical Layers

Modbus RTU and Modbus ASCII

Operating Principles

Modbus on serial line - January 2006

TOLED

- Modbus serial line and the OSI model


7 6 5 4 3 2 1 APPLICATION PRESENTATION SESSION

Modbus application protocol

Not used
TRANSPORT NETWORK

LINK
PHYSICAL

Master-Slave Transmission mode: RTU or ASCII RS485 two or four wire RS232

Modbus on serial line - January 2006

TOLED

- Modbus Master-Slave protocol principles


One master
Communication can only be initialised by the master

One to 247 slaves

Modbus on serial line - January 2006

TOLED

- Modbus serial line frame


Modbus PDU

PDU = Protocol Data Unit

Address

Function Code

Data

CRC or LRC

= 0 to 247 Identifies the addressee

= 1 to 127 Action to perform

Additional data depending on the Function Code

Validity check

Two addressing modes:

Unicast

Address field = 1 to 247

Broadcast

Address field = 0 (used in write only mode)

Modbus on serial line - January 2006

TOLED

- Unicast mode addressing


Address = 1 to 247
Request 5
Funct. Code Request data CRC

Adr 1

Adr 2

Adr 3

Adr 4

Adr 5

Adr n

Response
5
Funct. Code Response data CRC

Modbus on serial line - January 2006

TOLED

- Broadcast mode addressing


Address = 0
Request
0
Funct. Code Request data CRC

Adr 1

Adr 2

Adr 3

Adr 4

Adr 5

Adr n

No response from slaves Used only for write functions

Modbus on serial line - January 2006

TOLED

- Unicast addressing timing diagram


Slave 1 REQUEST

Master

Await timeout
Process response

Analyse resp. Prep. req.

Next request

Slave 1

RESPONSE

Slave n
Next request

Media

Slave 1 REQUEST

RESPONSE

Modbus on serial line - January 2006

TOLED

- Broadcast addressing timing diagram


Broadcast REQUEST

Master

Await timeout
Process response

Next request

Slave 1

Slave n

Process response

Media

Broadcast REQUEST

Next request

Modbus on serial line - January 2006

TOLED

- Transmission error event timing diagram

Master

Slave 1 REQUEST

Await timeout

Retransmit or next request

Slave 1 Slave n

Error detected

No response

Media

Slave 1 REQUEST

Retransmit or next request

Modbus on serial line - January 2006

TOLED

MODBUS RTU AND MODBUS ASCII

Implementation Classes

The Three Standardised Physical Layers

Modbus RTU and Modbus ASCII

Operating Principles

Modbus on serial line - January 2006

TOLED

- Two defined serial transmission modes


RTU mode Required Defines: ASCII mode

Optional

the content and format of each character


its encapsulation: the start and end of the frame Transmission mode and serial port parameters are identical on all products.

Modbus on serial line - January 2006

TOLED

- RTU mode: content


Every data item is encoded in one byte
B7 B6 B5 B4 B3 B2 B1 B0

Two hexadecimal digits


Encoding example: Read Device Identification = 43 = 0x2B 0x2
0 0 1 0 1

0xB
0 1 1

Modbus on serial line - January 2006

TOLED

- RTU mode: character format = 11 bits


With parity check
Encoding example: Read Device Identification = 43 = 0x2B
0x2B comprises 4 bits at 1 8 bits de donne Parit paire Odd parity

Start 1 Bit 0 7 Bit 0 6 Bit 1 5 Bit 0 4 Bit 1 3 Bit 0 2 Bit 1 1 Bit 1 0 Parity 1 1 0 Stop

1 stop bit

Odd number Nombre pair of debits bitsat 1

No parity check
Encoding example: Read Device Identification = 43 = 0x2B
0x2B comprises 4 bits at 1 8 bits de donne

Start 1 Bit 07 Bit 06 Bit 15 Bit 04 Bit 13 Bit 02 Bit 11 Bit 10 Stop 1 Stop 1

2 stop bits

Modbus on serial line - January 2006

TOLED

- RTU mode: frame format


256 bytes max.
Start >= 3.5 chars. Address
Function Code

Data

CRC

End >= 3.5 chars.

1 byte

1 byte

0 to 252 bytes

2 bytes

Time constraints
Frame OK
<= 1.5 chars. >= 3.5 chars.

Frame OK

Frame NOK

>= 1.5 chars.

>= 3.5 chars.

Modbus on serial line - January 2006

TOLED

- ASCII mode: content


Every data item is encoded in two ASCII characters (7 bits)
B6 B5 B4 B3 B2 B1 B0 B6 B5 B4 B3 B2 B1 B0

Two ASCII characters


Encoding example: Read Device Identification = 43 = 0x2B
ASCII code "2" = 0x32
0 1 1 0 0 1 0 1

ASCII code "B" = 0x42


0 0 0 0 1 0

Modbus on serial line - January 2006

TOLED

- ASCII mode: character format = 10 bits


With parity check
Example: encoding character "2" in ASCII = 0x32
0x32 comprises 3 bits at 1 7 data bits Even Odd parity

Start 1 Bit 0 6 Bit 1 5 Bit 1 4 Bit 0 3 Bit 0 2 Bit 1 1 Bit 0 0 Parity 1 0 1 Stop

1 stop bit

Nombre pair of debits bitsat 1 Odd number

No parity check
Example: encoding character "2" in ASCII = 0x32
0x32 comprises 3 bits at 1 7 bits de donne

Start 1 Bit 0 6 Bit 1 5 Bit 1 4 Bit 0 3 Bit 0 2 Bit 1 1 Bit 0 0 Stop 1 Stop 1

2 stop bits

Modbus on serial line - January 2006

TOLED

- ASCII mode: frame format


513 characters max.
: 1 char. Address
Function Code

Data

LRC

CR + LF 2 chars.

2 chars. 2 chars.

0 to 2 x 252 characters

2 chars.

Time constraints
Frame OK
<= 1 to 5 sec.

Frame OK

Frame NOK

>= 1 to 5 sec.

No inter-frame time constraint.

Modbus on serial line - January 2006

TOLED

- Transmission error checks


Two types of checks performed at the master and slave ends

Parity check
Character level

Frame check
Message level

Choice of even or odd parity

If RTU mode: calculate CRC


CRC = Cyclical Redundancy Checking

If ASCII mode: calculate LRC


LRC = Longitudinal Redundancy Checking

Modbus on serial line - January 2006

TOLED

- Reaction on error detection


The slave detects a transmission error
Master REQUEST
Await timeout Resend or Send error to application

Slave

Error detection

Does not process the request Does not provide a response

The master detects a transmission error


Master REQUEST Slave Wait
Process response

Does not process the request Error detection Resend or Send error to application

RESPONSE

Modbus on serial line - January 2006

TOLED

THE THREE STANDARDISED PHYSICAL LAYERS

Implementation Classes

The Three Standardised Physical Layers

Modbus RTU and Modbus ASCII

Operating Principles

Modbus on serial line - January 2006

TOLED

- Three standardized Modbus electrical interfaces


RS485 2 wire RS485 4 wire
Required
Multi-point and point-to-point
To integrate into an existing installation without modification

Optional

RS232 Transmission speeds:

Optional

Point-to-point mode 15 meter max.

9600 bps and 19200 bps required with 19.2 Kbps by default
Other speeds: 1200, 2400, 4800, 38400, 56 Kbps, 115 Kbps optional

Modbus on serial line - January 2006

TOLED

- Modbus RS485 2 wire installation


Master

Topology: bus type

T R 5V 650 ohms

Balanced pair
120 ohms 1 nF

Common

650 ohms

120 ohms 1 nF

PG
T R T R

Slave 1

Slave n

Max. number of devices: 32 including master without a repeater Max. length: Main segment: 1,000 meters at 19,200 bits/s Drops: 40 meters in total

Modbus on serial line - January 2006

TOLED

- Modbus RS485 4 wire installation


Master

Topology: bus type


Slave pair

5V 650 ohms

650 ohms 120 ohms 1 nF 5V 120 ohms 1 nF

Master pair
120 ohms 1 nF

Common PG
Max. number of devices: 32 including master without a repeater

120 ohms 1 nF

Slave 1

Slave n

Max. length: Main segment: 1,000 meters at 19,200 bits/s Drops: 40 meters in total
Modbus on serial line - January 2006

TOLED

- Modbus 2 and 4 wire compatibility


Two possibilities:
Connecting 2 wire devices to a 4 wire installation
Possible, by adapting installation wiring

Connecting 4 wire equipment to a 2 wire installation

Possible, by adapting device wiring

Modbus on serial line - January 2006

TOLED

- Connecting 2 wire devices to a 4 wire installation


Master

The total length of the new two wire bus must be less than 1,000 meters

5V 650 ohms

650 ohms Line terminator 5V 120 ohms 1 nF

Line terminator

Common
Adapting the installation
T R T R

120 ohms 1 nF

1 2 3 4

Disconnect the line terminators at one end Delete one pair of polarising resistors Loop back the two pairs at one end Connect the device using two wires

Slave 1

Slave n

Modbus on serial line - January 2006

TOLED

- Connecting 4 wire devices to a 2 wire installation


Master
T R 5V 650 ohms

Balanced pair
120 ohms 1 nF

Common

650 ohms

120 ohms 1 nF

Adapting device wiring


T R

1 2

Loop back transmission to device reception Connect the device to the two wire installation

Slave 1

Slave n

Modbus on serial line - January 2006

TOLED

IMPLEMENTATION CLASSES

Implementation Classes

The Three Standardised Physical Layers

Modbus RTU and Modbus ASCII

Operating Principles

Modbus on serial line - January 2006

TOLED

- Transparent Ready rules and vocabulary reminders


Three implementation levels for three service levels

Basic

Regular

Extended

An embedded function level model

Belonging to a class only if all of the required services are supported

A device can also support services belonging to a higher class.

Modbus on serial line - January 2006

TOLED

- Transparent Ready equipment identification


Web Services

A - no Web
Communication services

B to D

00
01 05

Without Modbus Modbus Basic

Other TR devices (through a TR gateway)

Modbus Regular

TR Modbus devices through a TR gateway

10 20
30

Modbus Basic TCP-IP +...


Modbus Basic TCP-IP + FDR +... Modbus Regular TCP-IP + FDR +...

All TR Modbus TCP-IP devices

A01 & A05


Two implementation classes for Modbus serial line devices

Modbus on serial line - January 2006

TOLED

- The two implementation classes


Class A01
Messaging class:
Data link class:

Basic
Basic

Access to registers only Not configurable

Class A05
Messaging class: Data link class: Device management class: Regular Regular Basic
Basic + access to bits and diagnostics Configurable Level 1 identification

Modbus on serial line - January 2006

TOLED

- Service classes data link layer


Basic
No configuration options

Address: 1 to X with X<= 247 Speed: 9600 bps Parity: odd Transmission mode: RTU Broadcast: supported if slave

Regular

Configurable data link layer

Basic + Address: support for address 248* Speed: 9600 and 19200 required Parity: odd and even required

* Address 248 is used if the configuration can be set by messaging

Modbus on serial line - January 2006

TOLED

Das könnte Ihnen auch gefallen