TcpClose
Description
This function block closes and releases a socket. You are responsible for closing any socket created by the TcpListen, TcpAccept, or TcpConnect function blocks, even if they have become invalid.
Figure 7-220: The TcpClose function block
Related Functions
TcpAccept, TcpBinReceive, TcpBinSend, TcpConnect, TcpIsConnected, TcpIsValid, TcpListen, TcpReceive, TcpSend
Arguments
Input
Execute | Description | On the rising edge A rising edge is the transition of a digital signal from low to high. It is also called positive edge close a socket. |
Data Type | BOOL | |
Range | 0, 1 | |
Unit | N/A | |
Default | — | |
ID | Description | The ID of the client socket |
Data Type | UDINT | |
Range | N/A | |
Unit | N/A | |
Default | — |
Output
Done | Description | If TRUE, then the command completed successfully |
Data Type | BOOL | |
Error | Description | If TRUE, an error has occurred |
Data Type | BOOL | |
ErrorID | Description | Indicates the error if Error output is set to TRUE. See the table in Search IndexFile and TCP/IP Function Block ErrorID Output |
Data Type | DINT |
Example
Structured Text
(* TcpClose example *)
CASE StepCounter OF
0:
Inst_TcpClose(TRUE, MySocketID);
StepCounter := StepCounter + 1;
1:
Inst_TcpClose(TRUE, MySocketID);
IF Inst_TcpClose.Done THEN
Inst_TcpClose(FALSE, 0);
StepCounter := StepCounter + 1;
END_IF;
END_CASE;