You are on page 1of 21

i

MODBUS
Table Of Contents
MODBUS......................................................................................................................................... 1
MODBUS Version 2.02............................................................................................................ 1
Using MODBUS: Unitronics' PLCs, Master - Slave ................................................................. 1
Using MODBUS: Accessing PLC data via SCADA/OPC server.............................................. 2
MODBUS: Configuration.............................................................................................................. 5
MODBUS: Scan ........................................................................................................................... 6
Read Coils (1) .............................................................................................................................. 6
Read Inputs (2) ............................................................................................................................ 7
Read Holding Registers (3).......................................................................................................... 8
Read Float Registers (3) .............................................................................................................. 9
Read Input Registers (4) .............................................................................................................. 9
Read Input Float Registers (4)................................................................................................... 10
Force Coil (5) ............................................................................................................................. 11
Preset Holding Register (6)........................................................................................................ 11
Loopback Test (8) ...................................................................................................................... 12
Force Coils (15).......................................................................................................................... 13
Preset Holding Registers (16).................................................................................................... 13
Preset Float Registers (16) ........................................................................................................ 14
Configuring a MODBUS slave device........................................................................................ 15
Slave Address Tables ................................................................................................................ 15
MODBUS via GSM or Standard Modem ................................................................................... 16
MODBUS Error Table ................................................................................................................ 17
Index .............................................................................................................................................. 19

1
MODBUS
MODBUS Version 2.02
MODBUS enables you to establish master-slave communications with any connected device
that supports the MODBUS protocol. Any controller in the network may function as either
master or slave using any of the controller's existing COM Ports.
Unitronics currently supports RTU (binary) transmission mode.
Using MODBUS: Unitronics' PLCs, Master - Slave
Before using a MODBUS operation in your application, you must:
Synchronize the communication port settings of master and slave devices. This is done
by placing Com Port Init FBs, set with identical parameters, in the ladder application of
both master and slave.
Include at least 1 MODBUS Configuration FB in the ladder application of both master and
slave. The port you select must be the same port selected in the Com Port Init FB.
The condition that activates the Configuration must turn ON for a single program scan
(positive transition recommended).However, the MODBUS configuration must be
scanned during every program cycle--after the Configuration is activated. One way
to ensure this is by placing the configuration in the first subroutine of the main
module.
Enable slave devices to be accessed by placing a Scan FB in the slave's Ladder
application.
The figure below shows the elements required to carry out a Read Coils Operation.

MODBUS
2
Note that the operand addresses in slave PLCs are indirect addresses (pointers).

Using MODBUS: Accessing PLC data via SCADA/OPC server
The PC master can access data within the PLC via the addresses given in the Slave
Addresses Table.
The PLC slave's Ladder application must include the following:
A Com Port Init FB.
A MODBUS Configuration FB. Within the Configuration, the port you select must be the
same port selected in the Com Port Init FB.
Note ! The condition that activates the Configuration must turn ON for a single program
scan (positive transition recommended).However, the MODBUS configuration must be
scanned during every program cycle--after the Configuration is activated. One way
to ensure this is by placing the configuration in the first subroutine of the main
module.
A Scan FB.
MODBUS
3

Note ! The operand addresses in slave PLCs are indirect addresses (pointers).


MODBUS Operations
The MODBUS FBs are grouped under MODBUS on the FB's menu.
MODBUS
4

MODBUS: Con f i gu r a t i on
MODBUS: Sc a n
MODBUS: Re a d Coi l s ( 1 )
MODBUS: Re a d I n pu t s ( 2 )
Re a d Hol di n g Re gi s t e r s ( 3 )
Re a d Fl oa t Re gi s t e r s ( 3 )
Re a d I n put Re gi s t e r s ( 4 )
Re a d Fl oa t I np ut Re gi s t e r s ( 4 )
Fo r c e Coi l ( 5 )
Pr e s e t Hol di ng Re gi s t e r ( 6 )
Fo r c e Coi l s ( 1 5 )
Pr e s e t Hol di ng Re gi s t e r s ( 1 6 )
Pr e s e t Fl o a t Re gi s t e r s ( 1 6 )
Ex a mpl e s
The applications listed below use MODBUS. To locate application examples, select Examples
from the Help menu.
MODBUS Slave.vlp
MODBUS Master.vlp
MODBUS
5
MODBUS: Configuration
A MODBUS Configuration FB must be included in both master and slave Ladder applications
as shown below.

