ReceiveData
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:
- Prefix
- If a variable is passed to the input variable prefix, the first characters of the received data must be the same as this prefix. Other characters are discarded. If no prefix is supplied (null), the receive data starts with the first received character.
- Suffix
If an input variable Suffix is supplied, the input data is read until the end of the receive data agrees with the suffix. If the received data reach the maximum length SizeReceiveData, a COMERROR_DATASIZEOVERRUN error is generated. - Block size
If no suffix is specified, characters are received up to SizeReceiveData. - Timeout
If a timeout is passed to the function block, characters are received until a correspondingly large time gap follows a character. The receive data consists of the characters received up to that point. If timeout is 0, characters are received up to SizeReceiveData without time monitoring. - Suffix and timeout
If both a suffix and a timeout are passed, the input data is read until: - the end of the receive data matches the suffix. (DataReceived=TRUE)
- the received data reaches the maximum length SizeReceiveData. (DataReceived=TRUE, Error=COMERROR_DATASIZEOVERRUN)
- a character is followed by a correspondingly large time gap. The receive data consists of the characters received up to that point. (DataReceived=TRUE, RxTimeout=TRUE)
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.
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. |
Inputs/outputs
VAR_IN_OUT
RXBuffer : ComBuffer;
END_VAR
Name | Type | Description |
---|---|---|
RxBuffer | Receive data buffer corresponding to the interface in use. |
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 | 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 |