7.15.8 TSEND
TSEND (Establish communication connection, send data)
Function
- The TSEND system library is used to send specified data asynchronously.
- No connection function is provided
Set up and establish communication connections
-
After the connection is successfully established, the user gives req a rising edge, which will trigger a data sending function;
-
The send data function TSEND only works when the communication connection has been successfully established;
-
The correct sending process requires a rising edge on the req pin first. You can see that the status word in the TSEND block changes from 0x7004 (connection has been established) → 0x7005 (data is being sent) → 0x7009 (data is sent successfully), indicating that the data has been sent successfully;
-
After giving the req pin a rising edge, if the connection is not established at this time, error = true will be displayed and the status code is 0x80A1 (the connection has not been established yet)
LD graphics

Parameter description
| Interface Variables | Declaration | Data Type | Description |
|---|---|---|---|
| REQ | Input | BOOL | A data sending action is triggered only when a rising edge is recognized |
| LEN | Input | UDINT | Send data with length LEN. If it is 0, send all data If it is larger than 65535 or larger than the size of DATA, an error will be reported directly |
| CONNECT | InOut | TCP_ConnectConfig | Function block instance for configuring connection parameters, see TCP_Connectconfig |
| DATA | InOut | ANY_TYPE | Data block to be sent |
| DONE | Output | BOOL | State parameter with the following possible values: 0: Sending data has not been started or is still in progress 1: Sending data has been successfully executed This status will only display one Cycle |
| BUSY | Output | BOOL | State parameter with the following possible values: 0: Sending data has not yet started or has been completed 1: Sending data has not yet been completed |
| ERROR | Output | BOOL | State parameter with the following possible values: 0: No error 1: Error sending data |
| STATUS | Output | WORD | The status of the current function execution process |
Status code description
| STATUS(WORD 16#) | Description |
|---|---|
| 0000 | Uncalled |
| 7005 | In process of sending data |
| 7009 | Data sent successfully |
| The following are exception status codes | Description |
|---|---|
| 80A1 | The specified connection has not been established yet, used when the sending and receiving functions are activated, but the connection has not yet been established |
| 80A4 | Data block is empty |
| 80A5 | 80A5 appears for the following three reasons: The parameter LEN is greater than 65536; The value of LEN is greater than the size of the data block; LEN is 0 and the size of the data block is greater than 65536 |
| 80A7 | Failed to obtain send buffer |
| 80A8 | socket sending buffer is full |
| 80A9 | Sending failed |
| 80AC | Asynchronous function enqueue failed |
| 80C3 | The connection corresponding to the current TConnectConfig is already used by other TSEND blocks |
| 80C5 | During the process of sending data, the peer actively disconnected |
Example
- LD example is shown in the following animation:

- ST example is shown in the following code:
TSEND_1(
REQ:=bVar,
LEN:=0,
CONNECT:=TCP_CONNECTCONFIG_1,
DATA:=iVar,
DONE=>OUT,
BUSY=>OUT2,
ERROR=>OUT3,
STATUS=>OUT4
);
bVar:=not bvar;
iVar:= iVar+2;