# ModbusClient\_TCP

## `ModbusClient_TCP` (FB)

`FUNCTION_BLOCK` ModbusClient\_TCP EXTENDS ModbusClientBase

### **Representation**

<figure><img src="/files/afdebbec3c7f4361a7bf44e0aea7e3b3e84f3409" alt=""><figcaption></figcaption></figure>

### 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`                         | ‘’                                         | <p>Hostname (FQDN, e.g. <code>[www.focus.de](http://www.focus.de)</code>) or IP address of the<br>Server (e.g. <code>192.168.178.210</code>)(Modbus-TCP)</p> |                  |
| Input       | `wPort`                 | `WORD`                           | 502                                        | <p>Port number of the Server (Modbus-TCP)(502 is the default<br>port)</p>                                                                                    |                  |
| 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                                      | <p>Current Standby state (FALSE = Not ready, TRUE = Ready to<br>send / receive Modbus data)</p>                                                              |                  |
| 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                                 | <p>Timeout for the Client-Server communication (Resolve = name<br>resolution & Connection time)</p>                                                          |                  |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://support.powerio.com/hub/codesys-hvac/en/hvac-modbus-library/functionblocks/generic/modbusclient_tcp.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
