New issue 59 by jarkko.s...@gmail.com: OSX support with hidapi
http://code.google.com/p/pywws/issues/detail?id=59
With OS X the libusb wil not work with weather station , because the device
is claimed by generic hid driver. It is possible to prevent this by writing
an empty device driver for weather station, but this is rumoured not to
work anymore.
OS X contains libraries to access hid usb devices, but the API is Apple
specific. I suggest using a wrapper library called 'hidapi'
(https://github.com/signal11/hidapi/downloads) and a python wrapper to call
the library. There may be alternatives, but I found the hidapi library
simple to use and sufficient for this purpose. Hidapi should work with
Linux and Windows too, but it did try it.
To use hidapi I suggest separating the usb code from WeatherStation.py . I
attached the version I am using.
Attachments:
WeatherStation.py 24.2 KB
DevicePyUsb.py 2.3 KB
DeviceHidapi.py 1.1 KB
hidapi.py 11.7 KB
Comment #1 on issue 59 by a...@jim-easterbrook.me.uk: OSX support with
hidapi
http://code.google.com/p/pywws/issues/detail?id=59
I'm in the process of rewriting WeatherStation.py at the moment, and have
already split off the USB code into its own class. Putting this class in a
separate module makes sense, but I can't promise to use your api.
'hidapi' is not available for the version of OpenWRT that's running on the
router I use with my weather station, so I won't be able to test any module
that uses it.
Just for the record: the hidapi wrapper is from this discussion
http://comments.gmane.org/gmane.comp.python.pyusb.user/749
Hello, can you send me the hidapi.dylib on mac.
My email address is huang...@gmail.com.
Thanks.
I assume you get hidapi files from
https://github.com/signal11/hidapi/downloads.
Comment #5 on issue 59 by a...@jim-easterbrook.me.uk: OSX support with
hidapi
http://code.google.com/p/pywws/issues/detail?id=59
I'm pleased to report that I've made some progress this week.
First I split off the lowest level USB interface code into its own Python
module (device_libusb.py), then created a second module (device_hidapi)
with a compatible USBDevice class.
Secondly I was able to compile hidapi on my Ubuntu machine and install it
as a shared library which can be imported by the ctypes based hidapi.py
wrapper. It uses libusb-1.0, unlike pyusb which uses libusb-0.1.
Lastly, it all seems to work!
I'll check in the new files in a few minutes, and then I need to write some
documentation. Leading novice users through the compilation and
installation of hidapi is not going to be easy.
I've found another Python interface to hidapi that is even simpler to use.
It claims to work on Linux, Windows and Mac. I've got it working with pywws
on Linux. Could a Mac owner try it for me?
1/ Get cython-hidapi from its git repository:
git clone http://github.com/gbishop/cython-hidapi.git
2/ Compile it:
cd cython-hidapi
python setup-mac.py build
3/ Install it:
sudo setup-mac.py install
4/ Test it:
python try.py
Traceback (most recent call last):
File "setup-mac.py", line 3, in <module>
from Cython.Distutils import build_ext
ImportError: No module named Cython.Distutils
Clearly there is no module called Cython.Distutils, so maybe I am suppose
to install something else first. Cython?
Mark
>--
>You received this message because you are subscribed to the Google Groups
>"pywws" group.
>To post to this group, send email to py...@googlegroups.com.
>To unsubscribe from this group, send email to
>pywws+un...@googlegroups.com.
>For more options, visit this group at
>http://groups.google.com/group/pywws?hl=en.
>
Yes, I hope it's in the Mac equivalent of a standard repository.
--
Jim Easterbrook <http://www.jim-easterbrook.me.uk/>
You shouldn't need 'sudo' when building the Python extension, just when
installing it.
I think those are warnings rather than errors.
Nope, this is exactly what I'd expect to see. I don't know what device
the test script is trying to open, but it wouldn't have got that far if
the extension hadn't installed OK.
This looks very promising. I'll check into pywws svn a module that uses
it to access the weather station.
Hooray! Touch wood.
> Will the changes you plan to make be compulsory? In other words if I
> upgrade in the future will I be expected to use this new form of USB
> interface driver?
No, my plan is to support at least two - the original pyusb (which is
the only one available on my OpenWRT router, without a lot of extra
work) and an hidapi based one. I'm hoping this cython-hidapi interface
will be easy enough to install and work for enough people that I don't
need to support the hidapi.py ctypes based interface. pywws should
automatically use whichever is installed.
Cython is missing by default (at least in OS X 10.6.8):
$ python setup-mac.py build
Traceback (most recent call last):
File "setup-mac.py", line 3, in <module>
from Cython.Distutils import build_ext
ImportError: No module named Cython.Distutils
Install it from source or from Mac Ports:
$ sudo port install py26-cython
After that:
$ python setup-mac.py build
running build
running build_ext
skipping 'hid.c' Cython extension (up-to-date)
$ sudo python setup-mac.py install
Password:
running install
running build
running build_ext
skipping 'hid.c' Cython extension (up-to-date)
running install_lib
copying build/lib.macosx-10.6-i386-2.6/hid.so ->
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages
running install_egg_info
Writing
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/UNKNOWN-0.0.0-py2.6.egg-info
$ python try.py
[{'usage_page': 1, 'product_id': 521, 'manufacturer_string':
u'A\x00p\x00p', 'vendor_id': 1452, 'release_number':
272, 'serial_number': ..., 'usage':
6, 'path': 'Bluetooth_05ac_0209_0x21ddf0', 'product_string':
u'v\x00i\x00e\x00r\x00a\x00s\x00\u2019\x00s\x00 '}, {'usage_page':
12, 'product_id': 33344, 'manufacturer_string': u'A\x00p\x00p\x00l\x00e\x00
\x00C\x00o\x00m\x00p\x00', 'vendor_id': 1452, 'release_number':
272, 'serial_number': u'', 'usage':
1, 'path': 'USB_05ac_8240_0x21e920', 'product_string':
u'A\x00p\x00p\x00l\x00'}, {'usage_page': 1, 'product_id':
45065, 'manufacturer_string': u'U\x00n\x00k\x00n', 'vendor_id':
1133, 'release_number': 1046, 'serial_number': ..., 'usage':
2, 'path': 'Bluetooth_046d_b009_0x21d2a0', 'product_string':
u'L\x00o\x00g\x00i\x00t\x00e\x00c\x00h\x00
\x00B\x00l\x00u\x00e\x00t\x00o\x00'}, {'usage_page': 65440, 'product_id':
32801, 'manufacturer_string': u'', 'vendor_id': 6465, 'release_number':
256, 'serial_number': u'', 'usage':
1, 'path': 'USB_1941_8021_0x21c670', 'product_string': u''}]
Traceback (most recent call last):
File "try.py", line 6, in <module>
h = hid.device(0x461, 0x20)
File "hid.pyx", line 42, in hid.device.__cinit__ (hid.c:951)
raise IOError('open failed')
IOError: open failed
I don't have the tried device, so I modified the try.pl:
$ diff try.py*
6,7c6
< #h = hid.device(0x461, 0x20)
< h = hid.device(0x1941, 0x8021)
---
> h = hid.device(0x461, 0x20)
13,20d11
< h.set_nonblocking(0)
<
< cmd = [0x00, 0xA1, 0, 0, 0x20, 0xA1, 0, 0, 0x20]
< h.write(cmd)
< for k in range(4):
< print h.read(8)
< print
<
$ python try.py
...
[85, 170, 255, 255, 255, 255, 255, 255]
[255, 255, 255, 255, 255, 255, 255, 255]
[15, 32, 1, 48, 17, 0, 0, 0]
[1, 0, 0, 240, 15, 0, 48, 166]
[85, 170, 255, 255, 255]
...
Note that to use HID devices in OS X, you must be the current console user
or root. So if you use cron or launchd job, you must be root. I don't know
if there is a special group or something for HID access.
Thanks for that. Would you be happy if I dropped support for hidapi.py
leaving a choice of two: pyusb or cython-hidapi?
I'd prefer to use something that's in a repository and is actively
maintained. I don't think hidapi.py meets those requirements.
That's ok with me.
I have a Mac and recently got a WH3081. I used the approach outlined above
which was to:
1. Download and install Cython.
2. Download and install cython-hidapi
3. Download latest pywws using svn checkout (not the older gtar from the
pywws downloads section)
4. Ran through the instructions on the pywws getting started page.
I confirm that the latest changes work for me on a Mac running OS X 10.7.2
and Python2.7.
Comment #11 on issue 59 by a...@jim-easterbrook.me.uk: OSX support with
hidapi
http://code.google.com/p/pywws/issues/detail?id=59
(No comment was entered for this change.)