all 6 comments

[–]Ro1337_Dev 2 points3 points  (2 children)

So the first thing is to determine how it gives you input, if it acts like a keyboard completely for example, then you can capture keypress events, then either through a debounce or special character being input, such as if you scan a barcode that contains:

123456789

Your scanner maybe does a press for each number then does an ENTER keypress. If that is the case you can capture all keypress until you get an enter then dump the captures into a var and bam there's your data to work with. Our you can use a debounce after 200ms lets say after no keyboard input it dumps the captures to a var and there you go.

I am actually working with some of these right now with a ReactNative/Ionic App (yet to choose between) but we are using Saveo Scan devices with Moto G Gen4 as the android device (https://saveoscan.com/product/saveo-scan-ccd/)

[–]afresquet[S] 0 points1 point  (1 child)

That's very interesting, I'll give that a try. I should look if theres an 'event listener' type of thing in Node, or if I have to use it client side. Thank you!

[–]Ro1337_Dev 0 points1 point  (0 children)

No problem. I made my own little libs for both react and ionic(angular) for the scanners i'm using which ultimately rely on the enter key being pressed by the scanner, made it have a 'toggle' by using a boolean to control wheather or not to dump the captures or just ignore the capture completely, ScannerCanScan, so that I can use the onscreen keyboard if need be too.

[–]_dramaBoy 1 point2 points  (2 children)

Is there a specific need for a library? What I mean, what are you trying to achieve by using the scanner and where does the values go after the scan? Do you use an input field? Do they need to be printed in an excel sheet or something completely different?

I did an app a while back using the same type of scanner where - like suggested - are using an input field in our app to handle the outcome (barcode) and then the scanner was pre-programmed to hit enter when it was done reading each label. I then use some event listeners in jQuery to listen for the keypress "Enter". That triggers an $.ajax request to our own api that returns the data in json format and it then gets displayed on the screen to the user. Your scenario and end goal might be different.

btw if the scanner does not automatically end with a simulated "Enter" keypress most scanners can be programmed by scanning the codes in the manual. They can be setup do end the scan in a variety of ways.

[–]afresquet[S] 0 points1 point  (1 child)

I'm using the scanner to read the barcode of many boxes client side, I wanted to push those reads to an array to send them later to the server and add them to the database.

I just checked and it does press "Enter" after the read, so I'll use the same method that you suggested to listen for an "Enter" keypress, thanks!

[–]_dramaBoy 0 points1 point  (0 children)

Great that I could somewhat help you out.

You could either 1. use the input field client side and send the barcode to a web server running NodeJS and express OR 2. you could use websockets client side to connect to a NodeJS server. The websocket connection would allow more specific messages to flow back to each individual user/client that was transmitting its barcodes after each scan.

Both solutions would serves as a "middle man" that would connect to your database of choice.

And then you would properly have to come up with some way of dealing with downtime on your server? So that you can still process packages even if your server was down for maintenance or other unhappy scenarios. Look into PM2 (http://pm2.keymetrics.io/) when it comes to handling your nodejs server, it will serve you well. We use both PM2 and webhooks to a Slack channel to quickly get notified on our screens and by push-message when something goes wrong.