Longitudinal Redundancy Check (LRC) Calculation

The calculation of the LRC is extremely important as it is used by both the POS Device and Elavon to validate the contents of the packet of data received during communications. In the event of a “Bad LRC,” the packet just received should be discarded, and a NAK (negative acknowledgment) should be sent as outlined in the Communications Protocol section of this document. (See “Elavon sends NAK to POS and POS sends NAK to Elavon”).

In the most general terms, the LRC is calculated by performing what is referred to as an “exclusive OR” of the packet to be transmitted (or received, in the event of validation). This calculation excludes the STX (Packet Start of Text Character) but includes the ETX or ETB (Packet End of Text or End of Block Characters).

As there are many different programming languages, platforms and styles of coding this document cannot address them all. However, provided below is a simple example of an LRC calculation written in C++ syntax.

In this example, the entire packet (including STX, ETX, or ETB) is passed to the Routine. It automatically bypasses the STX character, thereby, omitting it from the calculation. The return value is the calculated LRC, which should be appended to the Packet when transmitted.

// Beginning of C++ Sample Subroutine

    // Compute LRC computes the LRC of a packet which has included the STX

    // and ETX or ETB. The LRC is then returned.


unsigned char ComputeLRC(unsigned char \*Packet)

    {
        unsigned char \*p = Packet;
        unsigned char lrc = 0x00;

        p++; // bypasses STX in packet

        while (\*p != ETX && \*p != ETB) {lrc ^= \*p; p++; }

        lrc ^= \*p;

        return lrc;

    }

        // End of C++ Sample Subroutine