Beruflich Dokumente
Kultur Dokumente
03/04 AN2700K24G V1.0 All brand and product names are trademarks or
© Moeller GmbH, Bonn registered trademarks of the owner concerned.
Autor: O. Weiß
All rights reserved, including those of the translation.
No part of this application note may be reproduced in
any form (printed, photocopy, microfilm or any other
process) or processed, duplicated or distributed by
means of electronic systems without the expressed
written permission of Moeller GmbH, Bonn.
Status: April 2001
Subject to modification
MODBUS RTU Master/Slave for XC Controls
Contents
1 General points................................................................................................................................................................... 3
1.1 Function ......................................................................................................................................................................... 3
1.2 Field of application ......................................................................................................................................................... 3
1.3 Hardware requirements and possible COM ports.......................................................................................................... 4
1.4 Software requirements................................................................................................................................................... 4
2 Design............................................................................................................................................................................... 4
2.1 Structure ........................................................................................................................................................................ 4
2.2 Functions blocks and parameters.................................................................................................................................. 5
2.2.1 MODBUS Master ........................................................................................................................................................ 5
2.2.2 MODBUS Slave .......................................................................................................................................................... 6
3 Commissioning ................................................................................................................................................................. 7
3.1 Integration of the MODBUS connection......................................................................................................................... 7
3.2 Method of function and operation of the MODBUS connection ..................................................................................... 7
3.2.1 MODBUS master ........................................................................................................................................................ 7
3.2.2 MODBUS slave........................................................................................................................................................... 8
3.3 Exception codes............................................................................................................................................................. 9
3.4 Examples ....................................................................................................................................................................... 9
4 Annex .............................................................................................................................................................................. 10
4.1 Connector and connections of the controllers ............................................................................................................. 10
4.1.1 XC100 programming port ......................................................................................................................................... 10
4.1.2 XIOC-SER................................................................................................................................................................. 10
4.1.3 COM port of XVC100, HPG and XC600 ................................................................................................................... 10
1 General points
The MODBUS is a centrally polled bus system where the master controls the entire data transfer on the bus and where
no cross transfer between the slave stations is possible. Each exchange of data is initiated by the master on request. A
slave cannot initiate data transfer as it can only respond on demand.
For the development of the function block, the definitions of the MODBUS Protocol Reference Guide, PI-MBUS-300 Rev.
B, Issue January 1985, Gould Inc. Andover, Massachusetts, USA have been considered.
1.1 Function
The application note provides the MODBUS-RTU master and slave interface for all controls of the X series with the
following options.
Function Codes:
*)
The “Inputs” are realised as Coils and Holding registers via data fields. The functions do not directly access
physical inputs.
Master:
Max. 120 (90 with XC100 via PRG-Port) Registers / 1200 Coils per job
Slave:
Freely configurable number of Modbus data via global variable field. With every message a max. of 120 (90 with XC100
via PRG-Port) Registers / 1200 Coils can be exchanged.
The hardware interface used with the MODBUS is COM1 (PRG-Port) or depending on the control type the XIOC-SER
serial module. No additional software is required here as the MODBUS function block also supports the required
functions of the COM interface.
The application note also supports broadcast access for the function codes 05, 06, 15 and 16 with master and with slave
implementation. The MODBUS master addresses the MODBUS slave “0” for this purpose.
The application note is intended for use where the connection to a PLC system or a PLC via MODBUS RTU is required.
Note: The reaction and response times are dependant on the PLC cycle time. It is very important to take this factor into
consideration with the timing demands involved with MODBUS interfacing.
XSoft from V2.3 (from V2.3.2.6 for XC200), for XIOC-SER related targets
2 Design
2.1 Structure
The ModbusMaster and ModbusSlave function blocks are now provided in the libraries with the same name:
ModbusMaster.Lib
ModbusSlave.Lib
Note: The library must be imported from the respective control-specific subdirectory.
If MODBUS slave interfacing is to be implemented, the MODBUSSLAVE_DATASIZE.EXP export file must also be
imported. The Modbus data fields of the slave are dimensioned here.
ModbusMaster
VAR_INPUT
xEnable Enable of the MODBUS connection
usiComPort COM-Port: XC100->1,2,3; XC200->2,3,4,5; XVC100/HPG/XC600->1
uiBaudrate Baud rate of the COM port (4800, 9600, 19200, 38400, 57600)
usiParity Character parity format: none -> 0, odd -> 1, even -> 2
usiStopBits Stop bit character format: 1, 2
usiMODSlaveAdr Address of the MODBUS slaves to be accessed
usiMODfc Function Code: 1, 2, 3, 4, 5, 6, 8, 15, 16 provided they are supported by the
slave
uiMODdatOff Data offset in the slave for the data to be transferred
uiMODdatNr Number of data packages for transfer (maximum is the possible telegram
length)
tMODtimeOut Timeout for slave response
xMODfcStrobe Start (FC) job
VAR_IN_OUT
warMODRegister MODBUS data: Buffer for receive or send register (Holding/Input)
xarMODCoil MODBUS data: Buffer for receive or send BOOL variables (Coils/Inputs)
VAR_OUTPUT
xComPortActiv COM port has been successfully opened, MODBUS connection established
xMODtransActive MODBUS job active
xMODtransOk MODBUS job successfully completed
usiMODslaveAdrDone Slave last contacted
usiMODfcDone Function code of the last executed job
uiMODdatOffDone Slave data offset for the last job executed
uiMODdatNrDone Number of MODBUS data packages sent with the last job
usiMODfailCode Exception code of the last job executed
ModbusSlave
*)
ARRAY[1..a ] OF WORD warHoldingRegister
*)
ARRAY[1..b ] OF WORD warInputRegister
*)
ARRAY [1..c ] OF BOOL xarCoil
*)
ARRAY [1..d ] OF BOOL xarInput
*)
Maximum number of MODBUS data packages, configured in the MODBUSSLAVE_DATASIZE.EXP global variable
list to be imported:
a: ModbusSlave_uiMaxHoldingRegister :UINT
b: ModbusSlave_uiMaxInputRegister : UINT
c: ModbusSlave_uiMaxCoil : UINT
d: ModbusSlave_uiMaxInput : UINT
VAR_INPUT
xEnable Enable of the MODBUS connection
usiComPort COM-Port: XC100->1,2,3; XC200->2,3,4,5; XVC100_HPG_XC600->1
uiBaudrate Baud rate of the COM port (4800, 9600, 19200, 38400, 57600)
usiParity Character parity format: none -> 0, odd -> 1, even -> 2
usiStopBits Stop bit character format: 1, 2
usiMODSlaveAdr Address of the MODBUS slaves
VAR_IN_OUT
warHoldingRegister MODBUS data: Holding register
warInputRegister MODBUS data: Input register
xarCoil MODBUS data: Coils
xarInput MODBUS data: Inputs
VAR_OUTPUT
xComPortActiv COM port has been successfully opened, MODBUS connection enabled
xFrameReceived MODBUS job received (pulse)
usiMODfc Function code of the last executed job
uiMODdatOff Data offset for the last job executed
uiMODdatNr Number of MODBUS data packages to be sent with the last job
usiMODfailCode Exception code of the last job
3 Commissioning
For the master connection, the ModbusMaster.Lib library must be imported from the respective control-specific
subdirectory and the FB ModbusMaster function block of the same name is to be accessed and parameterized.
For the slave connection the ModbusSlave.Lib library must be imported from the respective control-specific
subdirectory and the FB ModbusSlave function block of the same name is to be accessed and parameterized.
Furthermore, the MODBUSSLAVE_DATASIZE.EXP export file must also be imported for connection of the slave. In the
project, the ModbusSlave_DataSize global variable list is created with the import. The sizes of the required MODBUS
data field should be entered as constants in the list. The fields are sized by default for 100 elements. If a field is not
required, the constant 1 should be entered in order to reduce unnecessary loading on the data memory.
The slave only provides the master with the elements configured here !
Note:
The Internal Functions which are also available in the library are used exclusively for internal purposes and should not be
accessed by the user !
Only a single instance is permitted per COM port, regardless of it is a slave or master !
The control-specific COM library is automatically integrated during import of the libraries. These are required for
actuation of the serial interface.
The MODBUS function block should be executed cyclically in order to avoid any possible time-outs with the
communication parameters.
The parameterized COM port (input usiComPort) is opened with a rising edge on xEnable and is initialised with the
uiBaudrate, usiParity and usiStopbits parameters. The data capacity is fixed at 8 bits (RTU Binary). The serial interface
remains open as long as the xEnable signal remains high. The COM Port closes again when the signal goes low.
If the signal was established via the programming port, the serial interface is only available again to the programming
device after the COM Port has been closed. Open COM ports are also automatically closed when the operating mode of
the control changes from RUN to STOP.
A High signal on the xComPortActiv output signals successful opening of the COM Port.
The MODBUS telegram recognition occurs automatically.
Every data transfer on the bus is initiated and controlled by the master.
A high level on the xMODfcStrobe input starts the job whose function is determined by the function code entered at the
usiMODfc input. Communication with the MODBUS station whose address has been parameterized on the
usiMODslaveAdr input is undertaken.
The MODBUS input parameters are interpreted differently and depend on the function code:
The warMODRegister and xarMODCoil buffers are always read or written by the master from the first index
(MODBUS -> 1).
The xMODtransActive output is High during job execution – until the slave response is received. After the job has been
completed, the output returns to “FALSE” and xMODtransOk is set to “1” if a telegram fault, protocol fault, data fault or
other communication fault has not occurred.
During a fault xMODtransOk remains at “FALSE” and the fault is described with the usiMODfailCode exception code
(see also the “Exception code” section).
If the slave does not answer within the set tMODtimeOut timeout time, a respective error message is issued here.
The MODBUS telegram of the master receives a response after the COM port is opened by the function block.
The slave exhibits a totally passive behaviour on the MODBUS. It will only respond to a request from the master.
Every valid MODBUS telegram which is received on the COM port is indicated by a pulse on the xFrameReceived
output.
The usiMODfc output describes the last job sent by the master. On the uiMODdatOff and uiMODdatNr outputs you can
read the start address and the data count of the received or sent data. Both outputs are updated from function blocks for
diagnostics even with a telegram fault.
With the Function Codes 5,6 and 8 uiMODdatNr describes the written value.
usiMODfailCode describes as is the case with the master, a telegram fault, protocol fault, data fault or other
communication fault (see also the “Exception codes” section).
usiMODfailCode:
00 : Ok
01 : Invalid function code
02 : Invalid slave data address
03 : Invalid value
04 : MODBUS device fault, telegram length fault
10 : Parameter fault
11 : Fault during opening or initialisation of the COM port
12 : CRC fault
*)
13 : MODBUS timeout
*)
14 : Slave address fault
*)
15 : Slave responds with incorrect FC
*)
16 : Slave responds with false number or offset of the data
*)
Only with ModbusMaster master function block
3.4 Examples
In the \Examples subdirectory you will find program examples for the integration of the master and slave connection in
the MODBUSSLAVEEXAMPLE.EXP and MODBUSMASTEREXAMPLE.EXP export file format.
After import of the required file the respective subdirectory is created in the project. Here you will find both the example
programs ModbusSlaveExampleVis or ModbusMasterExampleVis and ModbusSlaveExampleApp or
ModbusMasterExampleApp. The program with the “Vis” ending supports the visualisation with which the complete
function block can be operated and visualised. The program with the ending “App” is used for accessing the function
blocks in the standard manner -> parameterization of various inputs via constants.
The slave program example also has the required MODBUSSLAVE_DATASIZE.EXP export file (with default settings).
4 Annex
4.1.2 XIOC-SER
The card supports the RS232 physical interface (SUB-D 9 pin male) as well as the RS485 / RS422 (COMBICON):