Three specific communication functions are defined for sending and receiving data via a communication channel in Character Mode:
-
PRINT_CHAR: send a character string of a maximum of 1,024 bytes.
-
INPUT_CHAR: read a character string of a maximum of 1,024 bytes.
-
INPUT_BYTE: read a byte array of a maximum of 1,024 bytes.
NOTE: For INPUT_CHAR function, a configured timeout is necessary if the channel is configured without stop on silence, to acknowledge the activity bit of the function. For PRINT_CHAR function, it is advisable but not necessary to configure a timeout.
Internal Mechanism of the CPU
The Modicon M340 PLC serial port is full duplex, so a PRINT_CHAR function can be sent even when an INPUT_CHAR or INPUT_BYTE function has been sent and is still pending.
Two independent pointers allows access for reading and writing the data.
The below figure represents this mechanism:
The received data are stored in a 1024 bits cyclic buffer. Once the buffer has been fully filled, the 1025th bit received overwrites the 1st bit and so on. Each buffer bit read through the INPUT_CHAR function is reset.
The CPU save the ECHO of the transmitted data into the same buffer as the received data. Therefore it is mandatory to clear the buffer of the CPU after each PRINT_CHAR or before someone send data to the channel. Else the received data from an INPUT_CHAR or INPUT_BYTE will not be the expected one.
To clear the CPU buffer you can set to 1 the input parameter RAZ of the reading function and cancel this reading function before the timeout. The buffer is first reset then the processor is waiting for the reception of data.
NOTE: Using this feature is advised in order to start properly a reception by removing old data that can remain in the buffer.
There are two ways of programming that enable an exchange executed by the communication functions to be cancelled: