ReceiveString255
The function block ReceiveString receives a string of characters from the interface corresponding to the input variable RxBuffer, storing it in the output variable ReceivedString. The start and end of the character string are recognized by various mechanisms, which can be combined with one another.
Inputs
VAR_INPUT
Prefix : STRING;
Suffix : STRING;
Timeout : TIME;
Reset : BOOL;
END_VAR
Name | Type | Description |
---|---|---|
Prefix | STRING | If a string is supplied to the input variable Prefix, the first characters must correspond to this prefix. Other characters are discarded. If no prefix is supplied (an empty string), the received string starts with the first received character. |
Suffix | STRING | If a string is supplied to the input variable Suffix, the input data is read until the end of the received string corresponds to the suffix. If during this process the received data reach the maximum length of the receive string, a COMERROR_STRINGOVERRUN error is generated. If an empty string is supplied as the suffix, a timeout must be defined instead, since otherwise the end of the character string cannot be recognized. |
Timeout | TIME | If a timeout is supplied to the function block, then characters will be received until a correspondingly long interval has elapsed after reception of a character. The received string consists of the characters received up to that point. Suffix and timeout may be combined. If a suffix is supplied, the timeout may be 0. |
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, for example if the expected string could not be received and the function block remains busy. |
Inputs/outputs
VAR_IN_OUT
ReceivedString : STRING(255);
RXBuffer : ComBuffer;
END_VAR
Name | Type | Description |
---|---|---|
ReceivedString | STRING (255) | As soon as the StringReceived output becomes TRUE, the received character string is available in the ReceivedString variable. |
RxBuffer | Receive data buffer corresponding to the interface in use. |
Outputs
VAR_OUTPUT
StringReceived : BOOL
busy : BOOL;
Error : ComError_t;
RxTimeout : BOOL;
END_VAR
Name | Type | Description |
---|---|---|
StringReceived
| BOOL | As soon as the StringReceived output becomes TRUE, the received character string is available in the ReceivedString variable. |
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. |
Requirements
Development environment | Target platform | PLC libraries to include |
---|---|---|
TwinCAT v3.1.4012 | PC or CX (ARM, x86, x64) | Tc2_SerialCom |