ServerTCP (FB)

FUNCTION_BLOCK ServerTCP EXTENDS Server

MODBUS TCP server (slave).

ServerTCP processes MODBUS TCP requests by up to 16 parallel client connections.

For details about supported function codes and “data model” see Server.

Please note: some input variables related to connection configuration are read when rising edge on xEnable occurs. To change connection configuration the application needs to - disconnect (xEnable := FALSE and execute the FB) - modify the related input variables - connect (xEnable := TRUE and execute the FB)

The Server provides some statistics of received valid requests messages and sent reply messages. Invalid messages are dropped at the communication level, so doesnt appear in the statistics. To analyse situations where invalid reply messages might occur, you can use udiLogOptions with LoggingOptions.WarnOnReceivedInvalidFrames.

Please visit https://forge.codesys.com/prj/codesys-example/modbus/home to find examples.

InOut:

Scope

Name

Type

Initial

Comment

Inherited from

Input

xEnable

BOOL

FALSE

Enables the server, take over the configuration information fcsSupported and dataModel. If the “data model” (tableDefinitions) contains configuration errors, the Server will not got busy (xBusy = FALSE).

Server

fcsSupported

SupportedFcs

Constants.SUPPORTED_FCS_SIMPLE_SERVER

Supported “function codes”, accepted at xEnable FALSE => TRUE. In case fcsSupported is not assigned by the application it defaults to Constants.SUPPORTED_FCS_SIMPLE_SERVER.

Server

dataModel

TableDefinitions

“data model”, accepted at xEnable FALSE => TRUE.

Server

tInactivityInfoTime

UDINT

0

“inactivity info time” (in milliseconds). If no valid requests are received in this time xInactive is signaling inactivity - default = 0 -> no “inactivity info”.

Server

Output

xRunning

BOOL

Server is up and running, waiting for requests.

Server

xError

BOOL

Error

Server

eErrorID

Error

Error status

Server

xInactive

BOOL

No valid requests received for tInactivityTimeOut.

Server

udiNumMsgRecv

UDINT

Number of request messages received since enabling the Server.

Server

udiNumMsgReply

UDINT

Number of reply messages send since enabling the Server.

Server

udiNumMsgExcReply

UDINT

Number of exception reply messages send since enabling the Server.

Server

udiNumMsgExcReplyIllFct

UDINT

Number of exception reply messages send since enabling the Server, signaling illegal function.

Server

udiNumMsgExcReplyIllDataAdr

UDINT

Number of exception reply messages send since enabling the Server, signaling illegal data address.

Server

udiNumMsgExcReplyIllDataValue

UDINT

Number of exception reply messages send since enabling the Server, signaling illegal data value.

Server

xReadRequest

BOOL

Read request(s) happened since last call, rejected requests included.

Server

udiNumReadRequests

UDINT

Read request counter, rejected requests included.

Server

xWriteRequest

BOOL

Write request(s) happened since last call, rejected requests included.

Server

udiNumWriteRequests

UDINT

Write request counter, rejected requests included.

Server

Input

wsInterfaceName

WSTRING(255)

ETH interface name to bind to, “” to bind to any ETH interface. Only read when rising edge on xEnable occurs.

uiPort

UINT

502

ETH port to use. Only read when rising edge on xEnable occurs.

xReset

BOOL

FALSE

Reset the server.

udiLogOptions

UDINT

LoggingOptions.ServerStartStop

Logging options.

Output

uiConnectedClients

UINT

Number of actually connected clients.