Skip to content

Bar-code type 128

The bar-code type 128-B turns a text into a bar-code, including the CRC.

The displayed bar-code includes a leading B and a final CRC.

Configure

Warning

Ensure the bar-code 128 library is included and initialised according to the configuration procedure.

As a function, the bar-code 128 element requires no configuration.

Use

1
2
3
4
5
6
bool result = codeBar128(&myScreen,
    0, dy,
    "ABC-1234",
    32,
    myColours.black, myColours.white,
    false);

The required parameters are

  • The first line sets the link to the screen;

  • The second line sets the x-y coordinates of the top-left corner of the code-bar;

  • The third line provides the text.

The optional parameters are

  • The fourth line sets the height of the bars, with 32 pixels as default;

  • The fifth line specifies the colours for the front and the background, with black on white as default;

  • The sixth line displays the text below the bar-code, with false as default.

codeBar128 returns RESULT_SUCCESS if successful, RESULT_ERROR otherwise. The most common cause of error is an overflow due to a text too long.

uint16_t dz = getCodeBar128Size("ABC-1234");

getSizeCodeBar128() returns the width of the bar-code in pixels.

Example

This is the core of the code from example Code_Bar128.ino.

void displayCodeBar128()
{
    myScreen.setOrientation(myOrientation);

    uint16_t x, y, dx, dy, dz;
    uint8_t result;

    x = myScreen.screenSizeX();
    y = myScreen.screenSizeY();
    dx = x / 5;
    dy = y / 5;

    myScreen.selectFont(fontMedium);
    myScreen.gText(0, 0, "Bar-code type 128");

    myScreen.selectFont(fontMedium);
    myScreen.gText(0, 4 * dy, "*ABC-1234*");

    dz = getSizeCodeBar128("ABC-1234");
    result = codeBar128(&myScreen, (x - dz) / 2, dy, "ABC-1234", 32, myColours.black, myColours.white, true);
    if (result == RESULT_SUCCESS)
    {
        myScreen.flushFast();
    }
}