Buffers are designed to work with data communication functions.
The list of functions for data communication is given in the guide Function Block Library > Data Communication.
When working with all digital ports and interfaces, two buffers are used to receive and transmit data:
Name | Designation | Size, bytes |
---|---|---|
Buffer for receiving data | RXD | 128 |
Buffer for transmitting data | TXD | 64 |
In the editor, when debugging, buffers are displayed as an array of bytes, indexed from 0
to (buffer_size - 1)
.
There are many functions used to transmit data, but RS_SEND should be considered basic.
On its example, the process of data transmission is briefly described below. It can be divided into several main stages:
There are many functions used to receive data, but RS_RECV should be considered basic.
On its example, the process of data reception is briefly described below. It can be divided into several main stages:
If the procedure is extremely simple when transmitting data, then when working with receiving data, one important feature of data processing should be taken into account - device is able to receive an unlimited amount of data, but the RXD buffer can store no more than 128
bytes.
If the device will receive data that exceeds 128
bytes, RXD buffer will overflow. On overflow, the RXD buffer only holds the last 128
bytes of received data.
At the same time, for one cycle of execution of the receive function, device places no more than 64
bytes of data from the interface into the RXD buffer.
Therefore, if it is necessary to process data that exceeds 128
bytes, the program should be compiled in such a way that after each cycle of the function for receiving data from the interface, the current contents of the RXD buffer are processed. This approach will allow processing the entire required amount of data in several iterations.
It turns out that when working with large volumes of data, the RXD buffer is a sliding window along the flow of incoming information. The window size is
128
bytes, and the maximum offset per cycle is64
bytes.
Below is a visual representation of the process of receiving data that is slightly larger than the size of the RXD buffer:
64
bytes, increments the received data counter size
by 64
, and puts the data into the RXD buffer, starting at index 0
.64
bytes, increments the received data counter size
by 64
, and places the data in the RXD buffer, starting at index 64
.X
bytes, increments the counter of received data size
by X
, erases the first X
bytes in the RXD buffer, shifts the contents of the RXD buffer by X
bytes "to the left" (i.e. the byte at index X-1
will now be located at index 0
), increases the overflow counter offset
by X
and places data in the RXD buffer, starting at index (128-X)
.Transaction function is provided as a special case of data exchange. This is a sequence of the two previous operations Transmit and Receive. This approach is convenient to use for working with devices on a request/response basis.
There are many functions used to made the transaction, but RS_TRANS should be considered basic.
On its example, the process of transaction is briefly described below. It can be divided into several main stages: