-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
import and attribute errors Mac OS Mojave 10.14.6 Python 3.7.4 #4
Comments
Unfortunately, the way usb-ser-mon is coded it relies on udev, which is only available under linux. In order to determine which /dev/ttys your barcode scanner is connected to, try using this utility: Run it with the -l option. It only uses python serial port and no depdendencies on udev. I designed it to be run from within shell scripts for find serial ports. It can search based on vendor name, PID, VID, and serial number. |
I tried running the find_port.py script, but firstly I had to comment out the sys.exit(1) line near the bottom as Python was not liking it. I was reading the docs here, but I could see why that wouldn't work. Anyway, I ran your script and it failed to detect my scanner on the ttys* port. I can use pyusb along with libusb1 as the backend and it sees the device connected, but it does not tell me which ttys* port it is connected to, which I find strange. Here's the code I am using with pyusb:
This is the output when I run the above code:
This would be all I need if only it would show the ttys* port it is reading this information from. Would the ttys* port be one of the 0x** codes above? Thank you for your response and help. |
It looks like your scanner is presenting itself as a HID device and not a USB Serial device (which is why it's not showing up with a tty. If it was showing up as a tty then you should be able to do
On my Mac I see something like this with a usb serail device plugged in:
Notice the /dev/tty.usbserial-1440 on the far right (you'll probably need to scroll the display). If I run your little python program then I see (The Digi dongle is using an FTDI USB-to-serial chip)
|
When my barcode scanner is plugged in, it comes up as ttys002 most of the time. It could change from that to ttys003 or another number at times, or if I plug it into my macbook it can be different. So that is why I am trying to figure out how to identify which /dev/ device it is being represented as. Is there a way to poll HID devices since it is presenting itself as an HID device? When I first got the scanner and plugged it in Mac OS recognized it as a keyboard and wanted me to hold down the shift key. I just canceled that setup process. The scanner works, but I have to ensure my input field has focus, or it won't capture the barcode when I scan it. I would like to trap the code without having to have the input field having focus. But, for now, I can live with it until I need to do something. I have a thread set up to continuously read the /dev/ttys002 port, but it doesn't capture anything when a barcode is scanned. Here's my thread function:
But this code would only work if I knew for certain the /dev/ttys002 was correct. Again, thanks for your help. |
Since its acting like a keyboard, then it makes sense that its coming up as a HID device. I know under linux there are "input" drivers and you can setup your code to read from each individual input device (keyboard, mouse, etc), but I'm not that familiar with the Mac, so I'm not sure. |
So went digging a little more with the HID info, and I found pyhid and libusb/hidapi. I installed it and I can see the device using their code:
Which results in a bunch of information, but here's the relevant entry for the barcode scanner:
Still doesn't give me the /dev/ttys path that it is. This time when I plugged it in, it is coming up as /dev/ttys003, I think. As you can see from the directory listing, ttys001 through ttys003 are all active at nearly the same time.
|
It looks like the /dev/ttysXXX are psuedo tty's. If you open a terminal window and type the |
The command |
I suspect that if you knew the tty for the terminal that launched your "reader" process and that terminal had focus then it would get the characters from the scanner. But as soon as you change the focus away, it will stop receiving the scanner data. |
I installed your package via pip and upon running I get this error:
Traceback (most recent call last):
File "/Users/carroll/.vscode/extensions/ms-python.python-2019.8.30787/pythonFiles/ptvsd_launcher.py", line 43, in
main(ptvsdArgs)
File "/Users/carroll/.vscode/extensions/ms-python.python-2019.8.30787/pythonFiles/lib/python/ptvsd/main.py", line 432, in main
run()
File "/Users/carroll/.vscode/extensions/ms-python.python-2019.8.30787/pythonFiles/lib/python/ptvsd/main.py", line 316, in run_file
runpy.run_path(target, run_name='main')
File "/Users/carroll/.pyenv/versions/3.7.4/lib/python3.7/runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "/Users/carroll/.pyenv/versions/3.7.4/lib/python3.7/runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "/Users/carroll/.pyenv/versions/3.7.4/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/Users/Shared/toms-music-bingo/test-tty.py", line 145, in
main()
File "/Users/Shared/toms-music-bingo/test-tty.py", line 136, in main
context = pyudev.Context()
File "/Users/carroll/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pyudev/core.py", line 64, in init
self._libudev = load_ctypes_library('udev', SIGNATURES, ERROR_CHECKERS)
File "/Users/carroll/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pyudev/_ctypeslib/utils.py", line 56, in load_ctypes_library
raise ImportError('No library named %s' % name)
ImportError: No library named udev
Exception ignored in: <function Context.del at 0x106b8e4d0>
Traceback (most recent call last):
File "/Users/carroll/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pyudev/core.py", line 68, in del
self._libudev.udev_unref(self)
AttributeError: 'Context' object has no attribute '_libudev'
I am on Mac OS Mojave 10.14.6 using Python version 3.7.4. All I am trying to do is determine which /dev/ttys my barcode/qr code scanner is connected to.
Thank you!
The text was updated successfully, but these errors were encountered: