TcpBinReceive

PLCopen motion icon

 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, request to perform copying a file.

ID

UDINT

N/A

N/A

No default

The ID of the client socket.

Data

USINT[ ]

N/A

N/A

No default

The array where the received data is stored.

MaxChar

DINT

N/A

N/A

No default

The maximum number of bytes 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.

NbRcv

DINT

 

 

The number of characters actually received.

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: TcpBinReceive

FBD Language Example

Not available.

FFLD Language Example

Not available.

IL Language Example

Not available.

ST Language Example

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

See Also