WAGO-I/O-PRO 32 library
ModbusEthernet_04.lib
The ModbusEthernet_04.lib library provides the user with the two function modules, ETHERNET_MODBUSMASTER_UDP and
ETHERNET_MODBUSMASTER_TCP.
With these modules, a data exchange can be set up with several Modbus TCP / UDP slaves.
The ETHERNET_MODBUSMASTER_UDP module should be used in preference, as this enables faster data transfer.
The ETHERNET_TERMINAL_MODBUSSLAVE module is also included in the library.
This module provides a Modbus server, which maps the Modbus services to a word array.
Content
ModbusEthernet_04.lib 3
ETHERNET_MODBUSMASTER_UDP ... 3
ETHERNET_MODBUSMASTER_TCP ... 5
ETHERNET_MODBUSMASTER_RTU ... 7
ETHERNET_CLIENT_OPEN_CLOSE... 9
IP_ADRESSE ... 10
ETHERNET_TERMINAL_MODBUSSLAVE ... 11
ETHERNET_SERVER_OPEN_CLOSE ... 13
typETH_SLAVE_DATEN (data type) ... 14
ETHERNET_MODBUSMASTER_UDP
ModbusEthernet_04.lib
ETHERNET_MODBUSMASTER_UDP
WAGO-I/O-PRO 32 Library elements
Category: Communications module
Name: ETHERNET_MODBUSMASTER_UDP
Type: Function Function block X Program Library name: ModbusEthernet_04.lib
Requiered libraries Ethernet.lib
Applicable to: Fieldbus controller 750-842 from FW: 02.02.00(04) Fieldbus controller 750-841
Input parameter: Data type: Comment:
bUNIT_ID BYTE Fills the “UnitId” field in the Modbus protocol header.
Use:
- References the slave ID in a serial Modbus sub-network.
- Buffer index of the Modbus slave on the PC in conjunction with ActiveMBTSlaveCtl.
bFUNCTION_CODE BYTE The following Modbus function codes are supported:
FC1: (0x01) – read coils
FC2: (0x02) – read input discretes FC3: (0x03) – read multiple registers FC4: (0x04) – read input registers FC5: (0x05) – write coil
FC6: (0x06) – write single register FC7: (0x07) – read exception status FC11: (0x0B) – get comm event counter FC15: (0x0F) – force multiple coils FC16 (0x10) – write multiple registers FC23 (0x17) – read write multiple registers wREAD_ADDRESS WORD Modbus address in slave to be read.
wREAD_QUANTITY WORD Number of bits or words to be read.
ptREAD_DATA POINTER
TO BYTE
Pointer to the local data range in which the read data are stored.
wWRITE_ADDRESS WORD Modbus address in slave to be written.
wWRITE_QUANTITY WORD Number of bits or words to be written.
ptSEND_DATA POINTER
TO BYTE
Pointer to the local data range in which the data to be written are stored.
xSTART BOOL Initiate Modbus telegram
xRESET BOOL Reset internal data
tTIME_OUT TIME Maximum waiting time for the reply telegram from the Modbus slave.
ETHERNET_MODBUSMASTER_UDP
Return value: Data type: Comment:
xREADY BOOL Data transfer is complete or the waiting time parameterised in tTIME_OUT has expired.
wERROR WORD 0x0000 – Successful
0x0001 – Illegal function code 0x0002 – Illegal data address 0x0003 – Illegal data value 0x0004 – Slave device failure 0x0005 – Acknowledge 0x0006 – Slave device busy 0x0007 – Negative acknowledge 0x0008 – Memory parity error 0x000A – Gateway path unavailable 0x000B – Gateway target no response 0x0095 – Error Socket-Close
0x0096 – no valid Socket from FW 0x0097 – Illegal number of points 0x0098 – Internal buffer overrun 0x0099 - TimeOut
bRESPONSE_UNIT_ID BYTE Content of the “UnitId” field in the Modbus protocol header of the reply telegram Graphical description:
Functional description:
With the ETHERNET_MODBUSMASTER_UDP module, an Ethernet controller becomes the Modbus master.
The number of slaves is only limited by the Modbus protocol.
The ETHERNET_MODBUSMASTER_UDP uses the UDP protocol (User Datagram Protocol) and thus enables data to be exchanged more quickly than the TCP version.
ETHERNET_MODBUSMASTER_TCP
WAGO-I/O-PRO 32 Library elements
Category: Communications module
Name: ETHERNET_MODBUSMASTER_TCP
Type: Function Function block X Program Library name: ModbusEthernet_04.lib
Requiered libraries Ethernet.lib
Applicable to: Fieldbus controller 750-842 from FW: 02.02.00(04) Fieldbus controller 750-841
Input parameter: Data type: Comment:
strIP_ADDRESS STRING IP address of Modbus slave.
bUNIT_ID BYTE Fills the “UnitId” field in the Modbus protocol header.
Use:
- References the slave ID in a serial Modbus sub-network.
- Buffer index of the Modbus slave on the PC in conjunction with ActiveMBTSlaveCtl.
bFUNCTION_CODE BYTE The following Modbus function codes are supported:
FC1: (0x01) – read coils
FC2: (0x02) – read input discretes FC3: (0x03) – read multiple registers FC4: (0x04) – read input registers FC5: (0x05) – write coil
FC6: (0x06) – write single register FC7: (0x07) – read exception status FC11: (0x0B) – get comm event counter FC15: (0x0F) – force multiple coils FC16 (0x10) – write multiple registers FC23 (0x17) – read write multiple registers wREAD_ADDRESS WORD Modbus address in slave to be read.
wREAD_QUANTITY WORD Number of bits or words to be read.
ptREAD_DATA POINTER
TO BYTE
Pointer to the local data range in which the read data are stored.
wWRITE_ADDRESS WORD Modbus address in slave to be written.
wWRITE_QUANTITY WORD Number of bits or words to be written.
ptSEND_DATA POINTER
TO BYTE
Pointer to the local data range in which the data to be written are stored.
xSTART BOOL Initiate Modbus telegram
xRESET BOOL Reset internal data
tTIME_OUT TIME Maximum waiting time for the reply telegram from the Modbus slave.
Example: t#500ms
ETHERNET_MODBUSMASTER_TCP
Return value: Data type: Comment:
xREADY BOOL Data transfer is complete or the waiting time parameterised in tTIME_OUT has expired.
wERROR WORD 0x0000 – Successful
0x0001 – Illegal function code 0x0002 – Illegal data address 0x0003 – Illegal data value 0x0004 – Slave device failure 0x0005 – Acknowledge 0x0006 – Slave device busy 0x0007 – Negative acknowledge 0x0008 – Memory parity error 0x000A – Gateway path unavailable 0x000B – Gateway target no response 0x0097 – Illegal number of points 0x0098 – Internal buffer overrun 0x0099 – TimeOut
bRESPONSE_UNIT_ID BYTE Content of the “UnitId” field in the Modbus protocol header of the reply telegram Graphical description:
Functional description:
With the ETHERNET_MODBUSMASTER_TCP module, an Ethernet controller becomes the Modbus master using the TCP protocol.
The number of slaves is only limited by the Modbus protocol.
The ETHERNET_MODBUSMASTER_TCP module should only be used when this is necessitated by the remote station. The Beijer E300 operating terminal, for example, supports only MODBUS –TCP.
The disadvantage of the TCP protocol is its basic connection-orientated concept. As a result of this, a new connection is set up for each data transfer, which leads to a costly protocol
overhead in terms of time.
ETHERNET_MODBUSMASTER_RTU
WAGO-I/O-PRO 32 Library elements
Category: Communications module
Name: ETHERNET_MODBUSMASTER_RTU
Type: Function Function block X Program Library name: ModbusEthernet_04.lib
Requiered libraries Ethernet.lib
Applicable to: Fieldbus controller 750-842 from FW: 02.02.00(04) Fieldbus controller 750-841
Input parameter: Data type: Comment:
SOCKET WORD
UNIT_ID BYTE Fills the “UnitId” field in the Modbus protocol header.
Use:
- References the slave ID in a serial Modbus sub-network.
- Buffer index of the Modbus slave on the PC in conjunction with ActiveMBTSlaveCtl.
FUNCTION_CODE BYTE The following Modbus function codes are supported:
FC1: (0x01) – read coils
FC2: (0x02) – read input discretes FC3: (0x03) – read multiple registers FC4: (0x04) – read input registers FC5: (0x05) – write coil
FC6: (0x06) – write single register FC7: (0x07) – read exception status FC11: (0x0B) – get comm event counter FC15: (0x0F) – force multiple coils FC16 (0x10) – write multiple registers FC23 (0x17) – read write multiple registers READ_REFERENCE WORD Modbus address in slave to be read.
QUANTITY_TO_
READ
WORD Number of bits or words to be read.
WRITE_
REFERENCE
WORD Modbus address in slave to be written.
QUANTITY_TO_
WRITE
WORD Number of bits or words to be written.
TIME_OUT TIME Maximum waiting time for the reply telegram from the Modbus slave.
Example: t#500ms ptRECEIVE_BUFFER POINTER
TO
ARRAY[1..3]
OF BYTE
Pointer to the local data range in which the read data are stored.
ptSEND_DATA POINTER
TO
ARRAY[1..3]
OF BYTE
Pointer to the local data range in which the data to be written are stored.
ETHERNET_MODBUSMASTER_RTU
WAGO-I/O-PRO 32 Library elements
RESET BOOL Reset internal data
Return value: Data type: Comment:
ERROR WORD 0x0000 – Successful
0x0001 – Illegal function code 0x0002 – Illegal data address 0x0003 – Illegal data value 0x0004 – Slave device failure 0x0005 – Acknowledge 0x0006 – Slave device busy 0x0007 – Negative acknowledge 0x0008 – Memory parity error 0x000A – Gateway path unavailable 0x000B – Gateway target no response 0x0097 – Illegal number of points 0x0098 – Internal buffer overrun 0x0099 – TimeOut
READY BOOL Data transfer is complete or the waiting time parameterised in tTIME_OUT has expired.
RESPONSE_UNIT_ID BYTE Content of the “UnitId” field in the Modbus protocol header of the reply telegram Graphical description:
Functional description:
The ETHERNET_MODBUSMASTER_RTU module is used by:
- ETHERNET_MODBUSMASTER_UDP - ETHERNET_MODBUSMASTER_TCP
ETHERNET_CLIENT_OPEN_CLOSE
WAGO-I/O-PRO 32 Library elements
Category: Communications module
Name: ETHERNET_CLIENT_OPEN_CLOSE
Type: Function Function block X Program Library name: ModbusEthernet_04.lib
Requiered libraries Ethernet.lib
Applicable to: Fieldbus controller 750-842 from FW: 02.02.00(04) Fieldbus controller 750-841
Input parameter: Data type: Comment:
EN BOOL TRUE -> Open socket
FALSE -> Close socket
IP STRING IP address of remote station
(Modbus slave)
PORT WORD Port number of remote station
(Modbus slave)
TCP_PROTOKOLL BOOL TRUE -> Use TCP protocol FALSE -> Use UDP protocol Return value: Data type: Comment:
ERROR WORD = 0: no errors found
<> 0: error in operation (see ETH_ERROR data type in Ethernet.lib for details)
SOCKET WORD Handle on current socket
Graphical description:
Functional description:
The ETHERNET_CLIENT_OPEN_CLOSE module is used by:
- ETHERNET_MODBUSMASTER_UDP - ETHERNET_MODBUSMASTER_TCP
IP_ADRESSE
IP_ADRESSE
WAGO-I/O-PRO 32 Library elements
Category: Communications module
Name: IP_ADRESSE
Type: Function X Function block Program Library name: ModbusEthernet_04.lib
Requiered libraries Ethernet.lib
Applicable to: Fieldbus controller 750-842 from FW: 02.02.00(04) Fieldbus controller 750-841
Input parameter: Data type: Comment:
IP_ADR STRING IP address of remote station (Modbus slave)
Return value: Data type: Comment:
IP_ADR WORD IP address of remote station (numeric) Graphical description:
Functional description:
The module converts an IP address The module is used by:
- ETHERNET_MODBUSMASTER_UDP - ETHERNET_MODBUSMASTER_TCP - ETHERNET_CLIENT_OPEN_CLOSE
ETHERNET_TERMINAL_MODBUSSLAVE
WAGO-I/O-PRO 32 Library elements
Category: Communications module
Name: ETHERNET_TERMINAL_MODBUSSLAVE
Type: Function Function block X Program Library name: ModbusEthernet_04.lib
Requiered libraries Ethernet.lib
Applicable to: Fieldbus controller 750-842 from FW: 02.02.00(04) Fieldbus controller 750-841
Input parameter: Data type: Comment:
EN BOOL TRUE -> Activate Modbus server
iPORT INT Port on which the Modbus server is to be accessed.
TCP_PROTOKOLL BOOL TRUE -> TCP server FALSE -> UDP server
iBIT_OFFSET INT Address from which Modbus bit services access the data array
tWATCHDOG_TIME TIME The watchdog is started with the first telegram from the master. A check is made as to whether the master sends telegrams regularly. If the master drops out, i.e. the watchdog triggers, the xWATCHDOG_OK output is reset.
Input/Output parameter: Data type: Comment:
aDATA typETH_SLAVE_
DATEN
WORD ARRAY [0..
ETH_SIZE_SLAVEBUFFER]
Output parameter: Data type: Comment:
xWATCHDOG_OK BOOL Master is sending telegrams.
wERROR WORD 0x0000 – No error
0x0001 – Unsupported function code 0x0002 – Illegal address from master 0x0003 – Illegal data from master
Graphical description:
ETHERNET_TERMINAL_MODBUSSLAVE
WAGO-I/O-PRO 32 Library elements
Functional description:
This module is responsible for communication with external Modbus masters (e.g. various text displays / graphical displays).
For this purpose, the master accesses the aDATA word array presented to the module.
For bit services (function code 0x01, 0x02, 0x0F), an offset can be specified by means of the parameter iBIT_OFFSET.
When the bit services are used, the master only accesses the data from the specified offset address (word offset).
Example: iBIT_OFFSET = 10
The master writes a bit (coil) to Address 2 using function code 0x0F.
We can subsequently retrieve this bit from Bit 1 (counting method 0..15) of Word 10 (iBIT_OFFSET).
This module supports the following Modbus functions
•
0x01 Read Coil Status•
0x02 Read Input Status•
0x03 Read Holding Registers•
0x04 Read Input Registers•
0x05 Force Single Coil•
0x06 Preset Single Register•
0x0F Force Multiple Coils•
0x10 Preset Multiple Registers•
0x17 Read / Write Multiple Registers Word No. Data0 1 2 ...
255
ETHERNET_SERVER_OPEN_CLOSE
WAGO-I/O-PRO 32 Library elements
Category: Communications module
Name: ETHERNET_SERVER_OPEN_CLOSE
Type: Function Function block X Program Library name: ModbusEthernet_04.lib
Requiered libraries Ethernet.lib
Applicable to: Fieldbus controller 750-842 from FW: 02.02.00(04) Fieldbus controller 750-841
Input parameter: Data type: Comment:
EN BOOL TRUE -> Open socket
FALSE -> Close socket
PORT WORD Port on which the server is to be accessed.
TCP_PROTOKOLL BOOL TRUE -> Use TCP protocol FALSE -> Use UDP protocol Return value: Data type: Comment:
ERROR WORD = 0: no errors found
<> 0: error in operation (see ETH_ERROR data type in Ethernet.lib for details)
SOCKET WORD Handle on current socket
Graphical description:
Functional description:
The ETHERNET_CLIENT_OPEN_CLOSE module is used by:
- ETHERNET_TERMINAL_MODBUSSLAVE
typETH_SLAVE_DATEN (data type)
typETH_SLAVE_DATEN (data type)
WAGO-I/O-PRO 32 Library elements
Category:
Name: typETH_SLAVE_DATEN
Type: Data type X Enumeration
Library name: ModbusEthernet_04.lib
Element: Data type: Description:
typETH_SLAVE_DATEN ARRAY[0..ETH_SIZE_SLAVEBUFFER]
OF WORD
Word array for user data
Declaration:
TYPE
typETH_SLAVE_DATEN : ARRAY[0..ETH_SIZE_SLAVEBUFFER] OF WORD;
END_TYPE
Description:
The size of the field can be varied by "masking" the global constants ETH_SIZE_SLAVEBUFFER (default setting = 255).