trezor / cython-hidapi Goto Github PK
View Code? Open in Web Editor NEW:snake: Python wrapper for the HIDAPI
License: Other
:snake: Python wrapper for the HIDAPI
License: Other
As I am developing an android app in python and it needs to use hidapi support so is this possible to build it for android?
as I saw there is no build process for android platform in setup.py
Hello,
my suggestion is to make libusb optional (hidraw provides the same functionality, right?)
I can provide pull request for this feature, but like to get approval and discuss implementation details.
Some python packages provide optional features while installing (a list of packages can be extracted from [1]). It's common practice to add --with-feature or --without-feature options for 'python setup.py install' command.
I suggest adding '--without-libusb' for linux that would disable libusb as hard requirement and build only hidraw module.
The exact implementation of parsing '--without..' can be taken from setup.py of pylibmc package [2].
[1] -- pypa/pip#271
[2] -- https://github.com/lericson/pylibmc/blob/master/setup.py
Hello,
Now that Python 3.7 is out it is required to build this module during a pip install which requires a compiler on Windows. Can you update appveyor to create binaries for Windows x86/64 for Python 3.7?
Thanks!
h.open(0x534c, 1)
works fine.
h.open(0x534c, 1, '1B410A403BB99B3DF58D0125')
produces Segmentation fault.
There is probably a bug in conversion from python string to widechar.
I am using the hidapi on a raspberry pi 3 with raspian buster. I installed all dependecies correctly, i installed the pypi package, then i tried to build it myself. So far i built it without options, with the "--without-libusb" option and with the "--without-libusb" and the "with-system-hidapi" oprions together.
Everything i tried worked without errors, but i never got any output from hid.enumerate.
Also, i added a udev rule for my connected devices:
SUBSYSTEM=="usb", ATTR{idVendor}=="04d8", ATTR{idProduct}=="9018", MODE="0660", GROUP="plugdev", TAG+="uaccess", TAG+="udev-acl", SYMLINK+="snap%n"
KERNEL=="hidraw*", ATTRS{idVendor}=="04d8", ATTRS{idProduct}=="9018", MODE="0660", GROUP="plugdev", TAG+="uaccess", TAG+="udev-acl"
I dont know if i did this correct, but the symlink shows up.
I would like to know if i did something wrong, or if its a bug.
Thanks in advance
Hi,
I'd like to make a release of cython-hidapi for gentoo, are you planning to create a release since you forked ?
Thanks
Hello,
While using cython-hidapi on an embedded device, I came across a build issue. The setup.py contains hardcoded additions to the include path such as /usr/include/libusb-1.0
and /usr/include/hidapi
. This, as it should, caused build errors since host x86 libraries were being used when the target device is armv7.
My temporary fix for this was to remove all extra include paths from setup.py, update chid.pyx to include "hidapi/hidapi.h"
instead of just "hidapi.h"
, and build with --with-system-hidapi. Works great. However, it breaks normal build (also building hidapi) as that whole submodule requires those include paths to build.
I'm not certain why building hidapi is necessary instead of just requiring it to be installed (it's on every major and minor distro and build system), is it something to do with cython? If possible, I suggest getting rid of the submodule altogether and updating required dependencies. Either way, I've made a fork and am looking to upstream this.
Mark
I had some code which used to work under Windows 7/8/8.1 and got a failed open_path under Windows 10. Had to make share_mode = FILE_SHARE_READ|FILE_SHARE_WRITE for both the enumerate case and the not enumerate case to get through. (Of course this is not the fix I don't know the most correct flags to pass.)
Hello,
I'm successfully able to read data from the built in trackpad and a bluetooth mouse.
However, setting device.set_unblocking(1)
makes no effects while reading. For both devices the cursor doesn't move until the devices are closed.
Has someone any suggestion?
Hello, I've got some problems in accessing hidraw device from cython-hidapi library on Raspberry Pi.
I've set up permissions in /etc/udev/rules.d
, so I get rw-
permissions on connection:
(system3) pi@raspberrypi:~ $ ls -l /dev/h*
crw-rw-rw- 1 root plugdev 248, 0 Feb 18 11:41 /dev/hidraw0
crw------- 1 root root 10, 183 Feb 18 01:17 /dev/hwrng
The device is visible in hid.enumerate()
:
(system3) pi@raspberrypi:~ $ python -c "import hid; print(hid.enumerate())"
[{'product_id': 41042, 'usage_page': 0, 'interface_number': 0, 'product_string': '', 'serial_number': '', 'vendor_id': 1241, 'manufacturer_string': '', 'path': b'0001:0005:00', 'usage': 0, 'release_number': 256}]
But when I try to open it, I get OSError
:
(system3) pi@raspberrypi:~ $ python -c "import hid; h = hid.device(); h.open(0x04d9, 0xa052)"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "hid.pyx", line 66, in hid.device.open
OSError: open failed
I tried both builds; with and without libusb
and neither worked..
At the same time I can read straight from the /dev/hidraw0
(in python as well) - and it works fine. And the same device on osx works fine with cython-hidapi
.
I would appreciate any suggestion!
The same code I use to send a feature report on Mac OS and Windows just doesn't work on Linux.
Specifiaclly
buf = [0x0, 0x80, 0x25, 0x00, 0x00, 0x03]
res = self.hid_device.send_feature_report(buf);
returns a +ve integer on Windows and OSX but -1 on Ubuntu 14.04. My guess is that somehow the map and join with chr in the method itself gives a wrong result, but i don't really understand this level of programming.
Indeed running from an interactive python shell prints some weird characters to the console, but these are different from the equally weird characters that are printed on other OS.
>>> buf = [0x0, 128, 0x25, 0x00, 0x00, 0x03]
>>> buff = ''.join(map(chr, buf))
>>> print buff
�%�
Not too sure if this is an issue in cython-hidapi
or in hidapi
directly, so apologies in advanced for the noise.
I am running Python 2.7, hidapi==0.7.99.post21
, and OSX High Sierra (v10.13.4).
When using hid.enumerate()
inside a daemon process the following error occurs:
The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().
Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.
The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().
Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.
The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().
Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.
The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().
Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.
The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().
Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.
The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().
Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.
The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().
Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.
The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().
Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.
The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().
Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.
The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().
Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.
The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().
Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.
The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().
Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.
The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().
Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.
The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().
Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.
The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().
Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.
The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().
Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.
The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().
Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.
The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().
Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.
The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().
Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.
I am wondering if cython-hidapi is thread safe, according to the information I have found the signal11 hidapi is on OSX, and if cython-hidapi is thread safe, what the problem could be caused by?
I got this issue while building
running install
running build
running build_ext
skipping 'hid.c' Cython extension (up-to-date)
building 'hid' extension
/usr/bin/ccache arm-linux-androideabi-gcc -DANDROID -fomit-frame-pointer -D__ANDROID_API__=21 -mandroid -isystem /home/cis/.buildozer/android/platform/android-ndk-r17c/sysroot/usr/include/arm-linux-androideabi -I/home/cis/.buildozer/android/platform/android-ndk-r17c/sysroot/usr/include/arm-linux-androideabi -isysroot /home/cis/.buildozer/android/platform/android-ndk-r17c/sysroot -I/home/cis/trezortry/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/testapp11/include/python3.7 -DNDEBUG -g -fwrapv -O3 -Wall -DANDROID -fomit-frame-pointer -D__ANDROID_API__=21 -mandroid -isystem /home/cis/.buildozer/android/platform/android-ndk-r17c/sysroot/usr/include/arm-linux-androideabi -I/home/cis/.buildozer/android/platform/android-ndk-r17c/sysroot/usr/include/arm-linux-androideabi -isysroot /home/cis/.buildozer/android/platform/android-ndk-r17c/sysroot -I/home/cis/trezortry/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/testapp11/include/python3.7 -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -mthumb -I/home/cis/trezortry/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/python3-libffi-openssl-sqlite3/armeabi-v7a__ndk_target_21/python3/Include -fPIC -Ihidapi/hidapi -I/usr/include/libusb-1.0 -I/home/cis/trezortry/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/Include -I/home/cis/trezortry/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build -c hid.c -o build/temp.linux-x86_64-3.7/hid.o
hid.c:569:20: fatal error: hidapi.h: No such file or directory
#include "hidapi.h"
^
compilation terminated.
error: command '/usr/bin/ccache' failed with exit status 1
Operating System: OsX
Behavior:
Expected Behavior: a connection to be opened to any HID device in hid.enumerate()
reproduction:
>>> import hid
>>> hid.enumerate() // several HID devices listed
>>> h = hid.device()
>>> h.open(1452, 544) // apple USB keyboard -- works
>>> h.close()
>>> h.open(1452, 569) // apple bluetooth keyboard -- OSError: open failed
I assumed from Apple's bluetooth docs that bluetooth HID access would work the same as USB.
Any thoughts? It's my first attempt at using the library, so I may be doing something wrong.
Cheers
I'm in the process of packaging your library for debian. Now there came up an issue with the license. It is short and simple, and the intention seems clear, but there might be some ambiguities. As debian is very strict with licenses, it would be helpful, if you could adopt one of the standard licenses. The Expat / MIT license would probably be the closest to what you currently have.
I logged the issue also against the original at : gbishop/cython-hidapi#19. But you would both have to agree to a license change.
Hello, I am just curious, how can I identify multiple devices with the same product and vendor ID using your API?
For example here in get_serial_number_string
:
cdef int r = hid_get_serial_number_string(self._c_hid, buff, 255)
if not r:
return U(buff)
method should raise IOError
in else-branch. According to hidapi docs function hid_get_serial_number_string
returns -1
if error occurs.
I'm working with a Fitbit dongle, which exposes two HID endpoints (one for control, one for data). The information from hid.enumerate(VID,PID) doesn't give any way to distinguish between the two devices:
In [4]: hid.enumerate(VID, PID)
Out[4]:
[{'interface_number': -1,
'manufacturer_string': u'Fitbit Inc.',
'path': 'USB_2687_fb01_14500000',
'product_id': 64257,
'product_string': u'Fitbit Base Station',
'release_number': 256,
'serial_number': u'\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff',
'usage': 1,
'usage_page': 65290,
'vendor_id': 9863},
{'interface_number': -1,
'manufacturer_string': u'Fitbit Inc.',
'path': 'USB_2687_fb01_14500000',
'product_id': 64257,
'product_string': u'Fitbit Base Station',
'release_number': 256,
'serial_number': u'\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff',
'usage': 1,
'usage_page': 65290,
'vendor_id': 9863}]
So using dev.open(vid, pid)
or dev.open_path(path)
doesn't give me any way to open the second device, since the information is identical.
Is there any way to do this?
Hi Pavol,
When I call open() twice on the same hid.device() object, I get an IOError. So I always pair up the open() and close() calls. However, during the long-running reading process, if an error (for whichever reason) occurs, I might lose the reference to the original object hid.device(). If this happens, I have no way of closing the device again, and each new call to open() will result in a IOError. Here is the code to reproduce the mentioned behavior:
import hid
h = hid.device()
h.open(vid, pid)
h.close() # everything works fine
h.open(vid, pid)
h = hid.device() # lose the reference to the opened device
h.close() #doesn't close the device and I have no way of getting the handle to the USB buffer again
h.open(vid, pid) # results in a IOError
h.read(5) # crashes python.exe
So, I was wondering, is this the expected behavior, and should I implement the higher-level logic to handle this (which could be complicated, because of multiple processes communicating), or could the additional protection be implemented?
Thanks for your time,
Best,
Slobodan
I succeeded in the Mac OS and winodws, but I couldn't send and receive hid data when I was in raspberry pie.
How do I debug it?
Now that AppVeyor support is working, it would be great if the resulting builds were uploaded to PyPi.
Not sure if I'm missing anything but the install isn't working for me.
System Software Overview:
System Version: macOS 10.14.6 (18G95)
Kernel Version: Darwin 18.7.0
pip3 install hidapi
Collecting hidapi
Using cached https://files.pythonhosted.org/packages/c1/86/89df0e8890f96eeb5fb68d4ccb14cb38e2c2d2cfd7601ba972206acd9015/hidapi-0.7.99.post21.tar.gz
Requirement already satisfied: setuptools>=19.0 in /usr/local/lib/python3.7/site-packages (from hidapi) (41.4.0)
Building wheels for collected packages: hidapi
Building wheel for hidapi (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: /usr/local/opt/python/bin/python3.7 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/mp/lg0kjf_d4gbb2y4rfhxcgkyc0000gn/T/pip-install-1pifnjif/hidapi/setup.py'"'"'; __file__='"'"'/private/var/folders/mp/lg0kjf_d4gbb2y4rfhxcgkyc0000gn/T/pip-install-1pifnjif/hidapi/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /private/var/folders/mp/lg0kjf_d4gbb2y4rfhxcgkyc0000gn/T/pip-wheel-6yi7mcmk --python-tag cp37
cwd: /private/var/folders/mp/lg0kjf_d4gbb2y4rfhxcgkyc0000gn/T/pip-install-1pifnjif/hidapi/
Complete output (23 lines):
running bdist_wheel
running build
running build_ext
cythoning hid.pyx to hid.c
/private/var/folders/mp/lg0kjf_d4gbb2y4rfhxcgkyc0000gn/T/pip-install-1pifnjif/hidapi/.eggs/Cython-0.29.13-py3.7-macosx-10.14-x86_64.egg/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /private/var/folders/mp/lg0kjf_d4gbb2y4rfhxcgkyc0000gn/T/pip-install-1pifnjif/hidapi/hid.pyx
tree = Parsing.p_module(s, pxd, full_module_name)
building 'hid' extension
creating build
creating build/temp.macosx-10.14-x86_64-3.7
creating build/temp.macosx-10.14-x86_64-3.7/hidapi
creating build/temp.macosx-10.14-x86_64-3.7/hidapi/mac
Compiling with an SDK that doesn't seem to exist: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk
Please check your Xcode installation
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -framework IOKit -framework CoreFoundation -Ihidapi/hidapi -I/usr/local/include -I/usr/local/opt/[email protected]/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c hid.c -o build/temp.macosx-10.14-x86_64-3.7/hid.o
clang: warning: -framework IOKit: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: -framework CoreFoundation: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: no such sysroot directory: '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk' [-Wmissing-sysroot]
In file included from hid.c:4:
/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/include/python3.7m/Python.h:25:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
^~~~~~~~~
1 error generated.
error: command 'clang' failed with exit status 1
----------------------------------------
ERROR: Failed building wheel for hidapi
Hi,
The version on PyPi (including the wheels) appears pretty old, from 23 Oct 2017. I see that several updates to cython-hidapi
have been made since then (including to using libusb/hidapi, thank you! It has even more bug fixes now)
Can I help produce an updated release to PyPi?
Currently there's no way of determining (as far as I can tell) the version of the cython-hidapi installed programatically.
Python 3.6.9
Linux pinebook 4.19.63-sunxi64 #5.92 SMP Fri Aug 2 00:18:27 CEST 2019 aarch64 aarch64 aarch64 GNU/Linux
This is after running pip3 install --upgrade --user setuptools
and pip3 install --upgrade --user wheel
.
Build & installation works if I use python2... but I need python3 for this.
cython-hidapi$ python3 setup.py install --user
ERROR: Failed to build one or more wheels
Traceback (most recent call last):
File "/home/cel/.local/lib/python3.6/site-packages/setuptools/installer.py", line 128, in fetch_build_egg
subprocess.check_call(cmd)
File "/usr/lib/python3.6/subprocess.py", line 311, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/usr/bin/python3', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', '/tmp/tmp_0v6lho6', '--quiet', 'Cython']' returned non-zero exit status 1.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "setup.py", line 128, in <module>
install_requires = ['setuptools>=19.0'],
File "/home/cel/.local/lib/python3.6/site-packages/setuptools/__init__.py", line 144, in setup
_install_setup_requires(attrs)
File "/home/cel/.local/lib/python3.6/site-packages/setuptools/__init__.py", line 139, in _install_setup_requires
dist.fetch_build_eggs(dist.setup_requires)
File "/home/cel/.local/lib/python3.6/site-packages/setuptools/dist.py", line 721, in fetch_build_eggs
replace_conflicting=True,
File "/home/cel/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 782, in resolve
replace_conflicting=replace_conflicting
File "/home/cel/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 1065, in best_match
return self.obtain(req, installer)
File "/home/cel/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 1077, in obtain
return installer(requirement)
File "/home/cel/.local/lib/python3.6/site-packages/setuptools/dist.py", line 777, in fetch_build_egg
return fetch_build_egg(self, req)
File "/home/cel/.local/lib/python3.6/site-packages/setuptools/installer.py", line 130, in fetch_build_egg
raise DistutilsError(str(e))
distutils.errors.DistutilsError: Command '['/usr/bin/python3', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', '/tmp/tmp_0v6lho6', '--quiet', 'Cython']' returned non-zero exit status 1.
$ pip2.7 install --user hidapi
You are using pip version 7.1.0, however version 7.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting hidapi
Using cached hidapi-0.7.99.post8.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 20, in <module>
File "/tmp/pip-build-zHt5mZ/hidapi/setup.py", line 79, in <module>
ext_modules = modules,
NameError: name 'modules' is not defined
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-zHt5mZ/hidapi
Looking at the code, I can immediately see why:
if sys.platform.startswith('linux'):
...
if sys.platform.startswith('darwin'):
...
if sys.platform.startswith('win'):
...
ext_modules = modules,
On OpenBSD 5 sys.platform
is openbsd5
, therefore modules
never gets defined.
I'm not sure what the correct dependencies would be for OpenBSD, but maybe similar to linux, albeit without udev.
Thanks
I am working on a script to read a serial number off of an attached USB-HID device, which is a magnetic stripe reader. The script uses the feature report API methods send_feature_report
and get_feature_report
. When I run it on macOS High Sierra, 10.13.6, it works. But I tried to run the same script on a machine running Ubuntu 16.04, it does not work. Can you suggest how to debug this further?
I am only using 0 for the feature report number. So the list I am transmitting is:
[0], [2], [82], [78], [3], [29]
. I get a response from send_feature_report of 6, which is what I expect since there are 6 bytes in the packet.
When I try to read, using a request of get_feature_report(0, 8)
, I receive a response of [0]. Based on what I can see in the hid.pyx implementation, this is just the interface returning the feature report I requested.
I saw the issue described here and tried the suggestion, but it did not help. It also does not seem to line up with the API described in hidapi hid.h. I tried this both replacing the first byte (where the feature report number goes) and also placing it after the feature report number (in feature_report[1]). When I replace the feature report number, I get a response code of -1 from the API call. Otherwise, the output looks the same.
I have tried adjusting the delay setting (working off of the example in try.py) and there seems to be a window of time where the device does not respond at all, something less than 2 seconds between calling send
and get
The udev rules currently allow me to receive input from the device in the form of general HID Interrupt messages. Here is the text of the rules file I have:
ACTION=="add",ATTRS{idVendor}=="0acd",ATTRS{idProduct}== "2810",GROUP="plugdev"
ATTRS{idVendor}=="0acd",ATTRS{idProduct}=="2810",GROUP="plugdev"
ACTION=="add",SUBSYSTEM=="usb",ATTRS{idVendor}=="0acd",ATTRS{idProduct}== "2810",SYMLINK+="securemsr",GROUP="plugdev"
Thanks!
I've been trying to install cython-hidapi on Windows within cygwin, and ran into the following error:
$ pip install hidapi
Collecting hidapi
Using cached hidapi-0.7.99.post17.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 1, in
File "/tmp/pip-build-W1qbyY/hidapi/setup.py", line 86, in
ext_modules = modules,
NameError: name 'modules' is not defined
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-W1qbyY/hidapi/
It looks like the cause is that the sys.platform selection logic in setup.py doesn't account for Cygwin's sys.platform string being "cygwin".
Replacing line 44 with the following seems to work around the issue (if, indeed, a cygwin install should be treated the same as Windows), though I haven't been successful with having it actually detect a device yet:
if sys.platform.startswith('win') or sys.platform.startswith('cygwin'):
Just updated to macOS Catalina 10.15 and when installing hidapi I get the error below.
looks like this is the root of the error:
Compiling with an SDK that doesn't seem to exist: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk
Maybe there's a hard coded path somewhere?
Here's the full error:
pip install hidapi
Collecting hidapi
Using cached https://files.pythonhosted.org/packages/c1/86/89df0e8890f96eeb5fb68d4ccb14cb38e2c2d2cfd7601ba972206acd9015/hidapi-0.7.99.post21.tar.gz
Requirement already satisfied: setuptools>=19.0 in ./venv_37_1/lib/python3.7/site-packages (from hidapi) (41.4.0)
Installing collected packages: hidapi
Running setup.py install for hidapi ... error
ERROR: Command errored out with exit status 1:
command: /Users/joao/springlabs/git/spring-platform/venv_37_1/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/vg/pgz7_t6d2qn8n4w6tgkvshxh0000gp/T/pip-install-klax_zsu/hidapi/setup.py'"'"'; __file__='"'"'/private/var/folders/vg/pgz7_t6d2qn8n4w6tgkvshxh0000gp/T/pip-install-klax_zsu/hidapi/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/vg/pgz7_t6d2qn8n4w6tgkvshxh0000gp/T/pip-record-m03b6b9a/install-record.txt --single-version-externally-managed --compile --install-headers /Users/joao/springlabs/git/spring-platform/venv_37_1/include/site/python3.7/hidapi
cwd: /private/var/folders/vg/pgz7_t6d2qn8n4w6tgkvshxh0000gp/T/pip-install-klax_zsu/hidapi/
Complete output (23 lines):
running install
running build
running build_ext
cythoning hid.pyx to hid.c
/private/var/folders/vg/pgz7_t6d2qn8n4w6tgkvshxh0000gp/T/pip-install-klax_zsu/hidapi/.eggs/Cython-0.29.13-py3.7-macosx-10.14-x86_64.egg/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /private/var/folders/vg/pgz7_t6d2qn8n4w6tgkvshxh0000gp/T/pip-install-klax_zsu/hidapi/hid.pyx
tree = Parsing.p_module(s, pxd, full_module_name)
building 'hid' extension
creating build
creating build/temp.macosx-10.14-x86_64-3.7
creating build/temp.macosx-10.14-x86_64-3.7/hidapi
creating build/temp.macosx-10.14-x86_64-3.7/hidapi/mac
Compiling with an SDK that doesn't seem to exist: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk
Please check your Xcode installation
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -framework IOKit -framework CoreFoundation -I/usr/local/opt/openssl/include -Ihidapi/hidapi -I/usr/local/include -I/usr/local/opt/[email protected]/include -I/usr/local/opt/sqlite/include -I/Users/joao/springlabs/git/spring-platform/venv_37_1/include -I/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c hid.c -o build/temp.macosx-10.14-x86_64-3.7/hid.o
clang: warning: -framework IOKit: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: -framework CoreFoundation: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: no such sysroot directory: '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk' [-Wmissing-sysroot]
In file included from hid.c:4:
/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/include/python3.7m/Python.h:25:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
^~~~~~~~~
1 error generated.
error: command 'clang' failed with exit status 1
----------------------------------------
ERROR: Command errored out with exit status 1: /Users/joao/springlabs/git/spring-platform/venv_37_1/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/vg/pgz7_t6d2qn8n4w6tgkvshxh0000gp/T/pip-install-klax_zsu/hidapi/setup.py'"'"'; __file__='"'"'/private/var/folders/vg/pgz7_t6d2qn8n4w6tgkvshxh0000gp/T/pip-install-klax_zsu/hidapi/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/vg/pgz7_t6d2qn8n4w6tgkvshxh0000gp/T/pip-record-m03b6b9a/install-record.txt --single-version-externally-managed --compile --install-headers /Users/joao/springlabs/git/spring-platform/venv_37_1/include/site/python3.7/hidapi Check the logs for full command output.
Installed /Users/ag/projects/csc490-arm/cython-hidapi/.eggs/Cython-0.23.4-py2.7-macosx-10.10-x86_64.egg
/Users/ag/virtualenvs/csc490-arm/lib/python2.7/site-packages/setuptools/dist.py:285: UserWarning: Normalizing '0.7.99-8' to '0.7.99.post8'
normalized_version,
running build
running build_ext
building 'hid' extension
error: unknown file type '.pxd' (from 'chid.pxd')```
Hello,
I have an issue when I try to use hidapi to connect to an usb device.
The error is
File "test_raspberry_connected.py", line 2, in
import hid
File "usr/local/lib/python3.7/dist-packages/hid/init.py, line 30, in
raise ImportError(error)
ImportError: Unable to load any of the following libraries: libhidapi-hidraw.so libhidapi-hidraw.so.o ....... hidapi.dll libhidapi-0.dll
Avez vous une idée pour résoudre ce problème ?
Ce qui est étrange aussi c'est que toutes les autres librairies sont installées dans /usr/lib/python3 alors que hidapi est dans /usr/local/lib/python3.7/dist-packages, je ne sais pas si ça peut jouer.
Si quelqu'un peut m'aider à me débloquer ce serait vraiment top !
Clara
Hi!
I tried to compile python-hidapi on RPi. Notwithstanding some warnings, no real errors are thrown. However, when I connect a USB keyboard to the Pi and try to the try.py script, I get an error "open failed".
The listing from hid.enumerate() shows the keyboard with vendor_id 1452 and product_id 545, so I added 0x5AC and 0x221 as arguments in the try.py script.
Am I doing something wrong, or does this mean something is wrong with my install? I wanted to test with a keyboard first to ensure that cython-hidapi works on my Pi before acquiring the hardware I actually want to use.
Would you consider uploading also wheel archive to PyPI at least for some platforms? That would substantially simplify installation process on those platforms.
Running pip install hidapi
won't find mac/hid.c
I'm having trouble installing hidapi on a Raspberry Pi running raspbian - I get "error: unknown file type '.pyx' (from 'hid.pyx')". I was wondering whether this was anything to do with cython, and saw on an RPi-related closed issue that you recommended cython 0.22+. I've upgraded cython from 0.21.1 to 0.24.1 and the error is just the same afterwards. What else might the problem be?
I just did a pip install, so I have version 0.7.99-5
, running on Python 3.4.
$ python3
Python 3.4.2 (default, Oct 30 2014, 14:56:46)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.54)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import hid
>>> dev = hid.device(5824, 1158)
>>> dev.read(64)
Segmentation fault: 11
As I am creating an app in kivy python using buildozer a wrapper for python-for-android where a buildozer.spec file needs to be maintained and I simply wrote hidapi as requirement but it seems not working when says import hid
I'm having some issues that I suspect are my own fault. When I run python 2.7 and use import hid
manually, all is well. However, in my program, I am importing hid after a build, and the program throws an exception: dynamic module does not define init function (inithid)
. This code has worked before, and I'm trying to pin-point how to fix this problem.
I've tried pip install hidapi
and I've built successfully from source. Both work in the python cli, but not after I build. I'm working on https://github.com/openstenoproject/plover/blob/master/plover/machine/treal.py
I go through setuptools with py2app to create an .app
file, and that's where I run into the problem. It would appear that running without build doesn't have the same issue.
Any guidance would be much appreciated.
Hi Pavol,
I'm writing a driver for a HID device with multiple interfaces/endpoints. Below is
the output from lsusb -vv. Most of the reports are through the command interface, but there
are 3 interfaces with input reports and 1 interface with output reports. Using hidapi, is there
an easy way to claim these interfaces (something like libusb_claim_interface(udev, i)
and do a libusb_interrupt_transfer() to/from these endpoints?
Much thanks,
Warren
Bus 003 Device 003: ID 09db:00a1 Measurement Computing Corp.
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 64
idVendor 0x09db Measurement Computing Corp.
idProduct 0x00a1
bcdDevice 1.02
iManufacturer 1 MCC
iProduct 2 USB-1408FS
iSerial 3 01303B58
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 116
bNumInterfaces 4
bConfigurationValue 1
iConfiguration 4 Default
bmAttributes 0x80
(Bus Powered)
MaxPower 500mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 1
bInterfaceClass 3 Human Interface Device
bInterfaceSubClass 0 No Subclass
bInterfaceProtocol 0 None
iInterface 5 Interface 0
HID Device Descriptor:
bLength 9
bDescriptorType 33
bcdHID 1.10
bCountryCode 0 Not supported
bNumDescriptors 1
bDescriptorType 34 Report
wDescriptorLength 312
Report Descriptors:
** UNAVAILABLE **
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 1
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 1
bAlternateSetting 0
bNumEndpoints 2
bInterfaceClass 3 Human Interface Device
bInterfaceSubClass 0 No Subclass
bInterfaceProtocol 0 None
iInterface 6 Interface 1
HID Device Descriptor:
bLength 9
bDescriptorType 33
bcdHID 1.10
bCountryCode 0 Not supported
bNumDescriptors 1
bDescriptorType 34 Report
wDescriptorLength 29
Report Descriptors:
** UNAVAILABLE **
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x02 EP 2 OUT
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 1
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x83 EP 3 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 1
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 2
bAlternateSetting 0
bNumEndpoints 1
bInterfaceClass 3 Human Interface Device
bInterfaceSubClass 0 No Subclass
bInterfaceProtocol 0 None
iInterface 7 Interface 2
HID Device Descriptor:
bLength 9
bDescriptorType 33
bcdHID 1.10
bCountryCode 0 Not supported
bNumDescriptors 1
bDescriptorType 34 Report
wDescriptorLength 22
Report Descriptors:
** UNAVAILABLE **
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x84 EP 4 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 1
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 3
bAlternateSetting 0
bNumEndpoints 1
bInterfaceClass 3 Human Interface Device
bInterfaceSubClass 0 No Subclass
bInterfaceProtocol 0 None
iInterface 8 Interface 3
HID Device Descriptor:
bLength 9
bDescriptorType 33
bcdHID 1.10
bCountryCode 0 Not supported
bNumDescriptors 1
bDescriptorType 34 Report
wDescriptorLength 22
Report Descriptors:
** UNAVAILABLE **
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x85 EP 5 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 1
Device Status: 0x0000
(Bus Powered)
I think the problem is because I have multiple versions of Visual Studio installed, (2008 express, 2012 full). The problem could be solved if I compiled on a dedicated VM with only VS 2008
Stack trace:
C:\GitHub\cython-hidapi>python setup.py build
running build
running build_ext
skipping 'hid.c' Cython extension (up-to-date)
building 'hid' extension
Traceback (most recent call last):
File "setup.py", line 63, in
ext_modules = modules
File "C:\Python27\lib\distutils\core.py", line 152, in setup
dist.run_commands()
File "C:\Python27\lib\distutils\dist.py", line 953, in run_commands self.run_command(cmd)
File "C:\Python27\lib\distutils\dist.py", line 972, in run_command
cmd_obj.run()File "C:\Python27\lib\distutils\command\build.py", line 127, in run
self.run_command(cmd_name)File "C:\Python27\lib\distutils\cmd.py", line 326, in run_command
self.distribution.run_command(command)File "C:\Python27\lib\distutils\dist.py", line 972, in run_command
cmd_obj.run()File "C:\Python27\lib\site-packages\Cython\Distutils\build_ext.py", line 163, in run
_build_ext.build_ext.run(self)File "C:\Python27\lib\distutils\command\build_ext.py", line 340, in run self.build_extensions()
File "C:\Python27\lib\site-packages\Cython\Distutils\build_ext.py", line 171, in build_extensions
self.build_extension(ext)
File "C:\Python27\lib\distutils\command\build_ext.py", line 499, in build_exte nsion
depends=ext.depends)
File "C:\Python27\lib\distutils\msvc9compiler.py", line 473, in compile self.initialize()
File "C:\Python27\lib\distutils\msvc9compiler.py", line 383, in initialize vc_env = query_vcvarsall(VERSION, plat_spec)
File "C:\Python27\lib\distutils\msvc9compiler.py", line 299, in query_vcvarsal l
raise ValueError(str(list(result.keys())))
ValueError: [u'path']
The latest version of hidapi
doesn't provide binary builds for Windows: https://pypi.org/project/hidapi/0.7.99.post21/#files
This makes it a bit of a hassle to install it on Wine.
Just a heads up to anyone using this library on a Mac, you may hit this bug:
If you write, for example, 64 zero bytes, only 63 will be actually sent. A leading zero in any write will be removed, and the buffer shortened by one. You can work around by providing an extra leading zero in those cases.
Related: it would be nice to be able to know the version of the underlying hidapi
at runtime.
Hey there,
I'm trying to compile cython-hidapi on a raspberry pi (raspbian) and get the following error:
hid.pyx:14:46: Expected ')', found '*'
(that's the line that extern's from * the object
PyUnicode_FromWideChar( ... )
)
I have absolutely no experience with cython, so it escapes me why this is...
someone can clarify how i can adapt this code from pyusb to hidapi:
dev.ctrl_transfer(bmRequestType=0x21, bRequest=9, wValue=0x300, wIndex=1, data_or_wLength=(
0x12, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00))
Line 123 in 9227279
I don't see any related import in the code.
In setup.py Cython is imported before it has been installed, which causes the following exception:
C:\Russ\projects\github\cython-hidapi>pip install hidapi
Collecting hidapi
Using cached hidapi-0.7.99-6.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 20, in <module>
File "c:\users\russ\appdata\local\temp\pip-build-j6wqrh\hidapi\setup.p
y", line 4, in <module>
from Cython.Distutils import build_ext
ImportError: No module named Cython.Distutils
Installation will fail with:
Error compiling Cython file:
------------------------------------------------------------
...
import sys
from chid cimport *
^
------------------------------------------------------------
hid.pyx:2:0: 'chid.pxd' not found
``´
Hi there,
according to
IOKit.framework is located at "/System/Library/Frameworks/", but hidapi/mac/hid.c:hidapi_IOHIDDeviceGetService() tries to find it at "/System/Library/". That fails and at least on macOS 10.14 the fallback method seems to not working too, so that hid_enumerate() cannot determine a path. A subsequent call of hid_open() fails due to the empty path. The following patch fixes this issue for me:
--- a/hidapi/mac/hid.c
+++ b/hidapi/mac/hid.c
@@ -303,7 +303,7 @@ static io_service_t hidapi_IOHIDDeviceGe
* and the fallback method will be used.
*/
if (iokit_framework == NULL) {
- iokit_framework = dlopen("/System/Library/IOKit.framework/IOKit", RTLD_LAZY);
+ iokit_framework = dlopen("/System/Library/Frameworks/IOKit.framework/IOKit", RTLD_LAZY);
if (iokit_framework != NULL)
dynamic_IOHIDDeviceGetService = dlsym(iokit_framework, "IOHIDDeviceGetService");
Regards,
Dennis
It is not possible to send an Input report to device because there is no way to set report id, as it said into hidapi docs here: link to docs.
I would like to package cython-hidapi for Gentoo Linux, but I have some concerns about using a bundled copy of hidapi, in particular because we allow users to install multiple Python version (2.7+3.4+3.5, etc), and so the duplication of a library that is already in the system feels a bit awkward.
While I agree the current situation makes sense for default, would it be possible to have an option to link against the system copy?
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.