ap-- / python-seabreeze

Python module for OceanOptics spectrometers
https://python-seabreeze.readthedocs.io
MIT License
209 stars 81 forks source link

Basic HR2 support #242

Closed gabrielbenedikt closed 4 months ago

gabrielbenedikt commented 4 months ago

Here is a most basic HR2 support to pyseabreeze. -) Updated udev rules with appropriate PID. -) Copied and adapted the SR2 spectrometer class.

Tested basic functionality: -) Spectrometer is now found by seabreeze. -) Acquisition of a spectrum succeeds.

Passes pytest, without dark counts like the SR2 class this code is derived from.

============================================================================================================== test session starts ===============================================================================================================
platform linux -- Python 3.12.3, pytest-8.2.1, pluggy-1.5.0 -- /home/peter/.local/venvs/pd12/bin/python
cachedir: .pytest_cache
rootdir: /home/peter/development/python-seabreeze
configfile: pytest.ini
plugins: anyio-4.2.0
collected 28 items

tests/test_backends.py::test_seabreeze_installed PASSED                                                                                                                                                                                    [  3%]
tests/test_backends.py::test_seabreeze_wrong_backend_requested PASSED                                                                                                                                                                      [  7%]
tests/test_backends.py::test_seabreeze_any_backend_available[cseabreeze] PASSED                                                                                                                                                            [ 10%]
tests/test_backends.py::test_seabreeze_any_backend_available[pyseabreeze] PASSED                                                                                                                                                           [ 14%]
tests/test_backends.py::test_seabreeze_cseabreeze_backend_available PASSED                                                                                                                                                                 [ 17%]
tests/test_backends.py::test_seabreeze_pyseabreeze_backend_available PASSED                                                                                                                                                                [ 21%]
tests/test_backends.py::test_seabreeze_cseabreeze_api_init PASSED                                                                                                                                                                          [ 25%]
tests/test_backends.py::test_seabreeze_pyseabreeze_api_init[any] PASSED                                                                                                                                                                    [ 28%]
tests/test_backends.py::test_seabreeze_pyseabreeze_api_init[openusb] PASSED                                                                                                                                                                [ 32%]
tests/test_backends.py::test_seabreeze_pyseabreeze_api_init[libusb0] PASSED                                                                                                                                                                [ 35%]
tests/test_backends.py::test_seabreeze_pyseabreeze_api_init[libusb1] PASSED                                                                                                                                                                [ 39%]
tests/test_backends.py::test_seabreeze_compare_backend_feature_interfaces PASSED                                                                                                                                                           [ 42%]
tests/test_protocol.py::test_pyseabreeze_protocol_messages PASSED                                                                                                                                                                          [ 46%]
tests/test_spectrometers.py::TestHardware::test_cant_find_serial[backend(any)] PASSED                                                                                                                                                      [ 50%]
tests/test_spectrometers.py::TestHardware::test_device_cleanup_on_exit[backend(any)] PASSED                                                                                                                                                [ 53%]
tests/test_spectrometers.py::TestHardware::test_read_model[HR2:HR200451-backend(any)] PASSED                                                                                                                                               [ 57%]
tests/test_spectrometers.py::TestHardware::test_read_serial_number[HR2:HR200451-backend(any)] PASSED                                                                                                                                       [ 60%]
tests/test_spectrometers.py::TestHardware::test_crash_may_not_influence_following_tests[HR2:HR200451-backend(any)] XFAIL (check if following tests work after crash)                                                                       [ 64%]
tests/test_spectrometers.py::TestHardware::test_read_intensities[HR2:HR200451-backend(any)] PASSED                                                                                                                                         [ 67%]
tests/test_spectrometers.py::TestHardware::test_correct_dark_pixels[HR2:HR200451-backend(any)] SKIPPED (does not support dark counts)                                                                                                      [ 71%]
tests/test_spectrometers.py::TestHardware::test_read_wavelengths[HR2:HR200451-backend(any)] PASSED                                                                                                                                         [ 75%]
tests/test_spectrometers.py::TestHardware::test_read_spectrum[HR2:HR200451-backend(any)] PASSED                                                                                                                                            [ 78%]
tests/test_spectrometers.py::TestHardware::test_max_intensity[HR2:HR200451-backend(any)] PASSED                                                                                                                                            [ 82%]
tests/test_spectrometers.py::TestHardware::test_integration_time_limits[HR2:HR200451-backend(any)] PASSED                                                                                                                                  [ 85%]
tests/test_spectrometers.py::TestHardware::test_integration_time[HR2:HR200451-backend(any)] PASSED                                                                                                                                         [ 89%]
tests/test_spectrometers.py::TestHardware::test_trigger_mode[HR2:HR200451-backend(any)] PASSED                                                                                                                                             [ 92%]
tests/test_spectrometers.py::TestHardware::test_trigger_mode_wrong[HR2:HR200451-backend(any)] PASSED                                                                                                                                       [ 96%]
tests/test_spectrometers.py::TestHardware::test_list_devices_dont_close_opened_devices[backend(any)] PASSED                                                                                                                                [100%]

============================================================================================================ short test summary info =============================================================================================================
SKIPPED [1] tests/test_spectrometers.py:265: does not support dark counts
=================================================================================================== 26 passed, 1 skipped, 1 xfailed in 25.08s ====================================================================================================
MicheleCotrufo commented 4 months ago

Great to see that support for other recent models is being added! :) I have an HR4, and I would like to add support for that too. I am trying to replicate your code changes. How can I find the parameters for the entry to add in the file 10-oceanoptics.rule, and for the class HR4 to add to the file devices.py?

ap-- commented 4 months ago

@MicheleCotrufo those are the USB VENDOR ID and USB PRODUCT ID. Dependent on your operating system you'll find them in device manager (win) or by typing lsusb (unix)

ap-- commented 4 months ago

I'll push a new release later today!

Thanks again! ❤️