Modbus Example Program | PDF | Computer Networking | Computer Hardware
0% found this document useful (0 votes)
28 views1 page

Modbus Example Program

Uploaded by

proyectosvendom
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
28 views1 page

Modbus Example Program

Uploaded by

proyectosvendom
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 1

MODBUS RTU A1B1 setting master station, RS485-1 example program

Please note that A1B1/A2B2 can not be both the master station and the slave station
MODBUS RTU sets master station RS485-1, D8400-A1B1 port, 9600 8 1 NONE (communication parameters
can be modified at will). The program needs to call ADPRW by polling
M8002
0 [ MOV H3081 D8400 ]
Select string 1
as MODBUS
protocol, 9600,
8,1,N

[ MOV K0 D8401 ]
Select MODBUS
RTU as the
master station

[ MOV K3 D8412 ]
Timeout retries
3 times

[ MOV K30 D8409 ]


Slave response
timeout 30ms

[ MOV K10 D8411 ]


Delay return data
10ms

[ RST M8410 ]
OFF: ADPRW
sends and
receives data
for serial port 1

[ SET M0 ]
Start serial data
1 transmission

[ SET M10 ]
Restart when
communication
is interrupted
Note that when A1B1 RS485-1 is used as the master station: D8401 is K0, M8410 is 0

M0 <Read D0 data of Station 1 to D1>

30 [ ADPRW K1 K3 K0 K1 D1 ]
Start serial D0 of Station 1
data 1
transmission M8029
[ RST M0 ]
Reset serial
data 1
transmission
[ SET M1 ]
Start serial
data 2
transmission

M1 <Read D0 data of Station 2 to D2>

45 [ ADPRW K2 K0 K0 K1 D2 ]
Start serial D0 of Station 2
data 2
transmission M8029
[ RST M1 ]
Reset serial
data 2
transmission
[ SET M2 ]
Start serial
data 3
transmission

M2 <D1 of D3 data sent to Station 1>

60 [ ADPRW K1 K6 K1 K1 D3 ]
Start serial master station
data 3
transmission M8029
[ RST M2 ]
Reset serial
data 3
transmission
[ SET M3 ]
Start serial
data 4
transmission

M3 <D1 of D3 data sent to Station 2>


75 [ ADPRW K2 K6 K1 K1 D3 ]
Start serial master station
data 4
transmission M8029
[ RST M3 ]
Reset serial
data 4
transmission
[ SET M10 ]
Restart when
communication
is interrupted
[ SET M0 ]
Start serial
data 1
transmission

M10 K50
91 [ T0 ]
Restart when Delay start time
communication of communication
is interrupted T0 interruption
[ SET M0 ]
Start serial
data 1
transmission
[ RST M10 ]
Restart when
communication
is interrupted

MODBUS RTU A2B2 master station, RS485-2 example program


MODBUS RTU sets master station RS485-2, D8420-A2B2 port, 9600 8 1 NONE (communication parameters can
be modified at will). The program needs to call ADPRW by polling
M8002
0 [ MOV H3081 D8420 ]
Select string 1
as MODBUS
protocol,
9600, 8,1, N

[ MOV K0 D8421 ]
Select MODBUS
RTU as the
master station

[ MOV K3 D8432 ]
Timeout retries
3 times

[ MOV K30 D8429 ]


Slave response
timeout 30ms

[ MOV K10 D8431 ]


Delayed return
data 10ms

[ SET M8410 ]
ON: ADPRW sends
and receives data
for serial port 2

[ SET M10 ]
Restart when
communication
is interrupted

[ SET M0 ]
Start serial
data 1
transmission

Note that when A2B2 RS485-2 is used as the master station: D8421 is K0, M8410 is 1

M0 <Read D0 data of Station 1 to D1>

30 [ ADPRW K1 K3 K0 K1 D1 ]
D0 of Station 1
Start serial
data 1
transmission M8029
[ RST M0 ]
Reset serial
data 1
transmission
[ SET M1 ]
Start serial
data 2
transmission

M1 <Read D0 data of Station 2 to D2>

45 [ ADPRW K2 K0 K0 K1 D2 ]
D0 of Station 2
Start serial
data 2
transmission M8029
[ RST M1 ]
Reset serial
data 2
transmission
[ SET M2 ]
Start serial
data 3
transmission

M2 <D3 data is written to D1 of Station 1>

60 [ ADPRW K1 K6 K1 K1 D3 ]
Start serial Master station
data 3
transmission M8029
[ RST M2 ]
Reset serial
data 3
transmission
[ SET M3 ]
Start serial
data 4
transmission

M3 <D3 data is written to D1 of Station 2>


75 [ ADPRW K2 K6 K1 K1 D3 ]
Start serial Master station
data 4
transmission M8029
[ RST M3 ]
Reset serial
data 4
transmission
[ SET M10 ]
Restart when
communication
is interrupted
[ SET M0 ]
Start serial
data 1
transmission

M10 K50
91 [ T0 ]
Restart when Delay start time
communication of communication
is interrupted T0 interruption
[ SET M0 ]
Start serial
data 1
transmission
[ RST M10 ]
Restart when
communication
is interrupted

Description of the ADPRW instruction:

ADPRW S1 S2 S3 S4 S5

The same command ADPRW is used for writing and reading communication with the slave station.
S1: Slave station No
S2: Function code
S3: Slave variable starting address
S4: Number of read/write variables
S5: Read/write of master station, starting address of word or bit
For example:

Example 1

[ ADPRW K1 K3 K0 K1 D1 ]
Read D0 of station 1 and transmit it to D1 of master station
Read only one variable D0 of No. 1 slave station to D1 of master station with H03 command

Example 2
[ ADPRW K1 K3 K0 K5 D1 ]
Read D0-D4 of station 1 and transmit it to D1-D5 of master station
Read only the five variables D0-D4 of No. 1 slave station with the H03 command and transfer them to
D1-D5 of the master station

MODBUS RTU A1B1 setting slave, RS485-1 example program

*Channel RS485-1, port D8400-A1B1, MODBUS-RTU slave station No 1: 9600 8 1 NONE


M8002
0 [ MOV H3081 D8400 ]
Select string 1
as MODBUS
protocol,
9600, 8, 1, N

[ MOV H10 D8401 ]


Select MODBUS RTU
as slave station

[ MOV K10 D8411 ]


Delayed return data:
10ms

[ MOV K1 D8414 ]
Slave station: 1 station

MODBUS RTU A2B2 setting slave, RS485-2 example program


*Channel RS485-2, port D8420-A2B2, MODBUS-RTU slave station 1: 9600 8 1 NONE
M8002
0 [ MOV H3081 D8420 ]
Select string 2
as MODBUS
protocol,
9600, 8, 1, N

[ MOV H10 D8421 ]


Select MODBUS
RTU as slave
station

[ MOV K10 D8431 ]


Delayed return data:
10ms

[ MOV K1 D8434 ]
Slave station: 1 station

You might also like