Parameter Type Function
Por t
Number
Const ant Cl i ck t he dr op- down ar r ows t o vi ew avai l abl e por t s; cl i ck t he por t
you want t o use.
Net wor k I D Const ant Thi s number i dent i f i es t he devi ce on t he net wor k. You can ei t her
assi gn an I D vi a an MI , or di r ect l y vi a a const ant number . The uni t I D
r ange i s f r om 0- 255. Do not assi gn t he same I D number t o mor e t han
one devi ce.
Ti me out Const ant
or MI
Thi s i s t he amount of t i me a mast er devi ce wi l l wai t f or an answer
f r om a sl ave. Ti me out uni t s ar e def i ned i n 10 msecs; a Ti me out
val ue of 100 i s equal t o 1 second.
Ret r i es Const ant
or MI
Thi s i s t he number of t i mes a devi ce wi l l t r y t o send a message.
Funct i on i n
Pr ogr ess
MB Thi s bi t i s ON when MODBUS i s act i ve. Use t hi s as a condi t i on bi t
f or MODBUS oper at i ons t o avoi d communi cat i on conf l i ct s.
The Ladder application below enables the controller act as a MODBUS master and read coils
in a slave PLC. The Scan operation in the final net enables the controller to also act as a
slave.
MODBUS
6

MODBUS: Scan
This enables a master device to access a slave PLC.


Read Coils (1)
MODBUS
7
Use this command to read the status of a selected group of coils and write them into a vector.
The coil's status is written into a vector of MBs in the master PLC.

Parameter Type Function
Sl ave I D Const ant
or MI
The I D of t he sl ave devi ce cont ai ni ng t he coi l s t o be r ead
( dat a sour ce) .
Sl ave: St ar t of
Vect or
Const ant ,
MI , ML,
or DW
The st ar t of t he vect or of coi l s t o be r ead ( dat a sour ce) .
Read: Vect or
Lengt h
Const ant
or MI
The vect or l engt h.
Mast er : St ar t of
Vect or
MB Thi s i s t he st ar t of a vect or of MBs t hat wi l l cont ai n t he coi l s'
st at us i n t he mast er ( dat a dest i nat i on) .
Er r or St at us MI Shows an er r or message number . To di agnose t he er r or ,
check t he MODBUS Er r or Tabl e.
Tot al Sessi ons DW Thi s i s t he number of t i mes t he mast er PLC wi l l at t empt t o
access t he sl ave devi ce. Not e t hat t hi s i s a si mpl e
i ncr ement al count er . I ni t i al i ze i t by st or i ng 0 i nt o t he sel ect ed
DW.
Acknowl edgement s DW Thi s i s t he number of t i mes t he sl ave devi ce answer s.
Read Inputs (2)

Use this command to read the status of a selected group of inputs in a slave device and write
them into a vector. The inputs's status is written into a vector of MBs in the master PLC.

Parameter Type Function
Sl ave I D Const ant The I D of t he sl ave devi ce cont ai ni ng t he i nput s t o be r ead
MODBUS
8
or MI ( dat a sour ce) .
Sl ave: St ar t of
Vect or
Const ant ,
MI , ML,
or DW
The st ar t of t he vect or of i nput s t o be r ead ( dat a sour ce) .
Read: Vect or
Lengt h
Const ant
or MI
The vect or l engt h.
Mast er : St ar t of
Vect or
MB Thi s i s t he st ar t of a vect or of MBs t hat wi l l cont ai n t he
i nput s' st at us i n t he mast er ( dat a dest i nat i on) .
Er r or St at us MI Shows an er r or message number . To di agnose t he er r or ,
check t he MODBUS Er r or Tabl e.
Tot al Sessi ons DW Thi s i s t he number of t i mes t he mast er PLC wi l l at t empt t o
access t he sl ave devi ce. Not e t hat t hi s i s a si mpl e
i ncr ement al count er . I ni t i al i ze i t by st or i ng 0 i nt o t he sel ect ed
DW.
Acknowl edgement s DW Thi s i s t he number of t i mes t he sl ave devi ce answer s.

