C Language Development Kit/Functions/ReadBarcode

From OptiWiki

< C Language Development Kit | Functions
Revision as of 11:48, 25 February 2009 by Jbo (Talk | contribs)
(diff) ← Older revision | Current revision (diff) | Newer revision → (diff)
Jump to: navigation, search
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 text on a successful read.
length Contains the number of characters returned in text.
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 a buffer with data supplied by the scan-engine.

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, a buzzer signal.
//
// Note that an extra check is made on the minimum length when the barcode symbology
// is one of the 2 of 5 codes, or Codabar. This is done because of the poor
// specifications of these symbologies.
// Note the use of a loop, repeatedly invoking readbarcode().
 
#include "lib.h"
#include <stdio.h>
 
void main( void )
{
    char bcr_buf[42];
    struct barcode code;
 
    code.min   = 1;
    code.max   = 41;
    code.text  = bcr_buf;
 
    for(;;)
    {
        if( !scanneroff())
        {
            if( readbarcode(  ) == OK)
            {
                if( (code.id != CODABAR) &&
                    ( code.id != I2OF5) &&
                    ( code.id != D2OF5) ||
                    ( code.length > 5))
                {
                    goodreadled( RED, 10);
                    sound( TSTANDARD, VHIGH, SMEDIUM, SHIGH, 0);
                    scannerpower( OFF, 0);
                    printf("%s\n",code.text);
                }
            }
        }
        else
        {
            delay( 50 );
            scannerpower( ON, 250);
        }
        idle();
    }
}


Views
Personal tools