Is it possible to have multiple STDIN threads?

I hope to connect two USB barcode scanners to one computer, allowing two people to scan bitcodes at the same time. However, if both scan at the same time, the input from STDIN becomes messy.

Is there a way to configure different STDIN streams, each of which is associated with a specific USB port? The script console is in Ruby, although pointers in any language would be much appreciated.

+3
source share
3 answers

Try connecting 2 USB barcode scanners first and checking to see if what you are afraid of has happened. I suspect that all barcode digits are sent in one packet, while interrupts from other keyboard devices are on hold - so you will not get two barcodes "interlaced" together.

It is impossible to have more than one stdin, not literally. Other options depend on the OS you are on - on linux, perhaps the drivers provide you with different character devices for different scanners. On Windows, I believe that you will need to learn to speak the USB HID protocol ... best if you don't need to do anything.

+3
source

, STDIN. ( , - )

+3

, Mutex , ?

Here is a threading tutorial in Ruby

http://ruby-doc.org/docs/ProgrammingRuby/html/tut_threads.html

0
source

Source: https://habr.com/ru/post/1786244/


All Articles