Read Holding Registers (3)
Use this command to read the values of a selected group of registers in a slave PLC and write
them into a defined vector of registers in the master.

Parameter Type Function
Sl ave I D Const ant
or MI
The I D of t he devi ce cont ai ni ng t he r egi st er s t o be r ead ( dat a
sour ce) .
Sl ave: St ar t of
Vect or

Const ant ,
MI , ML,
or DW
The st ar t of t he vect or of r egi st er s t o be r ead ( dat a sour ce) .
Read: Vect or
Lengt h
Const ant ,
MI , ML,
or DW
The vect or l engt h.
Mast er : St ar t of
Vect or
MI Thi s i s t he st ar t of a vect or of MI s t hat wi l l cont ai n t he
r egi st er s' val ues i n t he mast er ( dat a dest i nat i on) .
Er r or St at us MI Shows an er r or message number . To di agnose t he er r or ,
check t he MODBUS Er r or Tabl e.
Tot al Sessi ons DW Thi s i s t he number of t i mes t he mast er PLC wi l l at t empt t o
access t he sl ave devi ce. Not e t hat t hi s i s a si mpl e
i ncr ement al count er . I ni t i al i ze i t by st or i ng 0 i nt o t he sel ect ed
DW.
Acknowl edgement s DW Thi s i s t he number of t i mes t he sl ave devi ce answer s.
MODBUS
9
Read Float Registers (3)
Use this command to read the values of a selected group of floating point registers in a slave
device and write them into a defined vector of registers in the master. Values after the decimal
point are rounded to the nearest whole value.

Parameter Type Function
Sl ave I D Const ant
or MI
The I D of t he devi ce cont ai ni ng t he r egi st er s t o be r ead ( dat a
sour ce) .
Sl ave: St ar t of
Vect or

Const ant ,
MI , ML,
or DW
The st ar t of t he vect or of r egi st er s t o be r ead ( dat a sour ce) .
Read: Vect or
Lengt h
Const ant ,
MI , ML,
or DW
The vect or l engt h.
Mast er : St ar t of
Vect or
MI Thi s i s t he st ar t of a vect or of MI s t hat wi l l cont ai n t he
r egi st er s' val ues i n t he mast er ( dat a dest i nat i on) .
Er r or St at us MI Shows an er r or message number . To di agnose t he er r or ,
check t he MODBUS Er r or Tabl e.
Tot al Sessi ons DW Thi s i s t he number of t i mes t he mast er PLC wi l l at t empt t o
access t he sl ave devi ce. Not e t hat t hi s i s a si mpl e
i ncr ement al count er . I ni t i al i ze i t by st or i ng 0 i nt o t he sel ect ed
DW.
Acknowl edgement s DW Thi s i s t he number of t i mes t he sl ave devi ce answer s.
Read Input Registers (4)
Use this command to read the values of a selected group of registers in a slave PLC and write
them into a defined vector of registers in the master.

MODBUS
10
Parameter Type Function
Sl ave I D Const ant
or MI
The I D of t he devi ce cont ai ni ng t he r egi st er s t o be r ead ( dat a
sour ce) .
Sl ave: St ar t of
Vect or

