TcpBinReceive
Description
This function block receives characters over a socket connection. It is possible that the number of characters actually received is less than the number expected. In that case, you will have to call this function again on the next cycle to receive 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. You must use the TcpIsValid function block after TcpSend. If the socket is no longer valid then you must close it by using the TcpClose function block.
Figure 7-208: The TcpBinReceive function block
Related Functions
TcpAccept, TcpBinSend, TcpClose, TcpConnect, TcpIsConnected, TcpIsValid, TcpListen, TcpReceive, TcpSend
Arguments
Input
Execute | Description | On the rising edgeA rising edge is the transition of a digital signal from low to high. It is also called positive edge request to perform copying a file |
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 | — | |
Data | Description | The array where the received data will be stored. |
Data Type | USINT[] | |
Range | N/A | |
Unit | N/A | |
Default | — | |
MaxChar | Description | The maximum number of bytes to receive |
Data Type | DINT | |
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 | |
NbRcv | Description | The number of characters actually received |
Data Type | DINT |
Example
Structured Text
(* TcpBinReceive example *)
CASE StepCounter OF
0:
Inst_TcpBinReceive(TRUE, MySocketID, MyDataArray, 256);
StepCounter := StepCounter + 1;
1:
Inst_TcpBinReceive(TRUE, MySocketID, MyDataArray, 256);
IF Inst_TcpBinReceive.Done THEN
BytesReceived := Inst_TcpBinReceive.NbRcv;
Inst_TcpBinReceive(FALSE, 0, MyDataArray, 0);
StepCounter := StepCounter + 1;
END_IF;
END_CASE;