JakubAndrysek / PySpaceMouse

🎮 Multiplatform Python library for 3Dconnexion SpaceMouse devices using raw HID.
https://spacemouse.kubaandrysek.cz/
MIT License
62 stars 17 forks source link

Windows 10 error ; and raspi error #1

Closed e71828 closed 2 years ago

e71828 commented 2 years ago
C:\Users\61240\Downloads\weimo_ws\src>python mouse.py
Traceback (most recent call last):
  File "C:\opt\ros\noetic\x64\lib\site-packages\easyhid\easyhid.py", line 53, in <module>
    hidapi = ffi.dlopen('hidapi.dll')
  File "C:\opt\ros\noetic\x64\lib\site-packages\cffi\api.py", line 150, in dlopen
    lib, function_cache = _make_ffi_library(self, name, flags)
  File "C:\opt\ros\noetic\x64\lib\site-packages\cffi\api.py", line 832, in _make_ffi_library
    backendlib = _load_backend_lib(backend, libname, flags)
  File "C:\opt\ros\noetic\x64\lib\site-packages\cffi\api.py", line 827, in _load_backend_lib
    raise OSError(msg)
OSError: cannot load library 'hidapi.dll': error 0x7e.  Additionally, ctypes.util.find_library() did not manage to locate a library called 'hidapi.dll'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "mouse.py", line 1, in <module>
    import pyspacemouse
  File "C:\opt\ros\noetic\x64\lib\site-packages\pyspacemouse\__init__.py", line 1, in <module>
    from .pyspacemouse import *
  File "C:\opt\ros\noetic\x64\lib\site-packages\pyspacemouse\pyspacemouse.py", line 1, in <module>
    from easyhid import Enumeration
  File "C:\opt\ros\noetic\x64\lib\site-packages\easyhid\__init__.py", line 8, in <module>
    from easyhid.easyhid import *
  File "C:\opt\ros\noetic\x64\lib\site-packages\easyhid\easyhid.py", line 55, in <module>
    hidapi = ffi.dlopen(ctypes.util.find_library('hidapi.dll'))
  File "C:\opt\ros\noetic\x64\lib\site-packages\cffi\api.py", line 150, in dlopen
    lib, function_cache = _make_ffi_library(self, name, flags)
  File "C:\opt\ros\noetic\x64\lib\site-packages\cffi\api.py", line 832, in _make_ffi_library
    backendlib = _load_backend_lib(backend, libname, flags)
  File "C:\opt\ros\noetic\x64\lib\site-packages\cffi\api.py", line 821, in _load_backend_lib
    raise OSError("dlopen(None) cannot work on Windows for Python 3 "
OSError: dlopen(None) cannot work on Windows for Python 3 (see http://bugs.python.org/issue23606)
e71828 commented 2 years ago

On Raspi

ubuntu@plum:~$ chmod +x mouse.py
ubuntu@plum:~$ ./mouse.py
Traceback (most recent call last):
  File "./mouse.py", line 5, in <module>
    success = pyspacemouse.open()
  File "/home/ubuntu/.local/lib/python3.8/site-packages/pyspacemouse/pyspacemouse.py", line 656, in open
    all_devices = list_devices()
  File "/home/ubuntu/.local/lib/python3.8/site-packages/pyspacemouse/pyspacemouse.py", line 598, in list_devices
    hid = Enumeration()
  File "/home/ubuntu/.local/lib/python3.8/site-packages/easyhid/easyhid.py", line 366, in __init__
    self.device_list = _hid_enumerate(vid, pid)
  File "/home/ubuntu/.local/lib/python3.8/site-packages/easyhid/easyhid.py", line 428, in _hid_enumerate
    start = hidapi.hid_enumerate(vendor_id, product_id)
  File "/home/ubuntu/.local/lib/python3.8/site-packages/cffi/api.py", line 912, in __getattr__
    make_accessor(name)
  File "/home/ubuntu/.local/lib/python3.8/site-packages/cffi/api.py", line 908, in make_accessor
    accessors[name](name)
  File "/home/ubuntu/.local/lib/python3.8/site-packages/cffi/api.py", line 838, in accessor_function
    value = backendlib.load_function(BType, name)
AttributeError: function/symbol 'hid_enumerate' not found in library '<None>': python3: undefined symbol: hid_enumerate
e71828 commented 2 years ago

I get, win10 only installed the interface,no module or lib found. could please the url for easyhid lib.

e71828 commented 2 years ago

sudo apt install libhidapi-dev, thanks.

JakubAndrysek commented 2 years ago

Does it work right now?

e71828 commented 2 years ago

Yes, It worked. Thanks.

Btw, for windows, the error could be solved?

JakubAndrysek commented 2 years ago

I tested it two years ago, and if I remember correctly, the Windows version didn't work for me, but since the primary goal was to make it work on Linux, I didn't bother with it further.

If I'm looking at the easyhid source code correctly. The library is trying to find hidapi.dll Look at it there on line 53

JakubAndrysek commented 2 years ago

I have also updated readme with a better install process. But I have not tested it yet. Could you please try it? @e71828

e71828 commented 2 years ago

the main log

ubuntu@plum:~$ pip show easyhid
Name: easyhid
Version: 0.0.10
Summary: A simple interface to the HIDAPI library.
Home-page: http://github.com/ahtn/python-easyhid
Author: jem
Author-email: jem@seethis.link
License: MIT
Location: /home/ubuntu/.local/lib/python3.8/site-packages
Requires: cffi
Required-by:
ubuntu@plum:~$ apt list libhidapi-dev
Listing... Done
libhidapi-dev/focal,now 0.9.0+dfsg-1 arm64 [installed]
ubuntu@plum:~$ uname -a
Linux plum 5.4.0-1070-raspi #80-Ubuntu SMP PREEMPT Thu Sep 8 15:35:01 UTC 2022 aarch64 aarch64 aarch64 GNU/Linux
ubuntu@plum:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.5 LTS
Release:        20.04
Codename:       focal
ubuntu@plum:~$ ./m
mouse.py       ms5837-python/
ubuntu@plum:~$ vim mouse.py
ubuntu@plum:~$ ls
PCA9685.py  catkin_ws  ina226.py      openocd      pigpio-master  ser_with.py       socket_server.py       tcp_serial_redirect.py
SSD1306     emio_ws    mouse.py       openocd.cfg  rpi-backup     servo_demo.c      stm32flash-0.6         temp_DHT11.py
USART.axf   hello      ms5837-python  pi_ina226    ser_read.py    socket_client.py  stm32flash-0.6.tar.gz  test_mouse.py
ubuntu@plum:~$ vim mouse.py
ubuntu@plum:~$ python3 mouse.py
Traceback (most recent call last):
  File "mouse.py", line 2, in <module>
    import pyspacemouse
ModuleNotFoundError: No module named 'pyspacemouse'
ubuntu@plum:~$ pip install pyspacemouse
Collecting pyspacemouse
  Using cached pyspacemouse-1.0.3-py3-none-any.whl (10 kB)
Requirement already satisfied: easyhid in ./.local/lib/python3.8/site-packages (from pyspacemouse) (0.0.10)
Processing ./.cache/pip/wheels/5e/5d/01/3083e091b57809dad979ea543def62d9d878950e3e74f0c930/typing-3.7.4.3-py3-none-any.whl
Requirement already satisfied: cffi in ./.local/lib/python3.8/site-packages (from easyhid->pyspacemouse) (1.15.1)
Requirement already satisfied: pycparser in ./.local/lib/python3.8/site-packages (from cffi->easyhid->pyspacemouse) (2.21)
Installing collected packages: typing, pyspacemouse
Successfully installed pyspacemouse-1.0.3 typing-3.7.4.3
ubuntu@plum:~$ python3 mouse.py
SpaceMouse Compact found
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
^CTraceback (most recent call last):
  File "mouse.py", line 10, in <module>
    time.sleep(0.01)
KeyboardInterrupt

ubuntu@plum:~$

about the permissison

ubuntu@plum:~$ ll /dev/hidraw0
crw-rw-r-- 1 root plugdev 237, 0 Sep 27 00:40 /dev/hidraw0
ubuntu@plum:~$ cat /etc/udev/rules.d/
70-snap.snapd.rules          99-hidraw-permissions.rules
ubuntu@plum:~$ cat /etc/udev/rules.d/99-hidraw-permissions.rules
KERNEL=="hidraw*", SUBSYSTEM=="hidraw", MODE="0664", GROUP="plugdev"
ubuntu@plum:~$ groups
ubuntu adm tty kmem dialout cdrom floppy sudo audio dip video plugdev netdev lxd i2c

if you are not in the group plugdev, need the scripts following:

ubuntu@plum:~$ sudo usermod -aG plugdev $USER
ubuntu@plum:~$ newgrp plugdev
ubuntu@plum:~$
e71828 commented 2 years ago

setenv

HID= C:\Users\admin\Documents\Hardware\hidapi\x64 PATH= %PATH%;%HID%

image

Good Results

image

JakubAndrysek commented 2 years ago

Excellent, so now is everything working?

Could you please add a pull request with a better installation process?

JakubAndrysek commented 2 years ago

Might I ask you in which project do you want to use this library? My motivation was in controlling my computer (apps) using this SpaceMouse. Especially for Inkscape - moving canvas and rotating objects.

e71828 commented 2 years ago

robot motion control

JakubAndrysek commented 2 years ago

That sounds nice 😍

So, is everything working correctly right now, might I close this issue?