Skip to main content

Function Block: ModbusServer

Library: ModbusTCP Server

The function block processes up to 16 parallel client connection requests by Modbus TCP. Modbus requests work within data ranges which map the input and holding registers.

The following Modbus function codes are supported:

  • 0x01 Read Coils

  • 0x02 Read Discrete Inputs

  • 0x03 Read Holding Registers

  • 0x04 Read Input Registers

  • 0x05 Write Single Coil

  • 0x06 Write Single Register

  • 0x0F Write Multiple Coils

  • 0x10 Write Multiple Registers

  • 0x17 Read/Write Multiple Registers

The ModbusServer function block uses the parameters which have been configured on the device editor tab of the Modbus TCP Server.

Table 27. Inputs (VAR_INPUT)

Name

Data Type

Initial Value

Description

wPort

WORD

502

Server port (TCP/IP protocol stack) 502 is Modbus default

pInputData

POINTER TO WORD

Pointer to WORD; points to the map of the Modbus input register

uiInputDataSize

UINT

1024

Length of the array of input data (WORDs per register); default: 1024

pOutputData

POINTER TO WORD

Pointer to WORD; points to the map of the Modbus holding register

uiOutputDataSize

UINT

Length of the array of output data (WORDs per register)

tTimeout

UDINT

Timeout (ms). If it is not zero and no Modbus write error has occurred until the timeout, then the output data is set to zero.

xEnable

BOOL

FALSE

Flag for starting request processing

xReset

BOOL

FALSE

Restart of normal communication with the servers; reset of status words and error bits for a rising edge

InterfaceName

WSTRING(255)

Name of the Ethernet interface (optional). When specified, the Modbus Server binds to the IP address of this interface.



Table 28. Outputs (VAR_OUTPUT)

Name

Data Type

Initial Value

Description

xBusy

BOOL

FALSE

TRUE while the request is being processed

xError

BOOL

FALSE

Information about errors found

byClientConnections

BYTE

0

Number of connections

xTimeout

BOOL

The timeout has expired. Holding registers and coils are set to zero.