7.15.6 TDISCON
TDISCON (disconnect the specified connection)
Function
- TDISCON system library is used to asynchronously disconnect the current TCP connection
Set up and establish communication connections
-
After the user configures the correct IP address and port number in the connect block, set the REQ parameter to true to enable the disconnection function and terminate the current communication connection.
-
The disconnect function only works when the communication connection has been successfully established
-
The correct disconnection process requires giving the req pin a rising edge first. You can see that the status word in the TDISCON block changes from 0x7003 (terminating the connection) → 0x7007 (the connection has been terminated), indicating that the connection has been successfully disconnected.
-
After the connection is established, if the peer actively disconnects at this time, the status code will change from 0x7004 (already established) → 0x7002 (connection is being established); if the connection is disconnected at this time, the socket resources created by the party will be released. RST messages can be seen through packet capture; if one is the server, one will also be removed from the listening state, and the other party will no longer be able to establish a connection in the future.
LD graphics

Parameter description
| Interface Variables | Declaration | Data Type | Description |
|---|---|---|---|
| REQ | Input | BOOL | Proactively disconnect only when rising edge is recognized |
| CONNECT | InOut | TCP_ConnectConfig | Function block instance for configuring connection parameters, refer to TCP_Connectconfig |
| DONE | Output | BOOL | State parameter with the following possible values: 0: The disconnection function has not been started or is still in progress 1: The disconnection function has been successfully executed. This status will only show for one cycle |
| BUSY | Output | BOOL | State parameter with the following possible values: 0: The disconnection function has not yet started or has been completed 1: The disconnection function has not yet been completed |
| ERROR | Output | BOOL | State parameter with the following possible values: 0: No error 1: Error in disconnect function |
| STATUS | Output | WORD | The status of the current function execution process |
Status code description
| STATUS (WORD 16#) | Description |
|---|---|
| 0000 | Uncalled |
| 7003 | Communication establishment is closing |
| 7007 | Active disconnection |
| The following are exception status codes | Description |
|---|---|
| 8087 | Failed to remove the Epoll Event corresponding to the client |
| 80A2 | Active disconnection failed |
| 80AC | Asynchronous function enqueue failed |
Example
- LD example is shown in the following animation:

- ST example is shown in the following code:
TDISCON_1(
REQ:=Close,
CONNECT:=TCP_CONNECTCONFIG_1,
DONE=>OUT,
BUSY=>OUT2,
ERROR=>OUT3,
STATUS=>OUT4
);