Const ant ,
MI , ML,
or DW
The st ar t of t he vect or of r egi st er s t o be r ead ( dat a sour ce) .
Read: Vect or
Lengt h
Const ant ,
MI , ML,
or DW
The vect or l engt h.
Mast er : St ar t of
Vect or
MI Thi s i s t he st ar t of a vect or of MI s t hat wi l l cont ai n t he
r egi st er s' val ues i n t he mast er ( dat a dest i nat i on) .
Er r or St at us MI Shows an er r or message number . To di agnose t he er r or ,
check t he MODBUS Er r or Tabl e.
Tot al Sessi ons DW Thi s i s t he number of t i mes t he mast er PLC wi l l at t empt t o
access t he sl ave devi ce. Not e t hat t hi s i s a si mpl e
i ncr ement al count er . I ni t i al i ze i t by st or i ng 0 i nt o t he sel ect ed
DW.
Acknowl edgement s DW Thi s i s t he number of t i mes t he sl ave devi ce answer s.
Read Input Float Registers (4)
Use this command to read the values of a selected group of floating point registers in a slave
device and write them into a defined vector of registers in the master. Values after the decimal
point are rounded to the nearest whole value.

Parameter Type Function
Sl ave I D Const ant
or MI
The I D of t he devi ce cont ai ni ng t he r egi st er s t o be r ead ( dat a
sour ce) .
Sl ave: St ar t of
Vect or

Const ant ,
MI , ML,
or DW
The st ar t of t he vect or of r egi st er s t o be r ead ( dat a sour ce) .
Read: Vect or
Lengt h
Const ant ,
MI , ML,
or DW
The vect or l engt h.
Mast er : St ar t of
Vect or
MI Thi s i s t he st ar t of a vect or of MI s t hat wi l l cont ai n t he
r egi st er s' val ues i n t he mast er ( dat a dest i nat i on) .
Er r or St at us MI Shows an er r or message number . To di agnose t he er r or ,
check t he MODBUS Er r or Tabl e.
Tot al Sessi ons DW Thi s i s t he number of t i mes t he mast er PLC wi l l at t empt t o
access t he sl ave devi ce. Not e t hat t hi s i s a si mpl e
i ncr ement al count er . I ni t i al i ze i t by st or i ng 0 i nt o t he sel ect ed
MODBUS
11
DW.
Acknowl edgement s DW Thi s i s t he number of t i mes t he sl ave devi ce answer s.
Force Coil (5)
Use this command to force the status of a selected coil in a slave PLC. The coil's status is
forced according to the status of a selected MB in the master PLC.


Parameter Type Function
Sl ave I D Const ant
or MI
The I D of t he devi ce cont ai ni ng t he coi l t o be f or ced ( dat a
sour ce) .
Sl ave Addr ess

Const ant ,
MI , ML,
or DW
The addr ess of t he coi l t o be f or ced ( dat a sour ce) .
Val ue t o For ce M, SB, I ,
O, T
Thi s MB i s l ocat ed i n t he mast er PLC; t hi s MB cont ai ns t he
st at us t o be f or ced. I f , f or exampl e, t he st at us of t hi s MB i s
OFF, t he st at us of t he coi l i n t he sl ave wi l l be f or ced t o OFF.
Er r or St at us MI Shows an er r or message number . To di agnose t he er r or ,
check t he MODBUS Er r or Tabl e.
Tot al Sessi ons DW Thi s i s t he number of t i mes t he mast er PLC wi l l at t empt t o
access t he sl ave devi ce. Not e t hat t hi s i s a si mpl e
i ncr ement al count er . I ni t i al i ze i t by st or i ng 0 i nt o t he sel ect ed
DW.
Acknowl edgement s DW Thi s i s t he number of t i mes t he sl ave devi ce answer s.

Preset Holding Register (6)
Use this command to preset the value of a single register in a slave PLC. The value is set in a
register contained in the master PLC.
MODBUS
12

