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).
fcsSupported
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.
dataModel
“data model”, accepted at xEnable FALSE => TRUE.
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”.
Output
xRunning
BOOL
Server is up and running, waiting for requests.
xError
BOOL
Error
eErrorID
Error status
xInactive
BOOL
No valid requests received for tInactivityTimeOut.
udiNumMsgRecv
UDINT
Number of request messages received since enabling the Server.
udiNumMsgReply
UDINT
Number of reply messages send since enabling the Server.
udiNumMsgExcReply
UDINT
Number of exception reply messages send since enabling the Server.
udiNumMsgExcReplyIllFct
UDINT
Number of exception reply messages send since enabling the Server, signaling illegal function.
udiNumMsgExcReplyIllDataAdr
UDINT
Number of exception reply messages send since enabling the Server, signaling illegal data address.
udiNumMsgExcReplyIllDataValue
UDINT
Number of exception reply messages send since enabling the Server, signaling illegal data value.
xReadRequest
BOOL
Read request(s) happened since last call, rejected requests included.
udiNumReadRequests
UDINT
Read request counter, rejected requests included.
xWriteRequest
BOOL
Write request(s) happened since last call, rejected requests included.
udiNumWriteRequests
UDINT
Write request counter, rejected requests included.
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.