Web Demos

BARCODE READER SDK DEMO

Explore the flexibe barcode reading settings to optimize for your specific usage scenario.

WEB TWAIN SDK DEMO

Try the most popular web scanner features: scan images, import local images and PDF files, edit, save to local, upload to database, and etc.

BARCODE READER JAVASCRIPT DEMO

Transform any camera-equipped devices into real-time, browser-based barcode and QR code scanners.

MRZ SCANNER WEB DEMO

Detects the machine-readable zone of a passport, scans the text, and parses into human-readable data.

APP STORE DEMOS

BARCODE READER SDK FOR IOS

BARCODE READER SDK FOR ANDROID

VIEW MORE DEMOS >

Build Node.js Barcode Reader on Raspberry Pi

Dec 11, 2017

Node.js is available for all platforms including IoT devices like Raspberry Pi. In this post, we will demonstrate how to quickly create an online barcode reader on Raspberry Pi using Node.js and Dynamsoft Barcode Reader SDK.

Node.js for Raspberry Pi

If you flashed Rasbian Jessie, the latest Linux ROM for Raspberry Pi, you might have noticed that Node.js is pre-installed by default. However, the Node version is out of date. To get new features of Node.js, download the latest version. Here are the steps to install Node.js for Raspberry Pi.

  1. Remove the pre-installed Node.js: [javascript] sudo apt-get remove node [/javascript]
  2. Check Pi hardware information:``` uname –m armv7l

    ```

  3. Download the matched Node version for ARM.
  4. Extract the package:``` tar –xf node-v4.4.1-linux-armv7l.tar.xz

    ```

  5. Add the bin path to ~/.bashrc:``` vim ~/.bashrc export PATH=$PATH:/home/pi/node-v4.4.0-linux-armv7l/bin source ~/.bashrc

    ```

  6. Verify whether Node can work:``` node –v v4.4.0

    ```

Building Online Barcode Reader

Get the Dynamsoft Barcode Reader SDK for Raspberry Pi below. Download Dynamsoft Barcode Reader for Raspberry Pi > Extract the package and generate a symbolic link:``` sudo ln -s /lib/libDynamsoftBarcodeReader.so /usr/lib/libDynamsoftBarcodeReader.so

Install node-gyp for building Node C/C++ add-ons.```
npm install -g node-gyp

Create dbr.cc and binding.gyp:``` // dbr.cc Isolate* isolate = Isolate::GetCurrent(); HandleScope scope(isolate);

// convert v8 string to char * String::Utf8Value license(args[0]->ToString()); String::Utf8Value fileName(args[1]->ToString()); char *pFileName = *fileName; char *pszLicense = *license; // Dynamsoft Barcode Reader: init __int64 llFormat = args[2]->IntegerValue(); int iMaxCount = 0x7FFFFFFF; ReaderOptions ro = {0}; pBarcodeResultArray pResults = NULL;

// Initialize license if (pszLicense && (strcmp(pszLicense, “null”) !=0) ) { printf(“license: %s\n”, pszLicense); DBR_InitLicense(pszLicense); } else { #ifdef LINUX_DBR printf(“Linux dbr license\n”); DBR_InitLicense(“"); #endif }

ro.llBarcodeFormat = llFormat; ro.iMaxBarcodesNumPerPage = iMaxCount;

// Decode barcode image int ret = DBR_DecodeFile(pFileName, &ro, &pResults);

// binding.gyp { “targets”: [ { ‘target_name’: “dbr”, ‘sources’: [ “dbr.cc” ], ‘conditions’: [ [‘OS==”linux”’, { ‘defines’: [ ‘LINUX_DBR’, ], ‘include_dirs’: [ “/home/pi/Desktop/dbr/include” ], ‘libraries’: [ “-lDynamsoftBarcodeReader”, “-L/home/pi/Desktop/dbr/lib” ] }] ] } ] }

Build dbr.so:```
node-gyp build

Install Node modules express and formidable for rapidly making a Web project:``` npm install express formidable

Use the barcode module in **server.js**:```
var dbr = require('./build/Release/dbr');

dbr.decodeFile(

    license, fileName, barcodeType,

    function(msg) {

        var response = 'Totol count: ' + msg.length;

        var result = null;

        for (index in msg) {

            result = msg[index]

            response += '<p>' + result['format'] + ': ';

            response += result['value'] + '<p>';

        }

        res.send(response);

    }

);

Start the server:``` node server.js

``` Visit http://localhost:2016/index.htm and try online barcode reader for Raspberry Pi: Barcode Reader for Raspberry Pi

Source Code

https://github.com/dynamsoftlabs/raspberry-pi-nodejs-barcode-reader-

Subscribe Newsletter

Subscribe to our mailing list to get the monthly update.

Subscribename@email.com