ReceiveData

ReceiveData 1:

ReceiveData receives data of any type from the interface corresponding to the input variable RxBuffer, storing it in the ReceiveData variable. The start and end of the data stream are recognized by various mechanisms, which can be combined with one another:

As soon as the output DataReceived becomes TRUE, the receive data is ready in the ReceiveData variable. The number of characters received is given in LenReceiveData.

ReceiveData 2: Inputs

VAR_INPUT
  pPrefix         : POINTER TO BYTE;
  LenPrefix       : BYTE;
  pSuffix         : POINTER TO BYTE;
  LenSuffix       : BYTE;
  pReceiveData    : POINTER TO BYTE;
  SizeReceiveData : DINT;
  Timeout         : TIME;
  Reset           : BOOL;
END_VAR

Name

Type

Description

pPrefix

POINTER TO BYTE

pPrefix is the address of any kind of data structure that is passed to the function block using ADR(variable name). LenPrefix indicates the number of data bytes in the prefix.

LenPrefix

BYTE

LenPrefix indicates the number of data bytes in the prefix.

pSuffix

POINTER TO BYTE

pSuffix is the address of any kind of data structure that is passed to the function block using ADR(variable name).

LenSuffix

BYTE

LenSuffix indicates the number of data bytes in the suffix.

pReceiveData

POINTER TO BYTE

pReceiveData is the address of the receive data, and is found by means of ADR(receive data). The receive data is placed in the variables to which pReceiveData points.

SizeReceiveData

UDINT

SizeReceiveData is found by means of SIZEOF(receive data), and indicates the maximum size of the receive data.

Timeout

TIME

Timeout defines the maximum interval between two received characters. Timeout monitoring becomes effective after the first character. This means that timeout cannot be used to detect whether an expected telegram arrives or not. This is monitored externally.

Reset

 

BOOL

Setting the Reset input will reset the function block from the receive state into the initial state. Resetting is only necessary in exceptional cases, if, for example, the expected data could not be received and the function block remains busy.

ReceiveData 3: Inputs/outputs

VAR_IN_OUT
  RXBuffer         : ComBuffer;
END_VAR

Name

Type

Description

RxBuffer

ComBuffer

Receive data buffer corresponding to the interface in use.

ReceiveData 4: Outputs

VAR_OUTPUT
  DataReceived    : BOOL;
  busy            : BOOL;
  Error           : ComError_t;
  RxTimeout       : BOOL;
  LenReceiveData  : UDINT;
END_VAR

Name

Type

Description

DataReceived

 

BOOL

DataReceived becomes TRUE as soon as the receive data is valid. The output remains TRUE for precisely one cycle, which means that it is necessary to evaluate the received data immediately.

Busy

BOOL

Busy becomes TRUE after the first character has been received, and goes FALSE as soon as the data has been received or an error or timeout has occurred.

Error

ComError_t

If a fault occurs, Error will contain an error code.

RxTimeout

 

BOOL

RxTimeout becomes TRUE if the maximum interval between two received characters is exceeded. This causes data reception to be aborted, and the characters received up to this point are available.

If a suffix is not being used, then detection of a timeout does not represent a fault, but indicates the normal end of the receive data.

If, on the other hand, a suffix was being used, it was not possible to receive this. The timeout is not output as an error, but is only signaled via this output. In such a case DataReceived is nevertheless TRUE and LenReceivedData indicates the number of data received until the timeout. To evaluate only valid and complete receive data (incl. suffix), a query should check RxTimeout=FALSE and Error=COMERROR_NOERROR in addition to DataReceived=TRUE.

LenReceiveData

UDINT

LenReceiveData indicates the actual number of data bytes received, and can be less than or equal to SizeReceiveData.

If prefix or suffix are used, they are also included in the receive data and LenReceiveData thus indicates the total number of received data bytes including prefix and suffix.

Requirements

Development environment

Target platform

PLC libraries to include

TwinCAT v3.1.4012

PC or CX (ARM, x86, x64)

Tc2_SerialCom