TcpConnection.Receive (METH)

METHOD Receive : ERROR_ID

Method to receive data as a stream from an established TCP connection.

VAR
    fbTcpConnection     : TcpConnection;        (* Instance of function block - can be either TcpConnection or TcpClient. Anyhow a communication must be established before using the Receive method() *)

    eErrorId            : AC500_Tcp.ERROR_ID;           (* Error Id of the Connect method *)
    dwAddErrNo          : AC500_Tcp.RTS_IEC_RESULT;     (* Additional error number - list available in GVL of CmpErrors.Erros library *)
    sDataRecv           : STRING(1000);                 (* Data buffer where the incoming message will be stored *)
    diRecvBytes         : DINT;                         (* Number of received bytes *)
END_VAR

------------
// Cyclic call of Receive()
eErrorId := fbTcpConnection.Receive(    Data        := ADR(sDataRecv),
                                        Size        := SIZEOF(sDataRecv),
                                        RecvBytes   => diRecvBytes,
                                        AddErrNo    => dwAddErrNo);

// As long as ERROR_ID = BUSY, the TcpConnection is waiting for incoming messages
IF eErrorId = AC500_Tcp.ERROR_ID.NO_ERROR OR eErrorId = AC500_Tcp.ERROR_ID.NO_ERROR_BUSY THEN

    // Something has been received without an error
    IF diRecvBytes > 0 THEN
        ;   // The received telegram/message is <> to 0
    END_IF
ELSIF eErrorId <> AC500_Tcp.ERROR_ID.BUSY THEN

    ;   // For ERR_INTERNAL, please check AddErrNo - AC500_Tcp.RTS_IEC_RESULT - the error codes are listed in the GVL of CmpErros.Errors

END_IF
InOut:

Scope

Name

Type

Comment

Return

Receive

ERROR_ID

Input

Data

POINTER TO BYTE

Pointer to the memory size where the data will be stored

Size

UDINT

Size of the datat to be received - maximum size of TCP packet is 64kB = 65 535 Bytes

Output

RecvBytes

DINT

Number of received bytes that has been read from the TCP stream

AddErrNo

RTS_IEC_RESULT

Additional error number gives information about error from SysSock2Close –> please see CmpErrors.Errors