# ModbusClient\_TCP

## `ModbusClient_TCP` (FB)

`FUNCTION_BLOCK` ModbusClient\_TCP EXTENDS ModbusClientBase

### **Representation**

<figure><img src="https://2592874069-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQR4vCFzt6ixgsqlR3pdR%2Fuploads%2F72CenA7gPXPeRZfCt1jc%2FModbusClient_TCP.png?alt=media&#x26;token=810edf05-4d03-4a53-9962-b9727aa16d34" 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>                                                          |                  |
