VernierST/godirect-py

USB connection does not work on OSX

Closed this issue · 5 comments

Seems to be related to issues with hidapi. I've installed hidapi using home-brew and pip installed https://github.com/apmorton/pyhidapi as it seemed that this was a dependency.

The initial error is that hid.device does not exist. Assuming that I pip installed the right hid api then it seemed the class is Device with a capital D.

I cloned go direct-py so that I could edit it and try and troubleshoot. I changed line 37 in device_usb.py to:
'self._device = hid.Device(vid=self.VID, pid=self.PID)'
and then ran into another error that Device had no function open_path(), so I changed line 38 in device_usb.py to:
'hid.hidapi.open(vid=self.VID, pid=self.PID)'

I now get the following error:

Traceback (most recent call last):
File "printECG.py", line 5, in
gdx.open_usb()
File "/Users/scarere/Documents/Queens/Capstone/IHMS/GoDirectSensor/gdx.py", line 63, in open_usb
open_device_success = self.selected_device.open()
File "/Users/scarere/Documents/Queens/Capstone/IHMS/godirect_osx/device.py", line 105, in open
if not self._GDX_init():
File "/Users/scarere/Documents/Queens/Capstone/IHMS/godirect_osx/device.py", line 473, in _GDX_init
return self._GDX_write_and_check_response(command)
File "/Users/scarere/Documents/Queens/Capstone/IHMS/godirect_osx/device.py", line 360, in _GDX_write_and_check_response
if not self._GDX_write(buff):
File "/Users/scarere/Documents/Queens/Capstone/IHMS/godirect_osx/device.py", line 333, in _GDX_write
return self._write(buff)
File "/Users/scarere/Documents/Queens/Capstone/IHMS/godirect_osx/device_usb.py", line 72, in _write
self._device.write(packet)
File "/Users/scarere/venv/IHMS/lib/python3.7/site-packages/hid/init.py", line 149, in write
return self.__hidcall(hidapi.hid_write, self.__dev, data, len(data))
File "/Users/scarere/venv/IHMS/lib/python3.7/site-packages/hid/init.py", line 136, in __hidcall
ret = function(*args, **kwargs)
ctypes.ArgumentError: argument 2: <class 'TypeError'>: wrong type

It seems to be an issue with the hid_write function and the way that parameters are being passed to it. For some reason this issue does not occur on Windows, only on OSX.

It's important to note that the device is being found by hid. Using hidapi I can print the VID, PID, path and product string.

Also not sure if this is relevant or not, but I'm connecting via usb through a usb to usb-c dongle.

If anyone knows how to solve this issue quickly that would be greatly appreciated. I don't mind having to change some of the backend code to get it working

nro2 commented

Sorry it took so long to see this.

I just ran GoDirect-py on OSX just to check to make sure it was still working with USB and I was successful. There might a few different issues here. First, I want to make sure that you are using Python 3, that part is important. Next, I would try installing GoDirect with the dependencies. If you use the following command it should set you up with everything needed, including the correct version of hidapi:

pip install godirect[usb] (or pip3, depending on how you're set up)

Just for reference, I am using:
Catalina v. 10.15.1
hidapi 0.7.99.post21
Python 3.7.4

Next, you can check it against these examples that I am running it with to make sure everything is functioning correctly:

https://github.com/VernierST/godirect-examples

There's a Python specific folder in there with a few usb examples. I just ran gdx_getting_started_1.py to confirm that it is working with OSX and it worked fine.

Hope this helps!

Nick,

Thanks for checking back. I will close this issue. FYI, the package name in Pypi is simply "godirect", so that would make sense that the ‘pip install godirect-py[usb]’ did not work.

Cheers,
-ian-

nro2 commented

My mistake, I originally put pip install godirect-py[usb], you must have caught that before I edited it. Glad it is working for you now!