AC800M Modbus Interface White Paper
AC800M Modbus Interface White Paper
SUMMARY
This document presents sample Modbus serial interface programs written in Structured Text for
the AC800M. Since the system available for testing has not yet been upgraded to 800xA, the
standalone version of Control Builder M Professional (version 3.2/7, system baseline 2) was
used for this exercise. As the Modbus interface function blocks have not changed in the new
system release, the programs documented here should also work with the 800xA system. While
the programs are specific to the test case, they illustrate the requirements for interfacing
Modbus to the AC800M and serve as models for project-specific Modbus implementations.
CONTENTS
1. TEST ENVIRONMENT.......................................................................................................... 3
2. SOFTWARE DESCRIPTION................................................................................................ 4
3. NOTES.................................................................................................................................. 4
3.1 Addressing................................................................................................................... 4
3.2 Hardware Settings....................................................................................................... 5
3.3 Modbus Read/Write Function Codes...........................................................................5
4. APPLICATION_1 - (CONTROLLER_1.NORMAL)...............................................................6
4.1 Data Types.................................................................................................................. 6
4.1.1 ModbusCoilRead............................................................................................... 6
4.1.2 ModbusCoilSend............................................................................................... 7
4.1.3 ModbusRegisterRead........................................................................................7
4.1.4 ModbusRegisterSend........................................................................................ 9
4.1.5 ModbusRegisterStore........................................................................................9
4.2 Programs................................................................................................................... 13
4.2.1 Main - (Controller_1.Normal)...........................................................................13
4.2.2 ProcessPanelDX - (Controller_1.ProcessPanel)..............................................14
4.2.3 ModbusEmulatorDX - (Controller_1.ModbusEmulator)....................................18
4.2.4 Diagnostics - (Controller_1.Slow)....................................................................19
5. HARDWARE AC 800M...................................................................................................... 21
5.1 0 PM860 / TP830............................................................................................... 21
5.1.1 1 Ethernet................................................................................................ 22
5.1.2 2 Ethernet................................................................................................ 22
5.1.3 3 Com...................................................................................................... 23
5.1.4 4 Com...................................................................................................... 23
5.1.5 11 ModuleBus.......................................................................................... 23
5.2 1 CI853.............................................................................................................. 24
5.2.1 1 Com...................................................................................................... 24
5.2.2 2 Com...................................................................................................... 24
ABB Inc.
2 (25)
Doc. no.: JRR0002 en
Rev. ind. 0
10/4/2006 03:34:00
Date
PM
ABB Inc.
3 (25)
Doc. no.: JRR0002 en
Rev. ind. 0
10/4/2006 03:34:00
Date
PM
FIGURES
Figure 1 – Test Environment........................................................................................................ 3
SUPPORTING DOCUMENTS
1. Application Programming, Strategy and Design, EngineerIT AC800M/C, Version 3.2,
document number 3BSE 028 765 R201 Rev B, November 2002.
2. Communication, Protocols and Design, ControlIT AC800M/C, Version 3.2, document
number 3BSE 028 811 R301, October 2002.
ABB Inc.
4 (25)
Doc. no.: JRR0002 en
Rev. ind. 0
10/4/2006 03:34:00
Date
PM
1. TEST ENVIRONMENT
Figure 1 shows the system used to test the Modbus serial connections to the AC800M.
On the AC800M, two serial interfaces run simultaneously. A PC running a 3rd-party Modbus
Emulator package is connected to port 1 of a CI853 serial module, and the RS-232 port on a
Process Panel 235 is connected to port 3 of a PM860. This system is also used to test the Data
Exchange capability of the Process Panel, so the Process Panel is connected to an Allen-
Bradley PLC-5 and provides data transfer to the PM860. Configuration tools (ABB Control
Builder M, ABB Process Panel Builder, and A/B RSLogix) reside on a separate PC connected
via Ethernet to the target devices. This PC is used strictly for configuration and troubleshooting.
The PM860 is the master for all Modbus communications.
In operation, the Process Panel reads data from the PLC-5. This data is then transferred to a
Modbus memory area where it is read by the AC800M. The AC800M also reads data from the
Modbus Emulator on the PC. The AC800M manipulates a subset of the data and performs run
time calculations, then writes back to the Process Panel. The Process Panel displays data both
from the PLC-5 and from the AC800M. The user can reset certain run time counters by
manipulating software switches on the Process Panel.
ABB Inc.
5 (25)
Doc. no.: JRR0002 en
Rev. ind. 0
10/4/2006 03:34:00
Date
PM
2. SOFTWARE DESCRIPTION
The AC800M application comprises three programs.
1. Program ModbusEmulatorDX reads 100 integers from input registers in the PC Modbus
Emulator. These integers are stored in global variable EmulatorValues (structure of 100
ints).
2. Program ProcessPanelDX communicates with the Process Panel. The following reads
and writes are performed:
200 integers are read from holding registers (2 reads of 100 each) and stored in global
variable ModbusRegisterStore (structure of 200 ints).
64 booleans are read from coils and stored in global variable MBCoilRead (structure of
64 bools).
12 integers are written to holding registers from global variable MBRegWrite (structure
of 12 ints).
16 booleans are written to coils from global variable MBCoilWrite (structure of 16 bools).
3. Program Main keeps track of run time and moves data between the input variables and
the output variables.
The programs make use of custom structured data types to read and store data from the various
devices.
Of the Modbus communications programs, ModbusEmulatorDX is very straightforward and is a
good starting point for investigating Modbus operations.
Sections 4 and 5 include the Application and Hardware documentation generated directly from
Control Builder M.
3. NOTES
3.1 Addressing
Standard Modbus addressing is as follows:
Coils (read/write) start at address 00000.
Discrete inputs (read only) start at address 10000.
Input registers (read only) start at address 30000.
Holding registers (read/write) start at address 40000.
In the AC800M, Modbus addresses are not used directly. Instead, the base addresses for each
data type are encoded in the address string as follows:
The address string for coils is ‘%QX10#x’, where x is the coil number starting at 0.
‘%QX10#99’ corresponds to coil 100, address 00099.
The address string for discrete inputs is ‘%IX10#x’, where x is the input number starting
at 0. ‘%IX10#99’ corresponds to discrete input 100, address 10099.
ABB Inc.
6 (25)
Doc. no.: JRR0002 en
Rev. ind. 0
10/4/2006 03:34:00
Date
PM
The address string for input registers is ‘%IW10#x’, where x is the register number
starting at 0. ‘%IW10#99’ corresponds to input register 100, address 30099.
The address string for holding registers is ‘%MW10#x’, where x is the register number
starting at 0. ‘%MW10#99’ corresponds to holding register 100, address 40099.
Note that coil, input, and register addressing is device-specific and can start at either 0 or 1 (i.e.,
the first coil can be either coil 0 or coil 1) depending on the device.
ABB Inc.
7 (25)
Doc. no.: JRR0002 en
Rev. ind. 0
10/4/2006 03:34:00
Date
PM
4. APPLICATION_1 - (CONTROLLER_1.NORMAL)
Name Data Type Attributes Initial value I/O address Access Description
Variables
1 CountReadStarts int retain 0
2 CountWriteStarts int retain 0
3 ReadNotDoneCount int retain 0
4 WriteNotDoneCount int retain 0
5 MBRegStore ModbusRegisterStore retain
6 MBCoilRead ModbusCoilRead retain
7 MBRegWrite ModbusRegisterSend retain
8 MBCoilWrite ModbusCoilSend retain
9 EmulatorValues ModbusRegisterRead retain
4.1.1 ModbusCoilRead
Name Data Type Attributes Initial value Description
1 Coil1 bool retain
2 Coil2 bool retain
3 Coil3 bool retain
4 Coil4 bool retain
5 Coil5 bool retain
6 Coil6 bool retain
7 Coil7 bool retain
8 Coil8 bool retain
9 Coil9 bool retain
10 Coil10 bool retain
11 Coil11 bool retain
12 Coil12 bool retain
13 Coil13 bool retain
14 Coil14 bool retain
15 Coil15 bool retain
16 Coil16 bool retain
17 Coil17 bool retain
18 Coil18 bool retain
19 Coil19 bool retain
20 Coil20 bool retain
21 Coil21 bool retain
22 Coil22 bool retain
23 Coil23 bool retain
24 Coil24 bool retain
25 Coil25 bool retain
26 Coil26 bool retain
27 Coil27 bool retain
28 Coil28 bool retain
29 Coil29 bool retain
30 Coil30 bool retain
31 Coil31 bool retain
32 Coil32 bool retain
33 Coil33 bool retain
34 Coil34 bool retain
35 Coil35 bool retain
36 Coil36 bool retain
37 Coil37 bool retain
38 Coil38 bool retain
39 Coil39 bool retain
40 Coil40 bool retain
ABB Inc.
8 (25)
Doc. no.: JRR0002 en
Rev. ind. 0
10/4/2006 03:34:00
Date
PM
4.1.2 ModbusCoilSend
Name Data Type Attributes Initial value Description
1 Coil1 bool retain
2 Coil2 bool retain
3 Coil3 bool retain
4 Coil4 bool retain
5 Coil5 bool retain
6 Coil6 bool retain
7 Coil7 bool retain
8 Coil8 bool retain
9 Coil9 bool retain
10 Coil10 bool retain
11 Coil11 bool retain
12 Coil12 bool retain
13 Coil13 bool retain
14 Coil14 bool retain
15 Coil15 bool retain
16 Coil16 bool retain
4.1.3 ModbusRegisterRead
Name Data Type Attributes Initial value Description
1 Reg1 int retain
2 Reg2 int retain
3 Reg3 int retain
4 Reg4 int retain
5 Reg5 int retain
6 Reg6 int retain
7 Reg7 int retain
8 Reg8 int retain
9 Reg9 int retain
10 Reg10 int retain
11 Reg11 int retain
12 Reg12 int retain
ABB Inc.
9 (25)
Doc. no.: JRR0002 en
Rev. ind. 0
10/4/2006 03:34:00
Date
PM
ABB Inc.
10 (25)
Doc. no.: JRR0002 en
Rev. ind. 0
10/4/2006 03:34:00
Date
PM
4.1.4 ModbusRegisterSend
Name Data Type Attributes Initial value Description
1 Reg1 int retain
2 Reg2 int retain
3 Reg3 int retain
4 Reg4 int retain
5 Reg5 int retain
6 Reg6 int retain
7 Reg7 int retain
8 Reg8 int retain
9 Reg9 int retain
10 Reg10 int retain
11 Reg11 int retain
12 Reg12 int retain
4.1.5 ModbusRegisterStore
Name Data Type Attributes Initial value Description
1 Reg1 int retain
2 Reg2 int retain
3 Reg3 int retain
4 Reg4 int retain
5 Reg5 int retain
6 Reg6 int retain
7 Reg7 int retain
8 Reg8 int retain
9 Reg9 int retain
10 Reg10 int retain
11 Reg11 int retain
12 Reg12 int retain
13 Reg13 int retain
14 Reg14 int retain
15 Reg15 int retain
16 Reg16 int retain
17 Reg17 int retain
18 Reg18 int retain
ABB Inc.
11 (25)
Doc. no.: JRR0002 en
Rev. ind. 0
10/4/2006 03:34:00
Date
PM
ABB Inc.
12 (25)
Doc. no.: JRR0002 en
Rev. ind. 0
10/4/2006 03:34:00
Date
PM
ABB Inc.
13 (25)
Doc. no.: JRR0002 en
Rev. ind. 0
10/4/2006 03:34:00
Date
PM
ABB Inc.
14 (25)
Doc. no.: JRR0002 en
Rev. ind. 0
10/4/2006 03:34:00
Date
PM
4.2 Programs
4.2.1.1 Code
if First then
Timer(ET,Enable,Hold);
First := false;
end_if;
TotalSeconds := time_to_dint(TimerElapsed(ET))/1000;
TotalHours := TotalSeconds/3600;
Minutes := dint_to_int(mod(TotalSeconds,3600)/60);
MBCoilWrite.Coil1 := MBCoilRead.Coil1;
MBCoilWrite.Coil2 := MBCoilRead.Coil2;
MBCoilWrite.Coil3 := MBCoilRead.Coil3;
MBCoilWrite.Coil4 := MBCoilRead.Coil4;
MBCoilWrite.Coil5 := MBCoilRead.Coil16;
MBCoilWrite.Coil6 := MBCoilRead.Coil24;
MBCoilWrite.Coil7 := MBCoilRead.Coil32;
MBCoilWrite.Coil8 := MBCoilRead.Coil33;
MBCoilWrite.Coil9 := MBCoilRead.Coil34;
MBCoilWrite.Coil10 := MBCoilRead.Coil35;
MBCoilWrite.Coil11 := MBCoilRead.Coil48;
MBCoilWrite.Coil12 := MBCoilRead.Coil49;
MBCoilWrite.Coil13 := MBCoilRead.Coil64;
ABB Inc.
15 (25)
Doc. no.: JRR0002 en
Rev. ind. 0
10/4/2006 03:34:00
Date
PM
CountReadStarts := 0;
CountWriteStarts := 0;
end_if;
MBRegWrite.Reg1 := MBRegStore.Reg1;
MBRegWrite.Reg2 := MBRegStore.Reg100;
MBRegWrite.Reg3 := MBRegStore.Reg180;
MBRegWrite.Reg4 := MBRegStore.Reg190;
MBRegWrite.Reg5 := MBRegStore.Reg191;
MBRegWrite.Reg6 := EmulatorValues.Reg1;
MBRegWrite.Reg7 := dint_to_int(TotalHours);
MBRegWrite.Reg8 := Minutes;
MBRegWrite.Reg9 := ReadNotDoneCount;
MBRegWrite.Reg10 := WriteNotDoneCount;
MBRegWrite.Reg11 := CountReadStarts;
MBRegWrite.Reg12 := CountWriteStarts;
ABB Inc.
16 (25)
Doc. no.: JRR0002 en
Rev. ind. 0
10/4/2006 03:34:00
Date
PM
4.2.2.1 Code
(# Connect on startup. Also connect on timeout (status < 0).
The latter is not strictly required, but appears to be more robust
in practice. After a timeout, the Read or Write operation must be
re-initialized by setting the appropriate request flag.
The counters are for diagnostic purposes. #)
if ConnectStatus = 1 then
repeat
LoopDone := true;
if ReadCycle then
ABB Inc.
17 (25)
Doc. no.: JRR0002 en
Rev. ind. 0
10/4/2006 03:34:00
Date
PM
case ReadNumber of
1 : StartAddrMBR := Address1;
2 : StartAddrMBR := Address2;
3 : StartAddrMBR := Address3;
end_case;
if ReadNumber <= 2 then
MBRead( Req := ReadReq,
Id := Id_MB,
StartAddr := StartAddrMBR,
Ndr => ReadComplete,
Error => ReadError,
Status => ReadStatus,
Rd[1] := MBRegRead );
else
MBRead( Req := ReadReq,
Id := Id_MB,
StartAddr := StartAddrMBR,
Ndr => ReadComplete,
Error => ReadError,
Status => ReadStatus,
Rd[1] := MBCoilRead );
end_if;
if not ReadComplete then
if ReadReq then
ReadReq := false;
else
ReadNotDoneCount := ReadNotDoneCount + 1;
end_if;
else
ABB Inc.
18 (25)
Doc. no.: JRR0002 en
Rev. ind. 0
10/4/2006 03:34:00
Date
PM
if ReadNumber = 3 then
ReadNumber := 1;
WriteReq := true;
ReadCycle := false;
WriteCycle := true;
else
ReadNumber := ReadNumber + 1;
ReadReq := true;
LoopDone := false;
end_if;
end_if;
end_if;
if WriteCycle then
case WriteNumber of
1 : StartAddrMBW := Address5;
2 : StartAddrMBW := Address6;
end_case;
if WriteNumber = 1 then
MBWrite( Req := WriteReq,
Id := Id_MB,
StartAddr := StartAddrMBW,
Done => WriteComplete,
Error => WriteError,
Status => WriteStatus,
Sd[1] := MBRegWrite );
else
MBWrite( Req := WriteReq,
Id := Id_MB,
StartAddr := StartAddrMBW,
Done => WriteComplete,
Error => WriteError,
Status => WriteStatus,
Sd[1] := MBCoilWrite );
End_if;
if not WriteComplete then
if WriteReq then
WriteReq := false;
else
WriteNotDoneCount := WriteNotDoneCount + 1;
end_if;
else
LoopDone := false;
if WriteNumber = 2 then
WriteNumber := 1;
ReadReq := true;
ABB Inc.
19 (25)
Doc. no.: JRR0002 en
Rev. ind. 0
10/4/2006 03:34:00
Date
PM
ReadCycle := true;
WriteCycle := false;
else
WriteNumber := WriteNumber + 1;
WriteReq := true;
end_if;
end_if;
end_if;
until LoopDone end_repeat;
end_if;
4.2.3.1 Code
if ConnectStatus <> 1 or RdStatus < 0 then
MBConnect( En_C := ConnectReq,
Channel := Channel,
Partner := Partner,
Valid => ConnectValid,
Error => ConnectError,
Status => ConnectStatus,
Id := Id_MB );
RdReq := true;
end_if;
ABB Inc.
20 (25)
Doc. no.: JRR0002 en
Rev. ind. 0
10/4/2006 03:34:00
Date
PM
if ConnectStatus = 1 then
repeat
MBRead( Req := RdReq,
Id := Id_MB,
StartAddr := StartAddr,
Ndr => Done,
Error => RdError,
Status => RdStatus,
Rd[1] := EmulatorValues );
if not Done then
RdReq := false;
LoopDone := true;
else
RdReq := true;
LoopDone := false;
end_if;
until LoopDone end_repeat;
end_if;
4.2.4.1 Diagnostics
(* System support *)
ABB Inc.
21 (25)
Doc. no.: JRR0002 en
Rev. ind. 0
10/4/2006 03:34:00
Date
PM
SetTime( );
SetTimeZone( );
(* *);
ABB Inc.
22 (25)
Doc. no.: JRR0002 en
Rev. ind. 0
10/4/2006 03:34:00
Date
PM
5. HARDWARE AC 800M
ABB Inc.
23 (25)
Doc. no.: JRR0002 en
Rev. ind. 0
10/4/2006 03:34:00
Date
PM
5.1.1 1 Ethernet
Parameter Value Type Unit Min Max
IP address 10.127.32.21 string
IP subnet mask 255.255.255.0 string
Network Area 1 dint 0 35
Path Number 0 dint 0 3
Node Number 21 dint 0 500
Network Area Local false bool
Send Period 1 dint s 1 60
Max Lost Messages 3 dint 1 10
Proxy router 10.127.32.5 string
Target address 10.127.32.5 string
5.1.2 2 Ethernet
Parameter Value Type Unit Min Max
IP address 172.16.0.0 string
IP subnet mask 255.255.0.0 string
Network Area 0 dint 0 35
Path Number 0 dint 0 3
Node Number 0 dint 0 500
Network Area Local false bool
Send Period 1 dint s 1 60
Max Lost Messages 3 dint 1 10
Proxy router 0.0.0.0 string
Target address 0.0.0.0 string
Enable Ethernet false bool
channel
ABB Inc.
24 (25)
Doc. no.: JRR0002 en
Rev. ind. 0
10/4/2006 03:34:00
Date
PM
5.1.3 3 Com
Parameter Value Type Unit Min Max
Baudrate 19.2 enum KBIT/S
Parity none enum
Databits 8 enum
Stopbits 1 enum
Flow control None enum
Delay of the RTS-signal 0 dint msec 0 255
5.1.3.1 MODBUS
Parameter Value Type Unit Min Max
MODBUS type Master enum
MODBUS address 1 dint 1 247
Poll time 0 dint msec 0 8000
Timeout time 2000 dint msec 500 6000
Number of resends 3 dint 1 6
5.1.4 4 Com
5.1.4.1 PPP
Parameter Value Type Unit Min Max
IP address 192.168.255.254 string
IP subnet mask 255.255.255.0 string
Network Area 0 dint 0 35
Path Number 0 dint 0 3
Node Number 0 dint 0 500
Network Area Local false bool
Send Period 5 dint s 1 60
Max Lost Messages 3 dint 1 10
Proxy router 0.0.0.0 string
Target address 0.0.0.0 string
Remote IP address 192.168.255.253 string
5.1.5 11 ModuleBus
Parameter Value Type Unit Min Max
External power supervision true bool
Scan Cycle Time 0 dint ms 0 100
ABB Inc.
25 (25)
Doc. no.: JRR0002 en
Rev. ind. 0
10/4/2006 03:34:00
Date
PM
5.2 1 CI853
Channel Name Type Variable I/O description
IW1.0 UnitStatus dint
5.2.1 1 Com
Parameter Value Type Unit Min Max
Baudrate 19.2 enum KBIT/S
Parity none enum
Databits 8 enum
Stopbits 1 enum
Flow control None enum
Delay of the RTS-signal 0 dint msec 0 255
5.2.1.1 MODBUS
Parameter Value Type Unit Min Max
MODBUS type Master enum
MODBUS address 1 dint 1 247
Poll time 0 dint msec 0 8000
Timeout time 2000 dint msec 500 6000
Number of resends 3 dint 1 6
5.2.2 2 Com
Parameter Value Type Unit Min Max
Baudrate 19.2 enum KBIT/S
Parity none enum
Databits 8 enum
Stopbits 1 enum
Flow control None enum
Delay of the RTS-signal 0 dint msec 0 255
5.2.2.1 MODBUS
Parameter Value Type Unit Min Max
MODBUS type Master enum
MODBUS address 11 dint 1 247
Poll time 0 dint msec 0 8000
Timeout time 4000 dint msec 500 6000
Number of resends 3 dint 1 6
ABB Inc.