Skip to main content

7.15.9 TRCV

Function

  • TRCV system library is used to receive specified data asynchronously
    • No connection function is provided

Set up and establish communication connections

  • After the connection is successfully established, the user gives req a rising edge, which will trigger a receive data function;

  • The data receiving function TRCV only works when the communication connection has been successfully established;

  • The correct reception process requires setting the EN_R pin to true first. You can see that the status word in the TRCV block changes from 0x7004 (connection has been established) → 0x7006 (data is being received) → 0x7008 (data is received successfully), indicating that the data has been sent successfully;

  • If there is no error in the receiving process and the data of the specified length is not received, BUSY will remain true at this time and the status code is 0x7006;

  • After setting the EN_R pin to true, if the connection is not established at this time, error = true will be displayed and the status code is 0x80A1 (the connection has not been established yet)

LD graphics

alt text

Parameter description

Interface VariablesDeclarationData TypeDescription
EN_RInputBOOLEN_R = True, enable receiving function
LENInputUDINTReceive data with length LEN
If it is 0, receive data of DATA size
If it is greater than 65535 or greater than the size of DATA, an error will be reported directly
The receiving length also depends on On whether to turn on ADHOC mode
ADHOCInputBOOLReceiving mode:
0: Indicates that the static receiving mode is enabled. Only when data of the specified size is received, done will be set to true and maintained for a period
1: Indicates that the dynamic receiving mode is enabled. As long as data is received, even 1 byte, done will be set to true and maintained for a period
CONNECTInOutTCP_ConnectConfigFunction block instance to configure connection parameters, refer to TCP_Connectconfig
DATAInOutANY_TYPEData block to store received data
DONEOutputBOOLState parameter with the following possible values:
0: Receiving data has not yet started or is still in progress
1: Receiving data has been successfully executed. This status will only show for one cycle
BUSYOutputBOOLState parameter with the following possible values:
0: Receiving data has not yet started or has been completed
1: Receiving data has not yet been completed
ERROROutputBOOLState parameter with the following possible values:
0: No error
1: Error in receiving data
STATUSOutputWORDThe status of the current function execution process
RCVD_LENOutputUDINTActually received data length, only when done = true, it will be updated once and maintained for one cycle

Status code description

STATUS(WORD 16#)Description
0000Uncalled
7006Turn on the receiving function and receive data
7008Specified data successfully received
The following are exception status codesDescription
80A1The specified connection has not been established yet, used when the sending and receiving functions are activated, but the connection has not yet been established
80A4Data block is empty
80A580A5 appears for the following three reasons:
The parameter LEN is greater than 65536;
The value of LEN is greater than the size of the data block;
LEN is 0 and the size of the data block is greater than 65536
80A7Failed to obtain send buffer
80AASending failed
80ACAsynchronous function queue entry failed
80C3The connection corresponding to the current TConnectConfig is already used by other TRCV blocks
80C5During the process of sending/receiving data, the peer actively disconnected

Example

  • LD example is shown in the following animation:

alt text

  • ST example is shown in the following code:
TRCV_1(
EN_R:=bVar,
LEN:=0,
ADHOC:=true,
CONNECT:=TCP_CONNECTCONFIG_1,
DATA:=iVar,
NDR=>OUT,
BUSY=>OUT2,
ERROR=>OUT3,
STATUS=>OUT4,
RCVD_LEN=>OUT5
);