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 - xConnect- BOOL- FALSE - Connect to server (slave). - Output - xConnected- BOOL- Client (master) is connected to server (slave). - xError- BOOL- Error - eErrorID- Error status - udiNumMsgSent- UDINT- Number of request messages send since connect. - udiNumMsgReply- UDINT- Number of reply messages received since connect. - udiNumMsgExcReply- UDINT- Number of exception reply messages received since connect. - udiNumMsgExcReplyIllFct- UDINT- Number of exception reply messages received since connect, signaling illegal function. - udiNumMsgExcReplyIllDataAdr- UDINT- Number of exception reply messages received since connect, signaling illegal data address. - udiNumReplyTimeouts- UDINT- Number of reply timeouts since connect. - udiNumReqNotProcessed- UDINT- Number of requests not processed in time (“request starvation”) since connect. - udiNumReqParamError- UDINT- Number of requests started with parameter error, for example “Read Coils” -> “Quantity of coils” = 0. - udiLastTransactionTime- UDINT- Transaction time in ms - time difference between request message send und reply message received. - Input - aIPaddr- ARRAY [0..3] OF BYTE - [255, 255, 255, 255] - ETH server (slave) address, only read when rising edge on xConnect occurs. - uiPort- UINT- 502 - ETH server (slave) port, only read when rising edge on xConnect occurs. - tConnnectTimeOut- TIME- TIME#1s0ms - Connect timeout (in milliseconds), only read when rising edge on xConnect occurs. - udiLogOptions- UDINT- LoggingOptions.ClientConnectDisconnect - Logging options. 
