VernierST / godirect-py

A Python module for reading from Vernier Go Direct® Sensors using USB or BLE.
GNU General Public License v3.0
8 stars 9 forks source link

USB connection does not work on OSX #13

Closed scarere closed 4 years ago

scarere commented 4 years ago

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 4 years ago

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!

scarere commented 4 years ago

Hi Nick,

Thanks for getting back to me. After reading your email, I realized that since OS X switched to terminal over to zsh, installing setuptool extras was no longer working (square brackets are not permitted so you have to put the package name in quotations). I had just pip installed godirect and the other packages manually and may have installed the wrong versions.

I currently can not test whether this will fix the issues I was having as I do not have the sensor with me (I have gone home for the break). However I may be able to pick it up soon and will test it as soon as I can and let you know so that you can close the issue.

Thank you so much for help.

Sincerely, Shawn Carere

On Dec 13, 2019, at 2:05 PM, Nick Robinson notifications@github.com wrote:

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-py[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 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!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/VernierST/godirect-py/issues/13?email_source=notifications&email_token=AI3ZMACPT7MNQZ5L4UUXHJ3QYPMHDA5CNFSM4JLZ7M42YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEG26FBI#issuecomment-565568133, or unsubscribe https://github.com/notifications/unsubscribe-auth/AI3ZMAG4EA7R6HSR54AVIPDQYPMHDANCNFSM4JLZ7M4Q.

scarere commented 4 years ago

Hi Nick,

I managed to get a hold of the sensor to test out my environment and it works great. Thanks again for your help.

Thought it was worth noting that ‘pip install godirect-py[usb]’ did not work for me, however I was able to install the package with all it’s extras using ‘pip install godirect[usb]’

I now know that zsh requires quotations around the package when installing setuptool extras, hopefully that will save me some headaches in the future.

Thanks Again, Shawn

On Dec 14, 2019, at 11:02 AM, Shawn Carere shawncarere@gmail.com wrote:

Hi Nick,

Thanks for getting back to me. After reading your email, I realized that since OS X switched to terminal over to zsh, installing setuptool extras was no longer working (square brackets are not permitted so you have to put the package name in quotations). I had just pip installed godirect and the other packages manually and may have installed the wrong versions.

I currently can not test whether this will fix the issues I was having as I do not have the sensor with me (I have gone home for the break). However I may be able to pick it up soon and will test it as soon as I can and let you know so that you can close the issue.

Thank you so much for help.

Sincerely, Shawn Carere

On Dec 13, 2019, at 2:05 PM, Nick Robinson <notifications@github.com mailto:notifications@github.com> wrote:

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-py[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 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!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/VernierST/godirect-py/issues/13?email_source=notifications&email_token=AI3ZMACPT7MNQZ5L4UUXHJ3QYPMHDA5CNFSM4JLZ7M42YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEG26FBI#issuecomment-565568133, or unsubscribe https://github.com/notifications/unsubscribe-auth/AI3ZMAG4EA7R6HSR54AVIPDQYPMHDANCNFSM4JLZ7M4Q.

stocktonkincade commented 4 years ago

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 4 years ago

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!