Processing data in receive buffer and preparing CPU to receive further data

Receive a string of 8 bytes containing the characters "ABCDEFGH" via COM port 1. The characters are stored in ASCII HEX code without start and end codes.

  1.  (1) "Reception done" flag
  2.  (2) Execution condition
  3.  (3) Reception begins
  4.  (4)  Reception continues
  5.  (5) Execution of F159_MTRN (n_Number=0)

Receive buffer layout:

When reception begins, the value in offset 0 is 0. At the end of reception, the value in offset 0 is 8. The data in offset 1 to offset 4 is received in order from the lower byte.

System register settings

In order to use the data in the receive buffer, define a global variable having the same starting address and capacity. In this example, the starting address is DT200 (VAR_GLOBALDT200_awReceivedBuffer) and the receive buffer capacity is 5 (ARRAY [0..4] OF WORD).

Global variables

POU header and LD body

ST body

Data can be received from an external device if the "reception done" flag is FALSE. The "reception done" flag is evaluated by the system variable sys_bIsComPort1ReceptionDone. When the reception of the data is complete (the end code has been received), the "reception done" flag turns to TRUE, and subsequently, receiving data is prohibited. To prepare the system to receive the next data without immediately sending further data, the receive buffer is reset by executing F159_MTRN with n_Number = 0.

NOTE
  • The number of received bytes may change while a scan is being carried out. For example, if the number of received bytes is read more than once different statuses may exist within one scan.
  • The start code "STX" resets the receive buffer.

Modified on: 2022-03-02Feedback on this pagePanasonic hotline