node-hid icon indicating copy to clipboard operation
node-hid copied to clipboard

List of Supported Scanners and Scanner.on data not called

Open nneuberger1 opened this issue 2 years ago • 5 comments

Does anyone know some hardware supported scanners for node-hid?

After doing a quick proof of concept with this library, I purchased about 3 of these (Tera Pro) scanners for a point of sale project. https://www.amazon.com/gp/product/B07T5KG5JC/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&th=1

After doing more detail research, I noticed it possibly only supports HID mode. When connecting the device using bluetooth to an iPhone/iPad, it acts as a keyboard.

My goal is to not force a scan into a text field to act like a keyboard.

Plus, so far, I've never got the library to call the following line of code. I suspect because the scanner is acting like a keyboard.

scanner.on("data", function(code){ console.log("recieved code : " + code); });

I'm building something similar to a customer app like Square has. They have a list of supported scanners and wasn't sure if anyone has used any of those to make this library work. https://squareup.com/help/us/en/article/5143-bar-code-scanners-with-square-point-of-sale

nneuberger1 avatar May 06 '22 11:05 nneuberger1

I'm also running on macOS, but my intended deployment will either be Windows or Linux (Ubuntu or Redhat)

nneuberger1 avatar May 06 '22 11:05 nneuberger1

If the device acts like a HID keyboard, then you need to use standard UI events / keyboard reading techniques in Javascript/Node, and you will not be able to use node-hid. This appears to be the default mode of the device you linked.

If the device can act like a serial port (which, from the manual of the one you linked, looks like it can), then you should use node-serialport not node-hid.

If the device has a "HID data" mode, where it appears as a custom HID device and not a keyboard, then you will be able to use node-hid. But this mode did not appear to be in the manual of the device you linked.

todbot avatar May 06 '22 16:05 todbot

Could you please describe more by what you mean by:

My goal is to not force a scan into a text field to act like a keyboard.

todbot avatar May 06 '22 16:05 todbot

thanks for your help! I'm a bit lost on exactly what to do.

While connected as USB to my Mac, I have a node service and if my cursor is in the terminal (or even a notes app), the data will get output into that terminal or notes app.

Basically, I'd like to receive that event through the following in node. Likely because I'm learning about how to use this scanner with node-hid, I don't see the following received.

scanner.on("data", function(code){ console.log("recieved code : " + code); });

Indirectly, I want to relay this data from the scanner.on event back to a frontend (that's written in Flutter / Dart) that will be using web sockets back to the front end application.

I'm trying just about anything. I even tried connecting the scanner via Bluetooth to an iPhone. It does connect, but it acts as a keyboard when I scan. I've attempted to use a library called flutter_blue for receiving the data, but no joy.

https://pub.dev/packages/flutter_blue

I'll checkout the serial port option that you mentioned next. If you have any other ideas, that would be great.

nneuberger1 avatar May 06 '22 16:05 nneuberger1

To read a keyboard (doesn't matter if it's a scanner or normal) in a Node process, you'd do something like this: https://www.cloudhadoop.com/nodejs-keystrokes-stdin/ But the terminal window has to have focus to receive the key events. You cannot use node-hid because the OS owns keyboards (for security reasons)

If you have a front-end UI, you can use standard UI keyboard events, like this in Javascript https://www.section.io/engineering-education/keyboard-events-in-javascript/

todbot avatar May 06 '22 16:05 todbot