Parameter Type Function
Sl ave I D Const ant
or MI
The I D of t he devi ce cont ai ni ng t he r egi st er t o be pr eset
( t ar get ) .
Sl ave: Oper and
Addr ess
Const ant ,
MI , ML,
or DW
The addr ess of t he r egi st er t o be pr eset ( t ar get ) .
Val ue t o Pr eset Const ant ,
MI , SI ,
ML, SL,
DW,
SDW or T
Thi s i s t he addr ess of t he r egi st er cont ai ni ng t he val ue i n t he
mast er PLC ( sour ce) . Thi s val ue wi l l be wr i t t en i nt o t he
sl ave' s r egi st er , t he r egi st er t hat i s t o be pr eset .
St at us MI Shows an er r or message number . To di agnose t he er r or ,
check t he MODBUS Er r or Tabl e.
Tot al Sessi ons DW Thi s i s t he number of t i mes t he mast er PLC wi l l at t empt t o
access t he sl ave devi ce. Not e t hat t hi s i s a si mpl e
i ncr ement al count er . I ni t i al i ze i t by st or i ng 0 i nt o t he sel ect ed
DW.
Acknowl edgement s DW Thi s i s t he number of t i mes t he sl ave devi ce answer s.

Loopback Test (8)
Use this command to send a test message to a slave device and receive Acknowledgements
when communications are functioning properly.

Parameter Type Function
Sl ave I D Const ant
or MI
The I D of t he devi ce t o be checked.
Er r or St at us MI Shows an er r or message number . To di agnose t he er r or , check
t he MODBUS Er r or Tabl e.
Tot al Sessi ons DW Thi s i s t he number of t i mes t he mast er PLC wi l l at t empt t o
access t he sl ave devi ce. Not e t hat t hi s i s a si mpl e i ncr ement al
count er . I ni t i al i ze i t by st or i ng 0 i nt o t he sel ect ed DW.
MODBUS
13
Acknowl edgement s DW Thi s i s t he number of t i mes t he sl ave devi ce answer s.
Force Coils (15)
Use this command to force the status of a selected group of coils in a slave PLC. The coils'
status is forced according to the status of a group of MBs in the master PLC.

Parameter Type Function
Sl ave I D Const ant
or MI
The I D of t he sl ave devi ce cont ai ni ng t he coi l s t o be f or ced
( t ar get ) .
Sl ave: St ar t of
Vect or
Const ant ,
MI , ML,
or DW
The st ar t of t he vect or of coi l s t o be f or ced ( dat a sour ce) .
Mast er : St ar t of
Vect or
MI , SB, I ,
O, T
Thi s i s t he st ar t of a vect or of MBs t hat wi l l cont ai n t he coi l s'
st at us i n t he mast er ( dat a dest i nat i on) .
For ce: Vect or
Lengt h
Const ant
or MI
The vect or l engt h.
Er r or St at us MI Shows an er r or message number . To di agnose t he er r or ,
check t he MODBUS Er r or Tabl e.
Tot al Sessi ons DW Thi s i s t he number of t i mes t he mast er PLC wi l l at t empt t o
access t he sl ave devi ce. Not e t hat t hi s i s a si mpl e
i ncr ement al count er . I ni t i al i ze i t by st or i ng 0 i nt o t he sel ect ed
DW.
Acknowl edgement s DW Thi s i s t he number of t i mes t he sl ave devi ce answer s.
Preset Holding Registers (16)
Use this command to preset the value of a group of registers in a slave PLC. The values are
set in a vector of registers contained in the master PLC.

MODBUS
14
Parameter Type Function
Sl ave I D Const ant
or MI
The I D of t he devi ce cont ai ni ng t he r egi st er s t o be pr eset
( t ar get ) .
Sl ave: St ar t of
Vect or

