ap-- / python-oceanoptics

*discontinued* Python module for oceanoptics spectrometers
MIT License
21 stars 11 forks source link

Open spectrometers by serial-number #14

Open ap-- opened 9 years ago

ap-- commented 9 years ago

This should be implemented for everyone who wants to use several spectrometers at once

nonbiostudent commented 9 years ago

I'd be interested in working on this issue if no one else has started on it yet. From the brief look I've had at the exisiting code, I would propose a new get_spectrometers() function which returns a dict of spectrometer objects with their serial numbers as keys.

Does anyone have any ideas/comments on the problem of creating multiple instances of a spectrometer object - currently you get a USBError raised if you try to do that (e.g. if you call get_a_random_spectrometer() more than once). Would it be better to cache a list of spectrometer objects somewhere and have subsequent calls to the functions return the same instance each time?

ap-- commented 9 years ago

You could do the following: implement a list_unopened_spectrometers() function in utils.py, which (as you suggested) creates a dict of all available spectrometers, but catches and ignores the USBError if a spectrometer is already opened. A serial() function would need to be implemented in OceanOpticsUSBComm (and sadly, we need to figure out something for the STS class).

Then you could use the list in OceanOpticsBase to pick the spectrometer depended on the serial provided to the **init()** method.

This would not require a global variable storing a list of all spectrometers.