ex_bardecode
Unofficial Elixir NIF for Softek Barcode Reader Toolkit.
NOTE: test/fixtures/barcode.jpg should be removed from history if this repository is made public.
Installation
If available in Hex, the package can be installed
by adding bardecode to your list of dependencies in mix.exs:
def deps do
[
{:ex_bardecode, "~> 0.9.5"}
]
endDocumentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/ex_bardecode.
Usage
Bardecode exposes three functions for reading barcodes from different sources.
read_barcodereads from the specified image file (JPEG or TIFF)read_barcode_from_bitmapdecodes JPEG data from an in-memory binary
Bardecode.read_barcode(
"barcode.jpg",
%{
license: "license key",
type: [:pdf417, :code128],
multiple: true
}
)The options map is the same for all three functions.
licensestring for SoftTek (optional). If no license is specified, the last three characters of barcodes will be replaced with ???. A 30 day license can be obtained from sales@bardecode.com.typeis a list of barcodes to look for. By default it looks for all types, but this is slower than specifying specific types. Valid types are [:codabar, :code39, :code128, :code25, :ean13, :ean8, :upca, :upce, :pdf417, :datamatrix].multiplewill wait to find multiple barcodes iftrue. By default (false) it returns as soon as one barcode of any type is found.max_threadscan be used to limit the number of threads used. The default (0) determines the number based on the number of CPU cores available.timeoutis the maximum time in milliseconds, the default is 5000 (more of a suggestion).
Tasks
| Task | Description |
|---|---|
| mix compile | Builds bardecode, downloading the library if needed |
| mix clean | Removes files created by mix compile |
| mix test | Run the test suite |
| mix hex.publish | Publish a new version to Hex.pm |
Test under Linux using a Docker container:
docker build . -t ex_bardecode
docker run -it ex_bardecode /bin/bash
mix test --traceCode Layout
| File | Description |
|---|---|
| src/bardecode.c | C code for the NIF |
| src/barcode.h | Header file copied from the library |
| lib/bardecode.ex | Elixir function stubs for calling C |
| test/bardecode_test.exs | Elixir test suite |
| Makefile |
For building the NIF using mix compile |
Resources
- Softek Barcode Toolkit documentation included in the download
- Erlang Native Implemented Functions (NIF)
- Using C from Elixir with NIFs
- libjpeg download contains an example.c