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).

Client

Output

xConnected

BOOL

Client (master) is connected to server (slave).

Client

xError

BOOL

Error

Client

eErrorID

Error

Error status

Client

udiNumMsgSent

UDINT

Number of request messages send since connect.

Client

udiNumMsgReply

UDINT

Number of reply messages received since connect.

Client

udiNumMsgExcReply

UDINT

Number of exception reply messages received since connect.

Client

udiNumMsgExcReplyIllFct

UDINT

Number of exception reply messages received since connect, signaling illegal function.

Client

udiNumMsgExcReplyIllDataAdr

UDINT

Number of exception reply messages received since connect, signaling illegal data address.

Client

udiNumReplyTimeouts

UDINT

Number of reply timeouts since connect.

Client

udiNumReqNotProcessed

UDINT

Number of requests not processed in time (“request starvation”) since connect.

Client

udiNumReqParamError

UDINT

Number of requests started with parameter error, for example “Read Coils” -> “Quantity of coils” = 0.

Client

udiLastTransactionTime

UDINT

Transaction time in ms - time difference between request message send und reply message received.

Client

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.