ap-- / python-seabreeze

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

isready() #18

Open yakir12 opened 9 years ago

yakir12 commented 9 years ago

It would be an awesome feature to have an isready functionality for testing if the spectrometer is ready for input (e.g. via spec.integration_time_micros(12000)) and/or output (e.g. spec.intensities()).

ap-- commented 9 years ago

All spectrometer methods should be blocking.

What's your specific use case for an isready method?

yakir12 commented 9 years ago

I want to fetch intensities when the spec is ready and not before by using asynchronous coroutines. All of this is done in Julia (not Python) with channels, tasks, and @async. What do you mean with "All spectrometer methods should be blocking"? Maybe I can work around it?

On 18:57, Mon, 12/10/2015 Andreas Poehlmann notifications@github.com wrote:

All spectrometer methods should be blocking.

What's your specific use case for an isready method?

— Reply to this email directly or view it on GitHub https://github.com/ap--/python-seabreeze/issues/18#issuecomment-147334894 .

ap-- commented 9 years ago

If you call spec.intensities() pyseabreeze sends a request command to the spectrometer and starts reading the spectrum information from the spectrometer.

By default most oceanoptics spectrometers are in a free running trigger mode. This means, that once you set the integration time, the spectrometer is constantly acquiring spectra. When a spectrum is requested via usb the spectrometer is sending the next valid acquired spectrum. This means in free running trigger mode, dependent on when the spectrum is requested, it can take from [insert really short time] up to [insert the integration time you set] until the spec.intensities() call returns.

if you call spec.intensities() in a loop, the loop delay will be the integration time you set (plus some overhead).

yakir12 commented 9 years ago

I'm trying to avoid changing the integration time and fetching the intensities at the same time. I think it should be possible to do that in my specific setup but thought it would be great if there was a isready() function that could tell me when the spec is ready for any kind of communication. On 12/10/2015 8:30 PM, "Andreas Poehlmann" notifications@github.com wrote:

If you call spec.intensities() pyseabreeze sends a request command to the spectrometer and starts reading the spectrum information from the spectrometer.

By default most oceanoptics spectrometers are in a free running trigger mode. This means, that once you set the integration time, the spectrometer is constantly acquiring spectra. When a spectrum is requested via usb the spectrometer is sending the next valid acquired spectrum. This means in free running trigger mode, dependent on when the spectrum is requested, it can take from [insert really short time] up to [insert the integration time you set] until the spec.intensities() call returns.

if you call spec.intensities() in a loop, the loop delay will be the integration time you set (plus some overhead).

— Reply to this email directly or view it on GitHub https://github.com/ap--/python-seabreeze/issues/18#issuecomment-147360309 .

ap-- commented 9 years ago

I should check if pyseabreeze is threadsafe. In the meantime, if you want to change the integration time and read spectra from two different threads, you may need to implement the thread locking yourself.

I would recommend to use a single thread to communicate with the spectrometer and implement all asynchronous calls on this thread. In the main loop of this thread you can check if other threads want to change the integration time and do the change on demand.

yakir12 commented 9 years ago

Awesome advice. I'll keep tinkering. Thanks for all the work and sorry for opening all these "issues". On 12/10/2015 9:41 PM, "Andreas Poehlmann" notifications@github.com wrote:

I should check if pyseabreeze is threadsafe. In the meantime, if you want to change the integration time and read spectra from two different threads, you may need to implement the thread locking yourself.

I would recommend to use a single thread to communicate with the spectrometer and implement all asynchronous calls on this thread. In the main loop of this thread you can check if other threads want to change the integration time and do the change on demand.

— Reply to this email directly or view it on GitHub https://github.com/ap--/python-seabreeze/issues/18#issuecomment-147371751 .