python-seabreeze icon indicating copy to clipboard operation
python-seabreeze copied to clipboard

Raspberry Pi Seabreeze spec.close() not working

Open ThomasPleavin opened this issue 9 months ago • 4 comments

We have Seabreeze v2.10.0 running on a Raspberry pi 5 with an OceanFX Spectrometer, all is working great except spec.close(). On a windows based machine this works flawlessly to close a spectrometer after use and prevent a connection issue. The same Code running on a Pi5 will not close properly and cause issues when trying to reconnect. The following code will work every time on windows machine, but only once on a Pi5 and will not connect on subsequent runs. Do you have any thoughts?

from seabreeze.spectrometers import Spectrometer, list_devices

def get_spectrometer_serial_number():
    # List all connected devices
    devices = list_devices()
    print("Devices found:", devices)

    if not devices:
        print("No spectrometers found.")
        return None

    # Connect to the first available spectrometer
    spec = Spectrometer(devices[0])

    # Get and print serial number
    serial_number = spec.serial_number
    print(f"Spectrometer Serial Number: {serial_number}")

    # Close the device
    spec.close()
    print("Spectrometer connection closed.")

    # Try accessing the spectrometer to confirm it's closed
    try:
        _ = spec.serial_number
        print("ERROR: Spectrometer is still accessible after closing.")
    except Exception as e:
        print("Confirmed closed: accessing spectrometer raises an error.")
        print("Error message:", str(e))

    return serial_number

# Run the function
if __name__ == "__main__":
    get_spectrometer_serial_number()

ThomasPleavin avatar May 20 '25 13:05 ThomasPleavin

Additional context, the issue seems to be with the OceanFX Spectrometer, as previous versions of spectrometer (Flame, USB+) Seem to work fine

ThomasPleavin avatar May 20 '25 14:05 ThomasPleavin

Hi Thomas,

Is your code just a toy example of what you'd want to do?

Can you check what the following returns?

from seabreeze.spectrometers import list_devices

for device in list_devices():
    print("is open", device.is_open)
    device.open()
    print("is open", device.is_open)
    print("model", device.model)
    print("serial", device.serial_number)
    device.close()
    print("is closed", not device.is_open)

ap-- avatar May 21 '25 12:05 ap--

Hi AP,

Yes, all the other functionality of our code works as intended, its just the closing of the spectrometer thats misbehaving.

is the output from your code:

is open False is open True model FLAMEX serial OFX02911 is closed True

subsequent runs of code will not work, show is open False

ThomasPleavin avatar May 21 '25 14:05 ThomasPleavin

Another piece of potentially useful information, i installed v.2.10.0 but the OceanFX minimum int time change that was in v2.10.0 doesn't seem to be carried through on cseabreeze. Code on Windows Machine Returns 10 min int time for FlameX where as on Pi it returns 1000

ThomasPleavin avatar May 21 '25 16:05 ThomasPleavin