Const ant ,
MI , ML,
or DW
The st ar t of t he vect or of r egi st er s t o be pr eset ( t ar get ) .
Mast er : St ar t of
Vect or
Const ant ,
MI , SI ,
ML, SL,
DW,
SDW or T
Thi s i s t he st ar t of a vect or of MI s t hat wi l l cont ai n t he
r egi st er s' val ues i n t he mast er ( dat a sour ce) .
Pr eset : Vect or
Lengt h
Const ant ,
MI , ML,
or DW
The l engt h of t he vect or of r egi st er s i n bot h mast er and sl ave.
Er r or St at us MI Shows an er r or message number . To di agnose t he er r or ,
check t he MODBUS Er r or Tabl e.
Tot al Sessi ons DW Thi s i s t he number of t i mes t he mast er PLC wi l l at t empt t o
access t he sl ave devi ce. Not e t hat t hi s i s a si mpl e
i ncr ement al count er . I ni t i al i ze i t by st or i ng 0 i nt o t he sel ect ed
DW.
Acknowl edgement s DW Thi s i s t he number of t i mes t he sl ave devi ce answer s.
Preset Float Registers (16)
Use this command to preset the value of a group of floating point registers in a slave PLC. The
values are set in a vector of registers contained in the master PLC. Values after the decimal
point are rounded to the nearest whole value.

Parameter Type Function
Sl ave I D Const ant
or MI
The I D of t he devi ce cont ai ni ng t he r egi st er t o be pr eset
( t ar get ) .
Sl ave: St ar t of
Vect or
Const ant ,
MI , ML,
or DW
The addr ess of t he r egi st er t o be pr eset ( t ar get ) .
Mast er : St ar t of
Vect or
MI , SI ,
ML, SL,
DW,
SDW or T
Thi s i s t he addr ess of t he r egi st er cont ai ni ng t he val ue i n t he
mast er PLC ( sour ce) . Thi s val ue wi l l be wr i t t en i nt o t he
sl ave' s r egi st er , t he r egi st er t hat i s t o be pr eset .
St at us MI Shows an er r or message number . To di agnose t he er r or ,
check t he MODBUS Er r or Tabl e.
Tot al Sessi ons DW Thi s i s t he number of t i mes t he mast er PLC wi l l at t empt t o
access t he sl ave devi ce. Not e t hat t hi s i s a si mpl e
MODBUS
15
i ncr ement al count er . I ni t i al i ze i t by st or i ng 0 i nt o t he sel ect ed
DW.
Acknowl edgement s DW Thi s i s t he number of t i mes t he sl ave devi ce answer s.
Configuring a MODBUS slave device
The Ladder section below shows what elements are necessary to enable a master device to
read from a slave. Note that the MODBUS Scan operation should not be performed during the
initial program scan.
Note that you must use a condition (RLO) to activate the MODBUS Configuration.

Slave Address Tables
The value in a pointer causes operands in a slave to be accessed as follows:
Registers
Unitronics' slave devices can return requested data in floating point format. Values after the decimal
point are rounded to the nearest whole value.
Poi nt er Val ue
Fr om:
Oper and
t ype
Regi st er si ze Conver t t o Fl oat
0000 MI 16 bi t No
2000 MI 16 bi t Yes
4000 SI 16 bi t No
4550 SI 16 bi t Yes
5100 ML 32 bi t No
MODBUS
16
5600 ML 32 bi t Yes
6100 SL 32 bi t No
6200 SL 32 bi t Yes
6300 MDW 32 bi t No
6500 MDW 32 bi t Yes
6700 SDW 32 bi t No
6800 SDW 32 bi t Yes
6900 Ti mer pr eset 32 bi t No
7200 Ti mer
cur r ent
32 bi t No
7700 MF 0 32 bi t Yes
Coils
Note that you may use MODBUS 'coil' operations'
to refer to any bit operand.
Poi nt er
Val ue
Fr om:
Oper and t ype
0000 MB
3000 SB
4000 I
5000 O
6000 T
MODBUS via GSM or Standard Modem
MODBUS
17


MODBUS Error Table
Error # Error Message
0 No Er r or s
1 I l l egal Funct i on
2 I l l egal Dat a Addr ess
3 I l l egal Dat a Val ue
4 Mast er - - Ti me Out
5 No Communi cat i on
6 Mi smat ched Uni t I D
7 Mi smat ched Command
8 Lengt h of message
9 Funct i on not suppor t ed
10 I l l egal f or mat
11 Mi smat ched r ecei ved dat a



19
I ndex
C
communication.............................................7
M
MODBUS...............................................7, 18
N
network ................................................. 7, 18

You might also like