TcpReceive
Function Block - Receives characters over a socket connection.
- It is possible the number of characters actually sent is less than the number expected.
- In this case, use this function again to send the pending characters.
-
- It is possible that the socket becomes invalid if an error occurs in the TCP connection after this function block is called.
Use the TcpIsValid function block after TcpSend.
If the socket is no longer valid, close it using the TcpClose function block.
Inputs
|
Input |
Data Type See Data Types. |
Range |
Unit |
Default |
Description |
|---|---|---|---|---|---|
|
Execute |
BOOL |
0 to 1 |
N/A |
No default |
On the rising edge, receive a string over a socket connection. |
|
ID |
UDINT |
N/A |
N/A |
No default |
The ID of the client socket. |
|
MaxChar |
STRING |
N/A |
User units |
No default |
The number of characters to receive. |
Outputs
|
Output |
Data Type See Data Types. |
Range |
Unit |
Description |
|---|---|---|---|---|
|
Done |
BOOL |
|
|
If TRUE, the command completed successfully. |
|
Error |
BOOL |
|
|
If TRUE, an error has occurred. |
|
ErrorID |
DINT |
|
|
Indicates the error if Error output is TRUE. See the table in File, Recipe, and TCP/IP Function Block ErrorIDs. |
|
Data |
STRING |
|
|
String of received characters. |
FBD Language Example
Not available.
FFLD Language Example
Not available.
IL Language Example
Not available.
ST Language Example
(* TcpReceive example *)
CASE StepCounter OF
0:
Inst_TcpReceive(TRUE, MySocketID, 128);
StepCounter := StepCounter + 1;
1:
Inst_TcpReceive(TRUE, MySocketID, 128);
IF Inst_TcpReceive.Done THEN
ReceivedData := Inst_TcpReceive.Data;
Inst_TcpReceive(FALSE, 0, 0);
StepCounter := StepCounter + 1;
END_IF;
END_CASE;
See Also





