reading input from a specific device python - python

If i have two keyboards (default keyboard and an RFID reader) in my Linux machine
Using python how can I know from which device the input is coming from ?
I can read my input using the
input()
but i need to distinguish between the two devices

I'm assuming the RFID reader works on USB, if that's the case, should be treated like an input device as well as the HID Keybord (I'm assuming HID by your default).
I'm using evdev in python to do something similar for myself.
You can find the documentation here: http://python-evdev.readthedocs.io/en/latest/tutorial.html#reading-events
It has lots of simple and useful examples, like identify and read from multiple devices asynchronously.
I found it very easy to use.

Related

How can one read barcode from a barcode scanner using python

I am in need of library that can read barcodes from usb connected barcode scanners. I have done my research but there happens to be one barcode api which was recommended which is https://github.com/libusb/hidapi hidapi but it happens to be written in C++ and I do not know how to use it.
Any suggestion of alternatives to read barcodes from usb barcode scanners will be very well appreciated.
Many barcode scanners will hook into a PC as if it were a keyboard, and send through the text string as keyboard input when a barcode is scanned.
That would require no specialist library, as just monitoring keyboard input would be sufficient.
Looking through the specifications of your specific "datalogic gryphon" barcode scanner, it seems like there are some variants and drivers that allow this "Keyboard Interface".
If this is not working for your device, you can use the "COM-serial" or "RS-232" interfaces as input to your PC, and then use a library like pyserial to read in the input of that stream.
TL;DR: This is a driver issue, you can probably get an easy keyboard-like input if you contact the manufacturer of your device. Otherwise PySerial is the library you are probably looking for.
Connecting barcode scanners as keyboards can be problematic (security issues) or unrefined (scanning barcodes into incorrect fields). Here's a Python library that purports to bring barcodes in directly.
https://github.com/vpatron/barcode_scanner_python

Using Multiple Input Devices in Python Audio Processing (Pyo)

TLDR: Is there a way to mix multiple input devices' audio streams in real-time in Python (ideally with Pyo)?
I'm trying to use Pyo to combine audio streams from multiple microphones (or virtual microphones, e.g., Loopback devices) into one output audio stream. I've tried using pyo.Input, but it seems to have a core limitation: in Input(x), x seems to refer to a channel, not an input device. The input device seems to be constrained by the server: for s = pyo.Server(duplex=1), s.setInputDevice(someDeviceIndex) seems to be the only way to choose which input device will be used, with x then referring to a channel of that device (e.g., for a stereo microphone).
I have not seen any information in Pyo's docs (or in what I've read about other libraries) about how to mix multiple input devices together. pyo.Mixer seems promising, but examples given in the docs don't demonstrate how to use multiple Inputs, just other sound sources (e.g., a sine wave).
Is there any way that I can access multiple input devices within the scope of one Server and mix them together? If Pyo is not a good option for this task, what other libraries (and/or vanilla Python) might be a good fit?
Resolved on the Pyo forums at this link.

How to read a tag from PN532 in Python?

I want to experiment with the PN532 that comes connected with an arduino UNO. I have never touched anything similar, and in fact it took me quite a few tries to be able to play with LEDs on another arduino board I have.
Can someone provide me with a concrete example of reading data from the pn532 when I use a tag or card on it in Python?
Take a look at https://github.com/HubCityLabs/py532lib. The standard library is in C, somebody wrote a Python wrapper for the C library that you can use.
I did found a way that might be partially correct. Since Eugenes' answer does not provide a definitive way that we know will work, it cannot be considered a full answer so I will most probably accept this one if nothing else changes.
First of all since the PN532 does not continuously monitor for signals and emits data, we will have to program it the usual way in order for it to behave according to what we want to achieve.
This can be done using the same software that you program any other Arduino device.
Make sure you have chosen the correct port from the tools menu. If you don't know which port is that, in windows go to Start>All Programs>Accessories>System Tools>System Information>Components>Ports>Serial. For Linux going to /dev/serial/by-id should do.
Then I would recommend using the examples provided by the manufacturer here. Make sure you choose the right connection type or else you will see no data coming from the device (Most probably you will want I2C).
Once that is done, and your device emits data each time a tag is used on it (check with a serial terminal configured at 115200 Baud rate) then you are ready to start working with python.
Again I recommend this module to read your data from the serial port. It even comes with a ready to use example of a wxWidgets terminal to read your data from the PN532. If of curse you use another python library and you think its better do say so in the comments.

Vim (macvim): Alternately read input from keyboard and external program

I've got a python program that reads input from a midi device and produces text output derived from the incoming MIDI messages. As a simple example, let's say that it's simply mapping MIDI Note On events to note names e.g. note_on(60) --> 'C'. I'd like to capture the output in real time to a GVIM (actually MacVim) window without losing the ability to edit the output with a computer keyboard, i.e. I need for MacVim to read from both an external program and from the computer keyboard.
What's the cleanest general way to implement that under the assumption that the MIDI reader will never generate output while I'm trying to type and vice-versa? I'd prefer to be able to give the python script a filename and have it start MacVim with that file open, but doing it with shell commands or connecting from within MacVim would also be acceptable.
Based on the answers to How do I read and write repeatedly from a process in vim?, it looks like vim does not easily support 2 input sources asynchronously. I'll leave the question open in case someone happens to know an elegant solution, but for now it seems like the best approach is have my python program write to a normal file, use 'tail -f' for real-time viewing, and edit afterwards.

Finding usb gps in cross platform python

I'm working on a python app that's reading from a gps usb dongle. This far everything has been running in ubuntu/debian based systems where I communicated with the gps in a rather blunt way of scanning all of /dev/ttyUSB0-9 with pySerial for something speaking NMEA sentences on 38400 baud. Now I have been asked to get this app working cross platform and I'm a bit confused on which would be the best way of finding the gps dongle.
I have considered something along the lines of:
if os.name == "posix":
  self.conn = serial.Serial("/dev/ttyUSB%i" % usb)
elif os.name == "nt":
...
But I would rather have a single solution that works cross platform. Does anyone know of such a solution?
You could use the comports function from the scanwin32.py module provided in the pySerial documentation to figure out which COM ports are available, and then, using the returned informations about the open ports, find which one is your GPS dongle.
Edit: The documentation also provides a scan.py module which contains only a very simple function that probes each 256 ports to find which ones are open, maybe it would be sufficient for what you need.
I would guess that in the long run you may have more use of a cross platform anyway so go for why not stay with it?

Categories

Resources