TcpReceive
Function Block - Receives characters over a socket connection.
Inputs
Input |
Data Type |
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 |
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 and TCP/IP Function Block ErrorIDs. |
Data |
STRING |
|
|
String of received characters. |
Remarks
-
- 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.
- It is possible that the number of characters actually received is less than the number expected.
- In this case, call this function again on the next cycle to receive the pending characters.
Figure 1: TcpReceive
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