ClientTCP (FB)¶
FUNCTION_BLOCK ClientTCP EXTENDS Client
MODBUS TCP client (master).
Please note: some input variables related to connection configuration are read when rising edge on xConnect occurs. To change connection configuration the application needs to - disconnect (xConnect := FALSE and execute the FB) - modify the related input variables - connect (xConnect := TRUE and execute the FB)
The Client provides some statistics of sent request messages and received valid 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
xConnectBOOLFALSE
Connect to server (slave).
Output
xConnectedBOOLClient (master) is connected to server (slave).
xErrorBOOLError
eErrorIDError status
udiNumMsgSentUDINTNumber of request messages send since connect.
udiNumMsgReplyUDINTNumber of reply messages received since connect.
udiNumMsgExcReplyUDINTNumber of exception reply messages received since connect.
udiNumMsgExcReplyIllFctUDINTNumber of exception reply messages received since connect, signaling illegal function.
udiNumMsgExcReplyIllDataAdrUDINTNumber of exception reply messages received since connect, signaling illegal data address.
udiNumReplyTimeoutsUDINTNumber of reply timeouts since connect.
udiNumReqNotProcessedUDINTNumber of requests not processed in time (“request starvation”) since connect.
udiNumReqParamErrorUDINTNumber of requests started with parameter error, for example “Read Coils” -> “Quantity of coils” = 0.
udiLastTransactionTimeUDINTTransaction time in ms - time difference between request message send und reply message received.
Input
aIPaddrARRAY [0..3] OF BYTE
[255, 255, 255, 255]
ETH server (slave) address, only read when rising edge on xConnect occurs.
uiPortUINT502
ETH server (slave) port, only read when rising edge on xConnect occurs.
tConnnectTimeOutTIMETIME#1s0ms
Connect timeout (in milliseconds), only read when rising edge on xConnect occurs.
udiLogOptionsUDINTLoggingOptions.ClientConnectDisconnect
Logging options.