Data can be received from an external device if the "reception done" flag is FALSE. (The "reception done" flag turns to FALSE after switching to “RUN mode” or if data is sent or the ClearReceiveBuffer is performed.) Data is automatically received in the receive buffer of the CPU or of the Multi-Communication Unit. For the CPU, the receive buffer must be defined in the system registers. After the end of reception has been verified, data can be copied into a specified target area of the CPU.
When for the specified time no further bytes are received or the instruction ClearReceiveBuffer is performed, the IsDone output turns to TRUE. Reception of any further data is prohibited. F159_MTRN or ClearReceiveBuffer turns the "IsDone" flag to FALSE.
Procedure for receiving data from external devices:
Set communication parameters and receive buffer
Required settings: communication mode (program controlled), baud rate, communication format, receive buffer (CPU only)
Receive data
Data is automatically received in the receive buffer.Verify end of reception
Use one of the following methods:
Method |
Comment |
IsReceptionDone |
Returns the value of the "reception done" flag. It is TRUE if the end code has been received. |
IsReceptionDoneByTimeOut |
Used to verify the end of reception by timeout, e.g. with binary data when no end code is expected. NOTE MCU: The reception timeout has to be set in the system register of the communication port. |
sys_bIsComPort1ReceptionDone sys_bIsComPort2ReceptionDone sys_bIsToolPortReceptionDone (CPU only) |
These system variables turn to TRUE if the end code has been received. |
Input (X) flags of MCU unit X0 and X2 (MCU only) |
These flags can be used to verify the end of reception with a Multi-Communication Unit. |
Direct evaluation of the receive buffer. |
Process data in receive buffer
Use one of the following instructions:Instruction |
Comment |
ReceiveData |
Automatically copies data received by the CPU or Multi-Communication Unit into the specified variable. |
ReceiveCharacters |
Automatically copies characters received by the CPU or Multi-Communication Unit into a string variable. |
F10_BKMV |
Transfers data from the receive buffer to a target area. Not required with ReceiveData or ReceiveCharacters. |
F161_MRCV |
Copies data received by a Multi-Communication Unit to the CPU’s receive buffer. Not required with ReceiveData or ReceiveCharacters. |
Prepare CPU or MCU to receive next data
Use one of the following instructions:
Instruction |
Comment |
ClearReceiveBuffer |
The receive buffer is automatically reset when sending the next data. To reset the receive buffer without sending any data use one of these instructions. |
SendData |