ReceiveByte
Interface
VAR_OUTPUT
ByteReceived: BOOL;
ReceivedByte: BYTE;
Error: ComError_t;
END_VAR
VAR_IN_OUT
RxBuffer : ComBuffer;
END_VAR
Description
The ReceiveByte block receives a single character from the interface corresponding to the input variable RxBuffer. If ByteReceived=TRUE after the call, then the data byte received is available in the output variable ReceivedByte. Otherwise no data has been received.
Note
Whenever a the ReceiveByte block is processed in a PLC task that is running slower than the communication with the hardware, it must be remembered that more than one character can be made available in each PLC cycle. The characters received should therefore be read out within a loop:
REPEAT
Receive(RXbuffer:=RXbuffer);
IF Receive.ByteReceived THEN
(* evaluate character*)
END_IF
UNTIL NOT Receive.ByteReceived
END_REPEAT
The number of passes through the loop is inevitably limited by the size of the receive data buffer (presently 300 bytes), so that an endless loop need not be feared.
See also