Function BlockTcpReceivePLCopen motion icon

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 the 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-225: The TcpReceive function block

Related Functions

TcpAccept, TcpBinReceive, TcpBinSend, TcpClose, TcpConnect, TcpIsConnected, TcpIsValid, TcpListen, TcpSend

Arguments

Input

Execute Description On the rising edgeClosed A rising edge is the transition of a digital signal from low to high. It is also called positive edge receive a string over a socket connection.
  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
MaxChar Description The number of characters to receive.
  Data Type STRING
  Range N/A
  Unit user units
  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
Data Description String of received characters
  Data Type STRING

Example

Structured Text

(* 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;