ReceiveString
Interface
VAR_INPUT
Prefix : STRING;
Suffix : STRING;
Timeout : TIME;
Reset :BOOL;
END_VAR
VAR_OUTPUT
StringReceived: BOOL;
busy : BOOL;
Error: ComError_t;
RxTimeout : BOOL;
END_VAR
VAR_IN_OUT
ReceivedString : STRING;
RXbuffer : ComBuffer;
END_VAR
Description
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 string are recognised by various mechanisms, which can be combined with one another:
- Prefix If a string is supplied to the input variable prefix, the first characters must be the same as this prefix. Other characters are disallowed. If no prefix is supplied (an empty string), the received string starts with the first received character.
- Suffix If a string is supplied to the input variable suffix, the input data is read until the end of the received string agrees with 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 recognised.
- Timeout If a timeout is supplied to the 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.
As soon as the output StringReceived becomes TRUE, the received data are ready in the ReceivedString variable.
Reset
Setting the Reset input will reset the block from the receive state into the initial state. Reset is only necessary in exceptional cases, such as when the expected string can not be received.
Note
The string ReceivedString has a standard length of 80 characters which may be to short for some applications. In this case the function block ReceiveString255 can be used. The only difference is the string length of 255 characters for ReceivedString.