ReadBarcode

Availability All terminals
Description This function tries to fetch a barcode from the scanner.
Syntax unsigned int ReadBarcode( struct barcode *barcodep );
Arguments
struct barcode *barcodep
The structure barcode is defined as follows:
struct barcode
{
    char *text;
    int length;
    int id;
    int min;
    int max;
};
Member Description
text Pointer to a user supplied character buffer. ReadBarcode() places a zero-terminated barcode string in the text struct member on a successful read.
length Contains the number of characters returned in text struct member.
id The symbology of the barcode that was scanned. In the LIB.H file, a constant is defined for all supported symbologies. Look under the section "Constants for id member" to check out the various constants.
min The minimum allowed length of a barcode.
max The maximum allowed length of a barcode.
Returns
OK A barcode was available.
ERROR No barcode was available.
Remarks ReadBarcode() tries to find a barcode in the OS buffer that is filled with decoded barcode data.
If ReadBarcode() finds a barcode in the buffer, it fills the barcode structure, and returns.
If no barcode was read, ReadBarcode() calls Idle() and returns.

Use the SystemSetting() function to select which barcode symbologies must be read.
Example

// This program reads and displays a barcode. After each successful barcode reading,
// it gives a good read signal on the LED and a buzzer signal.

#include <stdio.h>
#include "lib.h"

void main( void )
{
    char bcr_buf[42] = {0};
    struct barcode code  = {0};

    code.min   = 3;
    code.max   = 41;
    code.text  = bcr_buf;

    ScannerPower(SINGLE|TRIGGER, 100);        // Single read, trigger mode, 2 sec

    for(;;)
    {
        if(ReadBarcode(&code) == OK)
        {
             GoodReadLed(GREEN, 10);
             Sound( TSTANDARD, VHIGH, SMEDIUM, SHIGH, 0);
             printf("%*s\r", code.length, code.text);
        }

        Idle();
    }
}