-
-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to connect to the HDX Spectrometer via USB from Linux (Windows works) #133
Comments
Hi @stepandr47 Did you install the udev rules? If not please run If that didn't solve it, please verify that the spectrometer is working by running it on a different machine with the original spectrasuite or oceanview software. Cheers, |
Which version of import usb; print(usb.__version__) |
So from your other issue, it seems that you have a flame-t running reliably? You could try testing a few different versions of pyusb: 1.1.0, 1.2.0, 1.2.1 If that doesn't work we'll have to figure out what the important difference is between the setup in https://github.com/ap--/python-seabreeze/pull/98 and yours. I can't really provide any hands-on help with debugging because I don't have an HDX... |
Yeah that is correct. I am able to do everything fine with the Flame-T. I have a test setup on a Ubuntu VM and a raspberry pi. The Flame-T works with both setups, but I can't get the HDX to work on either. I don't have the HDX with me today, so I will get back to you tomorrow on testing different versions of pyusb. |
Okay great. That's valuable information 👍 The pyusb versions are a longshot, but it's a super quick test. Another longshot would be: # run this before any other code
from seabreeze.pyseabreeze.protocol import OBPProtocol
OBPProtocol.OBP.HEADER_PROTOCOL_VERSION = 0x0000 |
I tried the different versions of pyusb on Ubuntu. I tried each of them with and without the OBPProtocol addition stated in your last comment. It was unable to connect in all case. I just now tried connecting to the device on Windows and it worked without any issues. I was also able to get data from it. Any ideas what could be causing the issue on Ubuntu? The only difference I can think of currently is the driver that gets installed when you connect it to the OceanView software. |
Okay. This is great. At least we know now that it's some difference between the OSes that's unrelated to the pyusb version. Hmmm 🤔
A simple thing I would try is to setup a virtualenv with seabreeze as root on the linux machine and run your test code as root. That rules out that it's some sort of permission issue. Also try running your script via:
and maybe compare the debug output between linux and windows. I'm pretty sure we'll be able to figure out what's causing this 👍 |
Running the script as root on Ubuntu got the same timeout error. I haven't looked through it yet but below are the outputs from linux. LIBUSB_DEBUG and PYUSB_DEBUG are not recognized on windows. During a quick search I was unable to find how to resolve this issue. One other thing worth mentioning is on windows I was only able to get it working when in a conda environment. I didn't realize my terminal was in one in the morning when I tested, but when I just tested now it won't work without being in the conda environment. Do to that I tried running the ubuntu setup in a conda environment, but it still gets the timed out error. |
Linux Output: Click to expand!
|
To get the same output for windows, you need to set them as environment variables:
(I think that's the right way for cmd.exe, powershell might be different) |
Was able to get these debugs working by adding these lines to the start of the script in windows. Noticed your comment after finding this way: Windows Output: Click to expand!
|
Hi @stepandr47 hmm, I was hoping we'd see that the libusb version would differ between the two. As it is, it is probably a bit hard to compare. (the linux output you posted seems to be from an interactive session and the windows output lacks the pyusb debug info) Could you save the following script on both your windows and linux machine and run it again and copy the full output of the script to this issue: # test_open_hdx.py
import os
os.environ['LIBUSB_DEBUG'] = "4"
os.environ['PYUSB_DEBUG'] = "debug"
import seabreeze
seabreeze.use('pyseabreeze')
from seabreeze.spectrometers import Spectrometer
print("=== SPECTROMETER OPEN ===")
spec = Spectrometer.from_first_available()
print("=== SPECTROMETER STOP ===")
print(spec) the following command should work in your linux shell AND in the windows cmd prompt:
It should write all output to the |
Linux Output:
|
Windows Output:
|
Hi @stepandr47 |
So, new things to test:
|
The first Linux output came from a Ubuntu VM. Below is the output from my current Raspberry Pi setup that I had captured yesterday. I won't be able to test with wireshark until Monday as I don't have the sensor with me today. What specifically should I be looking for when going through packets on wireshark? Are you wanting me to just capture using pcap and just post the pcap file here? Raspberry Pi Output:
|
If you could just post the pcap file that would be great. Tbh, I'm not entirely sure what to look for either. Which is why I think having the pcap file will make it a lot easier to ask the libusb experts for further advice. If you compare for example your virtual machine logs with the Pi logs, you can see, that they error in different parts of the code. The VM log errors on the first read, whereas the Pi log goes through a few more commands before it errors. Interestingly both error when requesting the length of the serial number buffer, just after the device gets opened. I will open a new branch and increase the write/read timeout for that command to something large. Maybe that solves the issue. |
Test if increasing the timeout for the first read after a spectrometer is opened helps with getting the HDX to work reliably under Linux. See #133.
Command 1 : Command 2: I am unsure what I did wrong for installing a specific branch on my Ubuntu VM. The above commands to install a specific branch work on windows, but when I try it on my Ubuntu VM I get the below output. I see that it says libusb not found at the end, but libusb is already installed so I am unsure what is causing that. Ouput: |
You need to follow: https://python-seabreeze.readthedocs.io/en/latest/install.html#step-1-linux |
That was it thanks. I installed that branch on windows, ubuntu and RPi. Still only working on windows. I have also captured the pcap for windows and ubuntu. I am unsure of a good way to do this on a RPi via ssh. Both of the files can be found in the below zip file. |
Just a quick question: do you connect the spectrometer through a USB hub on the PI? |
I did the packet capture through Windows Wireshark while the device was connected to a Ubuntu VM. So windows seems to see it from the VM as a USB hub. |
So just to be clear, the three test systems are:
And neither in 1+2 nor in 3 is a physical USB hub involved. |
Yes that is all correct |
Okay, so the packet capture was not conclusive. pyusb/pyusb#390 (comment) In the meantime we should investigate if the control requests are problematic.
Basically pyseabreeze grew organically out of the predecessor package python-oceanoptics and I refactored everything back then to adhere to the same api that libseabreeze exposed. It's possible that the order of calls made in there is incorrect, but has not affected a significant amount of the userbase so far.
So, if you could create two more packet captures from the linux VM for the following two scripts, that would allow us to check if there are differences between the two backends. NOTE: this would need to be done with the # cseabreeze test
import seabreeze
seabreeze.use('cseabreeze')
from seabreeze.spectrometers import Spectrometer
print(Spectrometer.from_first_available()) # pyseabreeze test
import seabreeze
seabreeze.use('pyseabreeze')
from seabreeze.spectrometers import Spectrometer
print(Spectrometer.from_first_available()) |
Below are the two pcap files stored in a zip folder. One for pyseabreeze and one for cseabreeze when using the above scripts to detect the Flame-T. These were both run on the Ubuntu VM. |
I have witnessed a similar behavior before when running Linux (I think it was Ubuntu) in a VM and connecting to the HDX through USB. In my experience the connection was working when I installed the correct version of libusb there. For life of me I cannot remember which version was it as I'm currently running HDX on a daily basis through the ethernet with a highly experimental fork of the library. |
Hi @Lavikjo Cheers, |
Hi @stepandr47 Given Lavikjo's comment so far, I think it might be worth trying different pyusb backends. libusb1# pyseabreeze using libusb1 (this is what currently doesn't work for you)
import seabreeze
print(seabreeze.__version__)
seabreeze.use('pyseabreeze', pyusb_backend='libusb1')
from seabreeze.spectrometers import Spectrometer
print(Spectrometer.from_first_available()) libusb0# pyseabreeze using libusb0 (you might have to `apt install libusb-0.1-4`)
import seabreeze
print(seabreeze.__version__)
seabreeze.use('pyseabreeze', pyusb_backend='libusb0')
from seabreeze.spectrometers import Spectrometer
print(Spectrometer.from_first_available()) openusb# pyseabreeze using openusb (you might have to `apt install libopenusb0`)
import seabreeze
print(seabreeze.__version__)
seabreeze.use('pyseabreeze', pyusb_backend='openusb')
from seabreeze.spectrometers import Spectrometer
print(Spectrometer.from_first_available()) |
Most likely it was something pre-built from aptitude. |
The outputs for each script can be seen below. libusb1:
libusb0:
openusb:
|
Hi @stepandr47, I'm having the same issue, have we had any changes since your first report? |
I'm having the same issue with the FX as well. I have one on hand and can provide any wireshark or usb debug logs as needed. |
I'm seeing the same issue with Ubuntu 22.04 and also Raspberry Pi running Raspian. Interestingly, I can get it to work periodically on Ubuntu Desktop. Usb debug logs here: |
Same problem here with a HDX connected by usb on a dell laptop. I've tried libusb0 and libusb1. Interestingly when I use seabreeze.use('pyseabreeze', pyusb_backend='openusb') and run list_devices():
If I'm using csearbreeze, I always get an empty list, without error. It seems a lot of debugging have been tried, but I can help if necessary... |
I'm also in a similar condition, spectrometer works with cbreeze, but when I try to use pyseabreeze, I get an error saying that the usb port is busy.... my spectrometer is QEPRO |
@dstr951 Please open a new issue for the QEPRO. |
This is now possible if connecting via Ethernet. |
spectrometer and system information
current problem
I am unable to connect to the HDX spectrometer. When I run list_devices() it displays:
This is the correct serial number for my device. I then have tried to connect to the device with from_serial_number(HDX01168) or from_first_available(). Both of these will give the below output on the first attempt:
Looking through the tickets I noticed that HDX support has been added, so I am unsure what I am doing incorrectly here.
steps to reproduce
Run below code with the HDX connected:
It seems like other users have gotten functionality working for an HDX spectrometer so I was wondering what I am doing incorrectly in the above implmentation.
The text was updated successfully, but these errors were encountered: