Redirect USB HID Barcode output to /dev/tty device - linux

I am having a USB-HID barcode scanner. When I try to scan the barcode the output is displaying on STDOUT. I am using Ubuntu machine. I want the output to be redirected to some tty device. So I will be doing open(tty*) with blocking mode.Wait till the Barcode data is captured in that /dev/tty*.
How can i achieve the redirecting part ?

So your problem is basically that you are not able to "bind" the barcode reader input to your software which redirects it to the /dev/tty*?
In this case I would recommend the Python evdev module. "evdev" stands for "event device" which is a Linux kernel term (see evdev on Wikipedia). Your barcode reader is an event device (/dev/input/event*) like a keyboard or gamepad. You could create an event device object with Python evdev and use the grab_context() method to bind the input exclusively to your script. Mention that there are also Linux evdev libraries for other languages which probably all refer to the C implementation.
Having a similar issue I started to write a software for piping barcode input to the network via MQTT. If you want to have a look at example code you could check out my project. The relevant Python files are directly in the root directory.

Related

How does Linux determine a device class?

Linux newbie question.
Just wondering how Linux determines which device class a device is? Specifically, when I plug a barcode scanner in how does it know it is an ttyACM device? I have a scanner that works with my Linux OS but the new model isn't recognized so I'm wondering if I can alter a file somewhere in the system that tells it to recognize the scanner as ttyACM0 and use the existing drivers.
USB devices (I assume your scanner is USB) are identified by vendorId and productId (two 16bit integers), each driver fill an array with the list of supported vendor/prods id (creating a relation vendor:prod->driver), I guess at compile time all the id in the array are merged together in a list which then is used for a lookup search when a device is plugged in.
Usually you can see vendor and product id of the attached device with dmesg command right after the device is plugged in (or with lsusb).
For ttyACM see acm_ids[] in drivers/usb/class/cdc-acm.c
Careful playing around with device drivers, even being ttyACM a terminal interface only if the interface tty->hardware is implemented poorly some command may break the hardware.
Perhaps this question should be in Unix & Linux stackexchange

Use serial-console as display, but computer keyboard for standard-input

I have a 40x7 VFD that functions as a serial terminal. It has a dedicated keypad that provides hex-entry, however, I would like to use a keyboard for the standard input. Basically, I want to be able to use the VFD as a display for a Linux bash prompt, but use the keyboard connected to the computer as the means of input. Instead of connecting a monitor, the serial terminal will be the monitor. I can get the login prompt displayed on the VFD with agetty, but since it only has hex-entry, how can I change where the system is looking for standard input?
Thanks,
Core_Module
I think the best method would be to create a pseudo terminal. In doing so you create a fake terminal device with a /dev/pts/[n] name that acts like a real input/output device. A program could connect the console (keyboard) as input and the VFD as output and send and receive that data over the pseudo device. You can then point agetty at the /dev/pts/[0] device instead of a /dev/ttyS[n] device. Some ideas on doing this can be found in many tutorials online. From the link:
A pseudo-terminal is a pair of character mode devices also called pty. One is master and the other is slave and they are connected with a bidirectional channel. Any data written on the slave side is forwarded to the output of the master side. Conversely, any data written on the master side is forwarded to the output of the slave.
I found another StackOverflow question that may also be of assistance. See this link. It could be adapted to suit your needs.

PCM voice data on serial port to sound device conversion in linux

I have a telephony modem which gives voice to my interfaced application via a serial USB ttyUSB0 in 16bit PCM 8000hz. I am able to capture this data and play with audacity. I want this port to be detected as a sound device in linux (I am on ubuntu). Is it possible? Are there any other options?
I'm guessing you are using a huawei 3G modem or something similar which gives ttyUSB1 for audio. Make sure you have the serial driver binded to it. Then simply pass the port itself as a "file" for input for any program of your choice.You need root access for that.You figured out the audio settings so it must be enough.I have voice calling working in UBUNTU 11.10 with Huawei. So let me know if i can help any further.
Ok, I see it's very old question but answers helped me to get a right direction so I decided to help others.
The one way to achieve (in addition to below) what are you are
looking for is to write dynamic kernel module.
Have it register as a sound device, and check that it has a GSM
module present (which module is it exactly can be recognized in
dmesg, lsmod, or output).
Then establish communication between user space representation as a
sound card and serial usb module.
The other way is to get module that you recognized by dmesg, lsmod and extend its functionality as a sound card.
All are tricky tasks because:
in the first case you have to resolve intermodule communication at the kernel level...... which is, lets say, a little hard even if programmer has a right background in subject.
the second case is hard in that you have to deal with:
USB stack (which is little unpleasant for human beings) and
sound subsystem (which is a little burdensome because of historical issues).
Without being an experienced kernel programmer there are small chances to succeed.

LabVIEW string output

How do I send a string output from a DAQ Board (NI- USB 6259) using LabVIEW? I want to send commands such as "CELL 0" or "READ" to a potentiostat device using LabVIEW.
Thanks
The 6259 doesn't do string output. It's a data acquisition board that's intended for reading/sourcing analog voltages or sending/receiving individual digital signals. It's not a communications device.
If you're really trying to send strings to this device, you probably need something more like an RS-232 or GPIB connection.
As eaolson said a DAQ is not intended to control devices. However it is an interesting project to enter the guts of the communication protocol. Doing it with a DAQ would require to:
Identify the protocol (GPIB or RS-232)
Make your cable from the DAQ output connector
For each command, generate the waveform in LabVIEW, by using the letters' ASCII code, stop bits, etc. This is the funniest part (INMHO, but I understand it's not everybody!)
Send it (using DAQ analog write VIs, you should find many examples for this)
The oscilloscope will be your best friend

How do I read events from a HID device under Ubuntu Jaunty?

I have a Linux USB HID device (a Hama MCE), and I can read its events manually by reading cat /dev/input/event7 and cat /dev/input/event8. Whenever I press a key on the device, a few bytes become available for reading with one of the cat commands above. I have a default installation of Ubuntu Jaunty 64-bit desktop on the machine.
I think I can write a parser to interpret the bytes emitted by the device, or I'll use libhid if it's more convenient.
My questions are:
How do I prevent the text-mode virtual consoles from receiving some of the key presses on the device as normal keypresses? As of now, some device keys result an Enter, a BackSpace, a PageUp or numeric keypad numbers.
Similarly, how do I prevent the X server from receiving keyboard and mouse events from this device? I have several USB keyboards and mice connected to the computer. I want the X server receive events from all of them, except for this device.
How do I set up that whenever the device gets connected to the computer, the command /usr/local/bin/keydumper /dev/input/event7 /dev/input/event8 (or one command for each /dev/ path) would get run, with the proper /dev/ paths substituted in the command line?
Answering my own question based on answers from the Linux USB HID driver developers:
Question 1. and 2.: Do
ioctl(open("/dev/input/event7", O_RDONLY), EVIOCGRAB, 1);
As long as this filehandle is open, the events generated would go only
to this filehandle (not to other open()s of the same device or to the
system keyboard or mouse event pool). At most one process can hold a
successful EVIOCGRAB at a HID device at a time. Lirc can be configured
to do an EVIOCGRAB.
Question 3.: Configure udev to start the program once the device is connected.
I do not have enough points to comment sadly.
If you are looking for the definition of EVIOCGRAB try
#include <linux/input.h>
I think solution for all questions can be writing own filter device driver, or custom driver for your device. I know such a thing (filter device driver) is available on windows so something similar can be on Linux. In that filter device driver you could block all unwanted events from the target device that you wish to block, I don't really get 3 question so I don't know how to answer for that.

Resources