From b78ec839e7ed61c19dce2bcdc6742fe64b95dbf6 Mon Sep 17 00:00:00 2001 From: Denis Ilia Date: Tue, 27 Aug 2024 13:50:22 +0200 Subject: [PATCH 1/3] Added oceanfx support for pyseabreeze over ipv4 --- src/seabreeze/pyseabreeze/devices.py | 28 +++++++++++++++++++ .../pyseabreeze/features/spectrometer.py | 12 ++++++++ 2 files changed, 40 insertions(+) diff --git a/src/seabreeze/pyseabreeze/devices.py b/src/seabreeze/pyseabreeze/devices.py index a70e1e7..5954fce 100644 --- a/src/seabreeze/pyseabreeze/devices.py +++ b/src/seabreeze/pyseabreeze/devices.py @@ -1362,3 +1362,31 @@ class ST(SeaBreezeDevice): sbf.rawusb.SeaBreezeRawUSBBusAccessFeature, sbf.nonlinearity.NonlinearityCoefficientsFeatureOBP2, ) + + +class FX(SeaBreezeDevice): + + model_name = "FX" + + # communication config + transport = (IPv4Transport,) + + ipv4_protocol = OBPProtocol + + # spectrometer config + dark_pixel_indices = DarkPixelIndices.from_ranges() + integration_time_min = 6000 + integration_time_max = 10000000 + integration_time_base = 1 + spectrum_num_pixel = 2136 + spectrum_raw_length = (2136 * 2) + 64 # XXX: Metadata + spectrum_max_value = 65535 + trigger_modes = TriggerMode.supported( + "OBP_NORMAL", "OBP_LEVEL", "OBP_EDGE", "DISABLED" + ) + + # features + feature_classes = ( + sbf.spectrometer.SeaBreezeSpectrometerFeatureFX, # need to implement this + sbf.rawusb.SeaBreezeRawUSBBusAccessFeature, + ) \ No newline at end of file diff --git a/src/seabreeze/pyseabreeze/features/spectrometer.py b/src/seabreeze/pyseabreeze/features/spectrometer.py index 609a330..0c5b49c 100644 --- a/src/seabreeze/pyseabreeze/features/spectrometer.py +++ b/src/seabreeze/pyseabreeze/features/spectrometer.py @@ -742,3 +742,15 @@ def get_wavelengths(self) -> NDArray[np.float_]: class SeaBreezeSpectrometerFeatureHR4(SeaBreezeSpectrometerFeatureOBP2): pass + + +class SeaBreezeSpectrometerFeatureFX(SeaBreezeSpectrometerFeatureOBP): + def _get_spectrum_raw(self): + timeout = int( + self._integration_time_max * 1e-3 + + self.protocol.transport.default_timeout_ms + ) + # the message type is different than the default defined in the protocol, + # requires addition of a new message type in protocol to work + datastring = self.protocol.query(0x00101000, timeout_ms=timeout) + return numpy.fromstring(datastring, dtype=numpy.uint8) \ No newline at end of file From 62abff4e850b9bd1f46ff5b6572de167ddfd8c7d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 27 Aug 2024 11:55:23 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/seabreeze/pyseabreeze/devices.py | 2 +- src/seabreeze/pyseabreeze/features/spectrometer.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/seabreeze/pyseabreeze/devices.py b/src/seabreeze/pyseabreeze/devices.py index 5954fce..ecfe9b2 100644 --- a/src/seabreeze/pyseabreeze/devices.py +++ b/src/seabreeze/pyseabreeze/devices.py @@ -1389,4 +1389,4 @@ class FX(SeaBreezeDevice): feature_classes = ( sbf.spectrometer.SeaBreezeSpectrometerFeatureFX, # need to implement this sbf.rawusb.SeaBreezeRawUSBBusAccessFeature, - ) \ No newline at end of file + ) diff --git a/src/seabreeze/pyseabreeze/features/spectrometer.py b/src/seabreeze/pyseabreeze/features/spectrometer.py index 0c5b49c..7739170 100644 --- a/src/seabreeze/pyseabreeze/features/spectrometer.py +++ b/src/seabreeze/pyseabreeze/features/spectrometer.py @@ -753,4 +753,4 @@ def _get_spectrum_raw(self): # the message type is different than the default defined in the protocol, # requires addition of a new message type in protocol to work datastring = self.protocol.query(0x00101000, timeout_ms=timeout) - return numpy.fromstring(datastring, dtype=numpy.uint8) \ No newline at end of file + return numpy.fromstring(datastring, dtype=numpy.uint8) From c393d584c5ef3c108d2b325e1d501bfe7db4b45b Mon Sep 17 00:00:00 2001 From: Andreas Poehlmann Date: Fri, 6 Sep 2024 00:30:36 +0200 Subject: [PATCH 3/3] fix mypy errors and avoid copy --- src/seabreeze/pyseabreeze/features/spectrometer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/seabreeze/pyseabreeze/features/spectrometer.py b/src/seabreeze/pyseabreeze/features/spectrometer.py index 7739170..037b0ec 100644 --- a/src/seabreeze/pyseabreeze/features/spectrometer.py +++ b/src/seabreeze/pyseabreeze/features/spectrometer.py @@ -745,7 +745,7 @@ class SeaBreezeSpectrometerFeatureHR4(SeaBreezeSpectrometerFeatureOBP2): class SeaBreezeSpectrometerFeatureFX(SeaBreezeSpectrometerFeatureOBP): - def _get_spectrum_raw(self): + def _get_spectrum_raw(self) -> NDArray[np.uint8]: timeout = int( self._integration_time_max * 1e-3 + self.protocol.transport.default_timeout_ms @@ -753,4 +753,4 @@ def _get_spectrum_raw(self): # the message type is different than the default defined in the protocol, # requires addition of a new message type in protocol to work datastring = self.protocol.query(0x00101000, timeout_ms=timeout) - return numpy.fromstring(datastring, dtype=numpy.uint8) + return numpy.frombuffer(datastring, dtype=numpy.uint8)