0

I'm building a Go application that runs in the terminal to gather input from two USB barcode scanners. How do I detect what barcode scanner the text (that's emulated as USB keyboard input) came from?

E.g. Barcode: 4009900522250 from Scanner 1 or Barcode: 4009900522399 from Scanner 2

I'm developing this on Mac OS, but the code will run on Raspbian for Raspberry Pi.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Brad Turner
  • 91
  • 1
  • 3
  • 5
  • 1
    @xarantolus: The answer to your question appears to be in the title: They emulate a keyboard. – Jonathan Hall Nov 06 '19 at 17:19
  • I'm pretty sure the only way to get that granular data is to read `/dev/inputX` (assuming Linux). See https://stackoverflow.com/questions/2775461/linux-keyboard-event-capturing-dev-inputx – Jonathan Hall Nov 06 '19 at 17:20
  • 1
    Yep, if you're receiving this as plain keyboard input, you don't know, same as you don't know which of multiple normal keyboards are typing - you just receive characters. To get more info you'd need to connect to the device directly. – Adrian Nov 06 '19 at 17:20
  • @xarantolus There is no library as they simply emulate a USB keyboard input. I've wrote a very basic Go program that waits for user input using `fmt.Scanln`. After the reader scans the barcode, it also 'clicks' return – Brad Turner Nov 06 '19 at 17:22
  • 1
    You may need different solutions for macos vs Raspberry Pi. Although they're probably similar (i.e. they may just require reading from different device names) – Jonathan Hall Nov 06 '19 at 17:25
  • 1
    This should help: https://stackoverflow.com/q/37134686/13860 – Jonathan Hall Nov 06 '19 at 17:27

1 Answers1

1

Many keyboard input barcode scanners have the ability to customize prefix/suffix codes that are appended to the front and back to identify barcode data input.

They can be customized by reading the settings barcode.

Set a different prefix/suffix code for each barcode scanner, check the key code notified by the application program one by one, and if such special data comes, either of which depends on the prefix/suffix code judges whether it is barcode data from the scanner.

kunif
  • 4,060
  • 2
  • 10
  • 30