ModbusClient_TCP

ModbusClient_TCP (FB)

FUNCTION_BLOCK ModbusClient_TCP EXTENDS ModbusClientBase

Representation

Function description

This function block provides the client functionalities in a Modbus TCP communication. The counterpart must provide the server functionalities. In the ideal case (= complete reception of the Modbus response telegram within one task cycle time), a new transmission is started cyclically after T = 5 * task cycle time (T = 50 ms for a task cycle time of 10 ms). For Modbus telegrams with a lot of data and/or low transmission rates on the serial side (RS 485) this time can increase accordingly.

InOut:

Scope
Name
Type
Initial
Comment
Inherited from

Output

xConnected

BOOL

TRUE if connection has been established

ModbusClientBase

Output

xLicenceValid

BOOL

TRUE if a valid licence was found

ModbusClientBase

Input

xEn

BOOL

TRUE

Input to enable / disable the function block

Input

sHostAddress

STRING

‘’

Hostname (FQDN, e.g. www.focus.de) or IP address of the Server (e.g. 192.168.178.210)(Modbus-TCP)

Input

wPort

WORD

502

Port number of the Server (Modbus-TCP)(502 is the default port)

Input

xResetLastErrors

BOOL

FALSE

Input to reset the error outputs (rising edge)

Output

byLastRequestUnitID

BYTE

0

Last Request telegram: Unit ID (0 = No Unit)

Output

eState

Client_TCP_StateCode

Client_TCP_StateCode.IDLE

Current state of the state machine as ENUM

Output

eResponseState

Client_TCP_Response_StateCode

Client_TCP_Response_StateCode.NO_ERROR

Last Response telegram: Description of the state as ENUM

Output

byLastErrorUnitID

BYTE

0

Last error: Unit ID (0 = No Unit)

Output

xError

BOOL

FALSE

Current Error State (FALSE = No Error, TRUE = Error)

Output

eLastErrorCode

Client_TCP_ErrorCode

Client_TCP_ErrorCode.NO_ERROR

Last Error: Description of the communication error as ENUM

Output

xReady

BOOL

FALSE

Current Standby state (FALSE = Not ready, TRUE = Ready to send / receive Modbus data)

Input Const

tKeepAliveTimeout

TIME

TIME#1m20s0ms

Time between the last package sent and the first probe (Idle-Mode)

Input Const

tTimeoutDeviceReceive

TIME

TIME#2s0ms

Timeout for the Device communication (Read)

Input Const

tTimeoutDeviceSend

TIME

TIME#2s0ms

Timeout for the Device communication (Send)

Input Const

tTimeoutConnect

TIME

TIME#3s0ms

Timeout for the Client-Server communication (Resolve = name resolution & Connection time)

Last updated