Receive Serial Data in Advanced Ladder

See also: Serial Communication in Advanced Ladder

See also: Project Toolbox for Advanced Ladder

 

The Receive Communication Data function is used to bring ASCII data from the serial port buffer into the program. The port must be one that has been opened with the Open Communications Port function and specified as “Generic ASCII” protocol. Noting the triangular “>” symbol on the input rung of the function, it will do as configured one time when it receives power. In cases where the configured number of bytes is not yet present, leaving the function powered will allow it to continue to receive data until the number of bytes configured has been reached. Interruption to rung input power and re-applying rung input power is required to function again.

Note: The Receive Communication Data function removes the specified number of bytes/characters from the serial port buffer. It is possible that the number of characters specified does not exist in the buffer, indicated by the RX Count never reaching the number of bytes specified and power never being passed through the function. It is also possible for more data to exist in the buffer beyond what the function is configured for. Leftover data would then be first in line to be received the next time a Receive Communication Data function is used. Therefore, it is important during development to determine the behavior of ASCII devices so that unexpected situations are minimized.

The Receive Communication Data function is meant for use with 8-bit ASCII data. Each 8 bits, or 1 byte of data is the space a single ASCII character consumes. Therefore, “Bytes” is synonymous with “Characters” in this case. ASCII characters used may be any of 255 characters to include the standard ASCII characters from character code 0x00 through 0x7F (decimal 0 – 127, “printable” characters such as numerals, the alphabet, and “non-printable” characters such as carriage return, line feed, etc.) as well as codes 0x80 through 0xFF (decimal 128 – 255, characters normally defined by the device manufacturer). See also: ASCII Character Codes in Serial Communication in Advanced Ladder.

Port: The port from which to receive data. This must be a port previously opened with the Open Communication Port function [see:Serial Communication in Advanced Ladder ] and specified as “Generic ASCII” protocol.

Number of Bytes: Variable/register or constant value determining the number of bytes to receive when this function is used. Synonymous with the number of ASCII characters to receive. Up to 255 Bytes may be received at a time.

Data Address: Variable/array/registers to which data will be received. In the case of 16-bit registers such as %RClosed Retentive 16-bit registers., 2 ASCII characters are packed into one register. Consecutive elements/registers will be used accordingly as dictated by the Number of Bytes parameter.

RX Count Address: Variable/register that contains the number of bytes/characters transferred from the port’s receive buffer so far when the function is powered. The RX Count maximum value is the number specified by the Number of Bytes parameter. The value when the function is not powered will be -1 when viewed as INT format.

 

Power Flow

The Receive Communication Data function executes immediately as soon as it receives power from the incoming rung.

The Receive Communication Data function will execute one time when it is powered. Power must be removed and reapplied to Receive more data.

Assuming the specified port has been opened, the Receive Communication Data function will pass power flow to the next function on the rung when the data has been completely transferred from the serial port buffer. This may take more than one OCS scan if the requested number of bytes is not yet present in the receive buffer, which can become more prominent with lower baud rates. Function completion is also indicated by the RX Count matching the number of bytes to Receive.

If the port has not been opened, or if the number of bytes specified is outside the range of 0 to 255, no power flow through the function will occur.

There is no need for any further functions to exist to the right of the Receive Communication Data function on the rung. The function’s result is considered an output.

 

Return to the Top: Receive Serial Data in Advanced Ladder