Function block ModbusServer

Presentation

The function block ModbusServer is part of the library SE_ModbusTCP_Slave. It handles ModbusTCP requests for writing and reading data between the HMI SCU controller as a server and Modbus clients. Up to 10 client connections can be served. The function block operates on defined data areas in the HMI SCU that represent Modbus input and output registers.

The ModbusServer function block runs in a POU assigned to a task, and therefore, if the controller is in STOP mode, the task with the ModbusServer function block is not running.

The Unit ID of the ModbusServer is 255.

Supported Function Codes

The following Modbus function codes are supported:

Function code

Description

3 (03 hex) or 4 (04 hex)

Read Multiple Registers

6 (06 hex)

Write Single Register

16 (10 hex)

Write Multiple Registers

23 (17 hex)

Read/Write Multiple Registers

Up to 10 client connections can be managed together. All client requests are processed within one controller cycle; however, one request per client connection.

Graphical Representation

G-SE-0043454.1.gif-high.gif

 

 

Parameters

This table describes the inputs of the function block:

Input

Type

Default Value

Description

wPort

WORD

502

Server port, 502 is Modbus default1

pInputData

POINTER TO WORD

-

First word address of the input data table.

pOutputData

POINTER TO WORD

-

First word address of the output data table.

uiInputDataSize

UINT

-

Size of the input data table.

uiOutputDataSize

UINT

-

Size of the output data table.

xEnable

BOOL

FALSE

When TRUE, the function block is executed. The values of the function block inputs can be modified and its outputs are updated continuously.

When FALSE, terminates the function block execution and resets its outputs.

xReset

BOOL

 FALSE

When TRUE, re-enables communication and the error bit.

tTimeout

UDINT

0

Modbus write timeout in ms. The function block needs to be reset after a timeout to re-enable communication.

1   Port 502 is the default port used for Modbus TCP/IP protocol. If Modbus TCP/IP (server or client) protocol is already configured in Vijeo-Designer for the controller, use a different port in the function block, to communicate between the server and the clients.

This table describes the outputs of the function block:

Output

Type

Default Value

Description

xBusy

BOOL

-

When TRUE, the function block is servicing a client request.

When FALSE, the function block has terminated servicing a client request.

The function block must be kept in an active task of the application program for at least as long as xBusy is TRUE. If not, the data tables are set to 0 while the function block outputs remain static.

xError

BOOL

-

When TRUE, it indicates that an error was detected. The execution of the function block has been terminated.

The function block needs to be reset to re-enable communication.

byClientConnections

BYTE

0

Number of active connections.

Return Codes

This table lists the values for the return codes for the library SE_ModbusTCP_Slave which are sent to the clients for various erroneous requests, or in response to successful operations:

Name

Type

Value

Description

RESPONSE_SUCCESS

BYTE

16#0

Successful communication.

ILLEGAL_FUNCTION

BYTE

16#1

The function code is not supported by the server.

ILLEGAL_DATA_ADDRESS

BYTE

16#2

The register offset is not supported by the server.

ILLEGAL_DATA_VALUE

BYTE

16#3

Incorrect value.

SLAVE_DEVICE_FAILURE

BYTE

16#4

An error has been detected on the server device.

ACKNOWLEDGE

BYTE

16#5

Server response to valid client request.

SLAVE_DEVICE_BUSY

BYTE

16#6

Server response to client request sent while an operation is already in progress.

GATEWAY_PATH_UNAVAILABLE

BYTE

16#A

Error detected when communicating through a gateway (Gateway misconfigured/busy)

GATEWAY_DEVICE_FAILED_TO_RESPOND

BYTE

16#B

Device connected to gateway did not respond.

Global Constant List

This table present the Global Constant List (GCL) for the library SE_ModbusTCP_Slave:

Name

Type

Value

Description

MODBUS_TCP_MAXCLIENTS

UINT

10

Non-editable GCL containing the maximum number of active connections.