ReceiveData

ReceiveData 1:

Interface

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
VAR_OUTPUT
    DataReceived    : BOOL;
    busy            : BOOL;
    Error           : ComError_t;
    RxTimeout       : BOOL;
    LenReceiveData  : UDINT;
END_VAR
VAR_IN_OUT
    RXbuffer        : ComBuffer;
END_VAR

Description

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 recognised 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.

pPrefix

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

LenPrefix

LenPrefix indicates the number of data bytes in the prefix.

pSuffix

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

LenSuffix

LenSuffix indicates the number of data bytes in the suffix.

pReceiveData

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

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

Timeout

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

Setting the Reset input will reset the 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 block remains busy.

DataReceived

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

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

Error

If a fault occurs, Error will contain an error code. The error code is defined by the data type ComError_t, and this is used to display it in text form at runtime.

RxTimeout

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.

LenReceiveData

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

RxBuffer

RxBuffer is the receive data buffer corresponding to the interface in use.