USB Barcode Scanner Setup & Flow (requires SSH access)

EDIT. We have found out the hard way that the node required for this post is broken in newer versions of NPM / Nodejs.
groov EPIC firmware bumped those versions around 1.4.0, so anything newer will not be able to use these instructions.
If we find or hear about a workaround / fix we will update this post.

Here are some detailed instructions for installing the node-red-contrib-usbhid Node-RED package on a groov EPIC. The flow at the bottom of this post can be used to get generic USB barcode scanner input in a Node-RED flow so you can use it in PAC Control, groov View, log it in a database, or anywhere else that you might need it.

  1. Open a new shell session.
  2. Get a required USB library:
    a. sudo apt-get update
    b. sudo apt-get install libusb-1.0-dev
  3. Give the Node-RED “dev” user permission to access USB:
    a. sudo mkdir -p /etc/udev/rules.d
    b. sudo nano /etc/udev/rules.d/85-pure-data.rules
    c. Add the following rule:
    SUBSYSTEM=="usb", GROUP="input", MODE="777"
    Use ctrl+o to save the file and then ctrl+x to exit the text editor
    d. sudo groupadd -f input
    e. sudo gpasswd -a dev input
  4. Close shell and install node-red-contrib-usbhid through the Node-RED package manager.
  5. Import and deploy the flow pasted below.
  6. Get the ID information for your scanner device:
    a. Inject the “Get USB Device IDs” flow, check the debug pane to see what’s already there
    b. Plug in your USB scanner and run the flow again
    c. Note the “VID” and “PID” for the new device in the debug pane
    d. Open the “Barcode Scanner” node and use the pencil to update the ‘Connection’ settings
    e. Type or paste in the VID and PID for your USB scanner and name the new connection
  7. Redeploy the flow and now any scanned codes should show up in the debug pane after 1s!

[{"id":"632a3966.4e64e8","type":"inject","z":"45a3a637.29c0e8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":500,"y":440,"wires":[["14f877c5.78cd48"]]},{"id":"167e060f.1502ba","type":"debug","z":"45a3a637.29c0e8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":890,"y":440,"wires":[]},{"id":"14f877c5.78cd48","type":"getHIDdevices","z":"45a3a637.29c0e8","name":"Get USB Device IDs","x":700,"y":440,"wires":[["167e060f.1502ba"]]},{"id":"500d4560.c8462c","type":"HIDdevice","z":"45a3a637.29c0e8","connection":"12763923.7040f7","name":"Barcode Scanner","x":430,"y":520,"wires":[["5d269865.5134c8"],[]]},{"id":"5d269865.5134c8","type":"join","z":"45a3a637.29c0e8","name":"Create Array","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"1","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":630,"y":520,"wires":[["d0e87266.42154"]]},{"id":"d0e87266.42154","type":"function","z":"45a3a637.29c0e8","name":"extract barcode","func":"var data = ''; // initialize output string\nfor(i = 0; i < msg.payload.length - 2; i+=2) { // get every other character for 1D barcodes\n next = msg.payload[i][3] - 29; // offset for integer numbers\n if(next < 0) next = String.fromCharCode(next + 122); // offset for ascii characters\n if(next == 15) data += ' '; // handle any space characters\n else if(next == 10) data += 0; // 10 is used in place of zero, since 0 means \"nothing\"\n else data += next;\n}\nreturn { payload : data };","outputs":1,"noerr":0,"x":800,"y":520,"wires":[["64f6799b.cbd528"]]},{"id":"64f6799b.cbd528","type":"debug","z":"45a3a637.29c0e8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":970,"y":520,"wires":[]},{"id":"12763923.7040f7","type":"HIDConfig","z":"","vid":"1155","pid":"22352","name":"Inateck BCST-33 1D Barcode Scanner"}]

Happy coding!

1 Like

Hi Terry,

Did you mean, this setup allows the use a barcode scanner that usually comes with USB dongle that emulate a keyboard input - just plug the usb dongle onto EPIC usb port?

Thank you.

That’s correct, whatever barcode you scan is fed straight into Node-RED character-by-character. I’ve tested it with a generic cabled USB scanner plugged into my groov EPIC and it does come in just like keyboard input.

Just be aware that the data does not come in as exact characters, it is offset numbers and ascii so you do need to do some conversion if you need the actual text or numbers from the barcode, but the function node in the flow above can handle that for you.

I was trying to get it work USBHID node to work on a PC. So I can test my code in node-red on PC.
If it is not so troublesome, could make barcode work on PC too? this is for testing and demo purpose. So we can simulate getting barcode data into node-red and pac control.

We have been focused on the EPIC of late, so have not had the time to test it on a PC.
Have you tried it?

Hi,

Has there been any developments to this method.

I achieved the entire process till I had to install the node-red-contrib-usbhid into Node Red. Keeps on failing to install.

Any thoughts, possibly I can email the log file for some advise ?

Best Regards
Robin

None of the nodes involved are Opto22 nodes, so @torchard and I can only tinker as we get time.
Perhaps posting to the https://discourse.nodered.org/ forums might yield some tips to try.

Perfect example is @grant1 getting some OCR assistance yesterday: Help with simple OCR of two-digit numbers - General - Node-RED Forum
I bet this has something to do with his process that has some groov hardware in the mix (Not the OCR bit as groov does not have webcam drivers… yet…).

Right you are! groov EPIC controlling is 6 solenoid valves to manipulate flows to a single point, which is then fed into an analyzer that monitors & displays the output (dew point) as a 2-digit LCD.

1 Like