Professional Documents
Culture Documents
Document No.:ED-2002-045
Version: 1.0
MESSUNG SYSTEMS
EL-2, J- Block MIDC Bhosari,
Pune – 411026.(INDIA)
Revision
Warning !
INDEX
1. INTRODUCTION ......................................................................................................................... 5
2. RTU_SLAVE (FB) ........................................................................................................................ 7
2.1 PLC VARIABLES AND RANGE SUPPORTED BY FB .................................................................... 9
2.2 MEMORY MAPPING FOR PROCESSOR 521X............................................................................. 10
3. RTU_MASTER (FB)................................................................................................................... 12
3.1 PLC VARIABLES AND RANGE SUPPORTED BY FB .................................................................. 18
APPENDIX 1 RTU_COMSET.......................................................................................................... 19
APPENDIX 2 PLC VARIABLES AND RANGE SUPPORTED BY PROCESSOR 521X......... 22
APPENDIX 3 MODBUS COMMANDS SUPPORTED BY FB ..................................................... 23
1. Introduction
Depending on the CPU model, ports Com1, Com2 and Com3 are available.
Please refer to Nexgen5000 CPU user manual for model wise features. All
the three serial ports support open protocol and user can communicate with
any third party device using communication driver functions.
Modbus protocol is one of the standard and most commonly used serial
protocols in Industrial communication. The protocol was introduced by
Modicon Inc. for communicating between multiple intelligent devices and was
then opened for everybody’s use.
More details of the protocol and the standard protocol document can be
downloaded from website www.modbus.org
Beijer make E terminal has RS-232 and RS-422 hardware interface and it
can be connected to RS-232 or RS-422 hardware interfaces with different
serial link cables..
2. RTU_SLAVE (FB)
Description of Parameters-
PORT VAR_IN BYTE This input byte holds communication port number to
be activated with Modbus RTU slave FB. It should
contain constant value of 1 or 2 or 3 for Port 1, Port
2, Port 3 respectively. Any other value is invalid.
SNO VAR_IN BYTE This input byte hold the station number. Valid range
is from 1 to 247. For invalid station number above
247, FB is not executed. Apart from the commands
received for this station, the broadcast commands
(station number as 0) are also executed.
COMSET VAR_IN RTU_Comset This is input variable of user defined data type
RTU_Comset. It defines communication parameter
settings like baud rate, parity, operation mode, etc
for a slave device. Appendix 1 provides the details of
various communication parameter settings.
Status VAR_OUT BYTE This output BYTE holds the status of execution
Status.0 This bit is TRUE when port is opened
successfully with the communication
parameters assigned.
Status.1 This bit is TRUE if checksum error is observed
in recent reception.
Status.2 This bit is TRUE if timeout of 1 sec is observed
in recent reception.
Replies VAR_OUT WORD This word holds number of healthy replies send to the
commands received from master. After 65535, value rolls
over to 0.
STN_Errs VAR_OUT WORD This word holds number of commands with different
station numbers received from master. After 65535, value
rolls over to 0. User should take proper action if such
errors are detected.
FNC_Errs VAR_OUT WORD This word holds number of invalid function code in
command received from master. After 65535, value rolls
over to 0. User should take proper action if such errors
are detected.
Example –
Variable Range
Coils 00001 to 12048
Input bits 10001 to 11024
15001 to 17048 ( Range extended from 15000 to 17048 for Output bits)
Input Registers 30001 to 30128
35001 to 35128 ( Range extended from 35001 to 35128 for Output Registers)
Holding Registers 40001 to 47936
For Modbus protocol, variable addresses start from 1. For the variables defined
with address 0 ( 00000, 10000, 30000, 40000 ) are ignored.
Nexgen 5000 Processor supports 2048 Input BOOLs from %IX0.0 to %IX255.7.
They are mapped from 10001 to 12048.
Here, input bit variable %IXmmm.n is mapped at Modbus variable
10001+(mmm*8)+n
Mmm is byte number from 0 to 255 and n is bit number from 0 to 7.
Variable Range Mapping in 1nnnn Variables
Input %IX0.0 to %IX0.7 10001 to 10008
BOOL %IX1.0 to %IX1.7 10009 to 10016
%IX2.0 to %IX2.7 10017 to 10024
3. RTU_MASTER (FB)
Description of Parameters-
PORT VAR_IN BYTE This input byte holds communication port number to be
activated with Modbus RTU slave FB. It should contain
constant value of 1 or 2 or 3 for Port 1, Port 2, Port 3
respectively. Any other value is invalid.
COMSET VAR_IN RTU_Comset This is input variable of user defined data type
RTU_Comset. It defines communication parameter
settings like baud rate, parity, operation mode, etc for a
master device. Appendix 1 provides the details of various
communication parameter settings.
GrSel VAR_IN BYTE This byte selects the sequence of sending commands
defined by array of records of type RecStruct.
0 This selects manual mode of operation. The
command defined by RecNo is sent once at rising
edge of Start input.
1 This selects auto mode of operation. The commands
with Gr=1 defined in array of records of type
RecStruct are sent one by one cyclically.
>1 This selects auto mode of operation. The commands
with Gr=1 and Gr=GrSel defined in array of records
of type RecStruct are sent one by one cyclically.
RecNo VAR_IN BYTE This byte holds record number in array of records of type
RecStruct to be sent is manual mode. In auto mode, this
input is ignored.
Start VAR_IN BOOL FB sends command defined by RecNo in manual mode at
rising edge of Start input. If a particular slave device is not
responding, FB retries as explained earlier. In auto mode,
this input is ignored.
TYPE RecStruct :
STRUCT
Gr: BYTE;
FNC:BYTE;
SNo :BYTE;
LDT : TT;
LAdr: WORD;
RAdr:WORD;
DLen:BYTE;
END_STRUCT
END_TYPE
Gr BYTE The command can be grouped for
sending an auto mode or manual
mode..
0- Normally, command with group
number 0 is sent once when
manual mode is initiated.
1- By default, commands with group
number 1 are sent cyclically in auto
mode. These group commands
also can be sent in manual mode.
<1- The commands with group
number defined in GrSel are sent
cyclically along with commands
with group number 1 in auto mode.
These group commands also can
be sent in manual mode.
FNC BYTE This byte defines the function code for
command as per Modbus protocol. The
function codes supported by FB are
given below. Appendix 3 provides more
details.
01 Read Coil Status
02 Read Input Status
03 Read Holding Register
04 Read Input Registers
05 Force Single Coil
06 Preset Single Register
15 Force Multiple Coils
16 Preset Multiple Registers
MaxRec VAR_IN BYTE This byte holds total number of records in an array.
Status VAR_OUT BYTE The bits in byte returns the status of FB as below.
Bit Significance
0 Recent record executed successfully
1 Checksum error in reception.
2 Timeout error
3 Unknown FNC in RecTable
4 End of RecTable reached
LastRec VAR_OUT BYTE This byte holds the index of Records which is recently
executed.
LastResult VAR_OUT BYTE This BOOLean variable holds the result of execution of
last record.
Example 1-
First record in the array sends command to write ( as FNC is 16) contents of
local marker word %MW10 to remote Modbus slave (station number 1)at
holding register 40100.
Second record in the array sends command to write ( as FNC is 16) contents
of local marker word %MW12 to %MW18 ( 4 words) to remote Modbus slave
(station number 1)at holding register 40101, 40102, 40103, 40104
respectively.
When GrSel is 2, all the records with Gr 2 are executed one by one along
with the records with Gr 1.
Sixth record in the array sends command to write ( as FNC is 16) contents of
local marker word %MW20 to %MW28 ( 5 words) to remote Modbus slave
(station number 1)at holding register 40110 to 40114.
%MW12 40101
%MW14 Records[1] writes %MW10 - %MW18 to 40102
%MW16 40101 - 40104 40103
Gr 1 %MW18 40104
commands
%MW20 40105
%MW22 40106
Records[2] reads 40105 – 40109 to
%MW24 40107
%MW20 - %MW28
%MW26 40108
%MW28 40109
%MW32 40101
%MW34 Records[4] reads 40101 – 40104 40102
%MW36 to%MW32 - %MW38 40103
Gr 2 %MW38 40104
commands
%MW20 40110
%MW22 40111
Records[5] writes %MW20 - %MW28
%MW24 To 40110 – 40114 40112
%MW26 40113
%MW28 40114
Variable Range
Coils 00001 to 09999
Input bits 10001 to 19999
Input Registers 30001 to 39999
Holding Registers 40001 to 49999
For Modbus protocol, variable addresses start from 1. For the variables defined
with address 0 ( 00000, 10000, 30000, 40000 ) are ignored.
Appendix 1 RTU_ComSet
This is user defined data type provided in Modbus library. The definition of
this user defined data type along with default values is as shown below.
TYPE RTU_ComSet :
STRUCT
ComSet : WORD:=16#4305;
TX_delay : BYTE := 0;
RX_Delay :BYTE := 0;
Time_out : TIME:= t#1s;
RetryCount : BYTE:=1;
END_STRUCT
END_TYPE`
Bits F E D C B A 9 8 7 6 5 4 3 2 1 0
ComSet is a word for
Receive Buffer Initialization
Baud Rate Group selection
decides communication
Software Handshake
Baud Rate
Parity
2400 0 0 0 0 0 0 1 1 16#3
4800 0 0 0 0 0 1 0 0 16#4
9600 0 0 0 0 0 1 0 1 16#5
14400 0 0 0 0 0 1 1 0 16#6
19200 0 0 0 0 0 1 1 1 16#7
28800 0 0 0 0 1 0 0 0 16#8
38400 0 0 0 0 1 0 0 1 16#9
57600 0 0 0 0 1 0 1 0 16#A
115200 0 0 0 0 1 0 1 1 16#B
230400 0 0 0 0 1 1 0 0 16#C
F E D C B A 9 8
No. of Data Bits 7 data bits 0
Bit 8 decides number of data bits.
8 data bits 1
Parity No parity 0 0
Bits 9 and A decides parity.
Odd parity 0 1
Even parity 1 0
Invalid 1 1
No. of Stop Bits 1 stop bit 0
Bit B decides number of stop bits
2 stop bit 1
Communication Mode
Bit C decides communication
mode. If half duplex mode is Half duplex 0
selected, reception is disabled
during transmission and vice versa.
For full duplex mode, reception is
possible during transmission and
vice versa. If full duplex mode is
selected for RS-485, echo is
Full duplex 1
received while transmission. User
should take care for handling such
communication.
Software Handshake XON/XOFF control disable 0
Bit D selects software handshake.
XON/XOFF control enable 1
Receive Buffer Initialization No Initialization 0
RxDelay BYTE RxDelay is a delay for starting reception after completion of any
transmission. This delay is active while receiving first byte after any
transmission. It is a character delay and varies according to
communication parameter settings. This is applicable only in half duplex
mode.
Actual time delay = (No. of parity bits+ No. of stop bits for transmission+
No. of data bits)*RxDelay / BPS
TxDelay BYTE TxDelay is a delay for starting transmission after completion of any
reception. This delay is active while transmitting first byte after any
reception. It is a character delay and varies according to communication
parameter settings. This is applicable only in half duplex mode.
Actual time delay = (No.of parity bits+ No. of stop bits for reception+
No. of data bits)* TxDelay / BPS
TimeOut TIME This parameter is applicable for RTU_MASTER FB. This is the time with 1
ms resolution within which a specific slave device should respond to a
command otherwise predefined retries are carried out . In case of
broadcast commands, master waits for the time duration defined by
TimeOut and after that master initiates next command.
RetryCnt BYTE This parameter is applicable for RTU_MASTER FB. This byte hold number
of retries FB should do if a specific slave device is not responding. If slave
device does not respond even after number of retries, communication error
for that slave device is confirmed.
IX255.0 to IX255.7
Input WORD %I W IW0, IW2, IW4 to IW254 128
Output BOOL %Q X QX0.0 to QX0.7 2048
(X is optional) QX1.0 to QX1.7
QX254.0 to QX254.7
Output WORD %Q W QW0, QW2, QW4 to QW254 128
Marker BOOL %M X MX0.0 to MX0.7 126976
(X is optional) MX1.0 to MX1.7
%MX15871.0 to %MX15871.7
Marker WORD %M W %MW0, %MW2, %MW4 to %MW15870 7936
Function
Variable Meaning Action
Code
01 Read Coil Status Obtains current status (TRUE/FALSE) of a
group of a coils
Coil 05 Force Single Coil Force coil to a status of TRUE or OFF.
15 Force Multiple Coils Force a series of consecutive coils to defined
TRUE or FALSE status
02 Read Input Status Obtains current status (TRUE/FALSE) of a
Input bit
group of digital inputs.
Input 04 Read Input registers Obtain current binary value in one or more input
Registers registers.
03 Read Holding Registers Obtain current binary value in one or more
holding registers.
Holding 06 Preset Single Register Write a specific binary value into a holding
Registers register.
16 Preset Multiple Registers Write specific binary values into a series of
consecutive holding registers.
MESSUNG SYSTEMS
EL – 2, J - Block, MIDC, Bhosari,
PUNE – 411 026. INDIA
Tel. – (+91) –020 – 712 0807, 712 2807
Fax. – (+91) –020 –712 0391
Document No.:ED-2002-045