ReceiveByte
The function block ReceiveByte receives a single character from the interface corresponding to the input variable RxBuffer.
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
ByteReceived : BOOL;
ReceivedByte : BYTE;
Error : ComError_t;
END_VAR
Name | Type | Description |
---|---|---|
ByteReceived | BOOL | If ByteReceived=TRUE after the call, then the data byte received is available in the output variable ReceivedByte. Otherwise no data has been received. |
ReceivedByte | BYTE | If ByteReceived=TRUE after the call, then the data byte received is available in the output variable ReceivedByte. Otherwise no data has been received. |
Error | If a fault occurs, Error will contain an error code. |
Sample
Whenever a the function block ReceiveByte is processed in a PLC task that is running slower than the communication with the hardware, it must be observed 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
(* Zeichen auswerten *)
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 infinite loop need not be feared.
Requirements
Development environment | Target platform | PLC libraries to include |
---|---|---|
TwinCAT v3.1.4012 | PC or CX (ARM, x86, x64) | Tc2_SerialCom |