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

isready()

Open yakir12 opened this issue 8 years ago • 6 comments

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()).

yakir12 avatar Oct 12 '15 04:10 yakir12

All spectrometer methods should be blocking.

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

ap-- avatar Oct 12 '15 08:10 ap--

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 [email protected] 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 .

yakir12 avatar Oct 12 '15 10:10 yakir12

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).

ap-- avatar Oct 12 '15 10:10 ap--

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" [email protected] 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 .

yakir12 avatar Oct 12 '15 10:10 yakir12

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.

ap-- avatar Oct 12 '15 11:10 ap--

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" [email protected] 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 .

yakir12 avatar Oct 12 '15 11:10 yakir12