alehaa / crutils

Tools and API to communicate with barcode readers
GNU Lesser General Public License v3.0
3 stars 0 forks source link
barcode barcode-reader barcode-scanner c qrcode qrcode-scanner

crutils

Travis Codecov GPL license

Crutils provides a uniform way to get barcodes from different barcode readers.

About

Some barcode readers emulate a HID (keyboard), some dump the output via serial and others use different protocols. To connect to any of these, you have to implement several APIs in your application and have to extend the code for new protocols.

Crutils provides a uniform API to read barcodes from different devices as simple as reading from stdin. Applications don't have to manage the communication with barcode readers anymore and on top, crutils is extendable by drivers for future protocols without recompiling your code.

Configuration

The default configuration file in etc/codereader.conf in your install path loads no codereaders. To use barcode readers, you have to add their definitions in this file, or use an alternative configuration file by setting the CODEREADER_CONFIG environment variable. The libconfig syntax will be used.

Each device is defined as a named variable with an array of options. At least the driver field must be set to the name of the driver to use. A simple configuration may look like the following example:

test1 = {
  driver = "xinput2";
  match = ["OKE PS2-USB", "Barcode"];
};

A detailed description is included in the default configuration file.

Drivers

Currently the following drivers are supported:

Usage

Cruilts comes with a binary called codereader. You can use it in shell scripts to get barcodes. In normal mode it will print received barcodes in an endless loop.

~$ codereader | tee barcodes.txt
12345

You may add an optional argument -n with the number of barcodes to read:

~$ codereader -n 1
12345
~$

Integration

For C/C++ applications libcodereader provides the codereader API. Simply create a new FILE * handle with codereader_open() to use it with functions like fgets to receive your barcodes as input from stdin - that's it.

#include <stdio.h>
#include <codereader.h>

int
main() {
    FILE *ch = codereader_open();
    char buffer[32];
    while (fgets(buffer, 32, ch) != NULL)
        printf("%s", buffer);
}

Adding a new driver

As mentioned above, crutils is extendable by drivers for any kind of devices. If your device is not supported yet, you may add a new driver in the src/drivers directory: Simply add a new subdirectory for your files and build it by calling the CMake function codereader_add_driver(NAME SOURCES ...).

Each driver must support the following symbols:

Contribute

Everyone is welcome to contribute. Simply fork this repository, make your changes in an own branch and create a pull-request for your changes. Please send only one change per pull-request.

You found a bug? Please file an issue and include any data to reproduce the bug.

License

crutils is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

crutils is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. A Copy of the GPL can be found in the LICENSE file.

Copyright © 2013-2017 Alexander Haase