Skip to main content

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

alt text

Parameter description

Interface VariablesDeclarationData TypeDescription
REQInputBOOLProactively disconnect only when rising edge is recognized
CONNECTInOutTCP_ConnectConfigFunction block instance for configuring connection parameters, refer to TCP_Connectconfig
DONEOutputBOOLState 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
BUSYOutputBOOLState 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
ERROROutputBOOLState parameter with the following possible values:
0: No error
1: Error in disconnect function
STATUSOutputWORDThe status of the current function execution process

Status code description

STATUS (WORD 16#)Description
0000Uncalled
7003Communication establishment is closing
7007Active disconnection
The following are exception status codesDescription
8087Failed to remove the Epoll Event corresponding to the client
80A2Active disconnection failed
80ACAsynchronous function enqueue failed

Example

  • LD example is shown in the following animation:

alt text

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