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

[pyseabreeze] add support for ADC1000-USB via USB

Open FFY00 opened this issue 2 years ago • 5 comments

The ADC1000-USB is an older interface for S-series spectrometers (eg. S2000) and has USB and serial connections.

This patch adds support for the interfacing with it via USB.

There are some similar ADC cards using different transports (eg. PCI, PCMCIA), which I suspect use the same protocol, so this patch may set the infrastructure to support those too.

Signed-off-by: Filipe Laíns [email protected]

FFY00 avatar Sep 02 '22 01:09 FFY00

Fixes #112.

I don't have access to a proper lab right now, so I cannot test this extensively. With the current implementation, I can communicate with the device and get some values. I'd really appreciate if someone else could test it. @drmcnelson could you try?

This PR does not implement the continuous strobe feature, since I do not know how to test it, but it should work the same as the OOI protocol.

There are some mypy errors, but it's getting pretty late, I'll try to check them out tomorrow.

FFY00 avatar Sep 02 '22 01:09 FFY00

Thank you so much ❤️

This is a great contribution! I'll have time to review it over the weekend. In the meantime you can try running the wheels created by the CI as a sanity check: https://github.com/ap--/python-seabreeze/actions/runs/2976101581

Cheers, Andreas 😃

ap-- avatar Sep 02 '22 09:09 ap--

I did some testing with plotting, and it seems the value format isn't quite right because this protocol seems to stream the LSB and MSB values in separate packets. I will look into it.

That said, I'd like to hear your opinions on the code design. I was just trying to get things to work the other day, while trying to produce okay code, but now I understand the code structure a bit better, and I am not sure if this implementation is optimal. We could split the code for the OOI protocol into a base classes for both protocols, instead of having the ADC protocol hijack OOI. Let me know what you think.

FFY00 avatar Sep 04 '22 22:09 FFY00

I managed to get the correct spectra values, but I am running into some issue with the synchronization, as the full spectrum data is streamed via multiple packets because it is USB 1.0.

FFY00 avatar Sep 05 '22 00:09 FFY00

@FFY00 Attached is my code for the ADC1000-USB. The code provides a gui, a command line interface, a command line utility, and a library, all in python. The zip includes a history file from the cli that shows some of the command sequences that I use. See the help command (at line 1234), for more on the cli if interested.

I have used this code for thousands of hours of data collection and it seems to work well.

You can crib from the attached code, just be sure to cite appropriately. See notes below.

For your code:

Besides getting the data flow working, make sure to support triggered operation and clocked operation and signal averaging.

A lot of the science that is done with these involves the spectrometer being triggered from a laser, or the laser being triggered from the spectrometer while it is being clocked.

And for weak signals, signal averaging is an absolute must. The choices are signal averaging in the device (if it supports it, I forget) and signal averaging in software. Either way, you need to be able to display the spectrum as it develops. Data acquisition with the ADC1000-USB is inherently not very fast, so it is fairly easy to keep up with it even with signal averaging in software.


Some notes on the code:

  1. There might be one open issue in saving the coefficients. I think I recall fixing it, but you might want to check. See writemap() and writecoefficients(). Since the coefficients are only used by software, and since I only have one of these instruments, it was not a high priority for me. They can be specified on the command line or through the interactive cli.

  2. I only use the first two coefficients. The higher order coefficients are usually order 10^-5 or smaller, and in practice calibration errors are often much larger than what those extra coefficients provide. Feel free to expand it to use all of them, I may someday too, even if only for conformance. See "self.map"


ADC1000usb.zip

drmcnelson avatar Sep 05 '22 12:09 drmcnelson

What is the status of this contribution? Is it ready to merge into the main branch, or has it been merged?

Do you still need me to test it?

Have you tried external triggering?

drmcnelson avatar Nov 02 '22 12:11 drmcnelson

Can Fedora be included in the build wheels tests?

drmcnelson avatar Nov 02 '22 12:11 drmcnelson

@FFY00

Integration_time_micros_limits returns 1000, 655350000

The data sheet says it should be 5 and 65535 milliseconds, so that would be 5000 for the lower limit

But, the real error may be that calling integration_time_micros( n ) with n greater than 65535 produces an error that n is too big for ushort()

drmcnelson avatar Nov 02 '22 15:11 drmcnelson

@FFY00 Another bug

The first read, and then after that, every second read, returns garbage.

Here is what the third read looks like (it looks like it is not getting the correct coefficients, too, but that is a secondary issue at this point):

Screenshot from 2022-11-02 12-00-11

And here is what it looks like with the code I posted a few comments up from here:

Screenshot from 2022-11-02 12-03-06

drmcnelson avatar Nov 02 '22 15:11 drmcnelson

Hello everyone,

sorry for the long delay. It's pretty hard lately to find enough time.

I made a few minor changes to this PR and merged it to master. For now i'll consider support for the adc1000-usb as experimental.

I changed the lower limit of the integration time and I fixed the parsing of the raw spectrum according to the datasheet. (it's actually almost the same as for the USB2000 spectrometer. the usb2000 has to zero the high nibble of the msb though. the adc1000 doesn't mention this in the datasheet.) I also fixed that in this PR the sync byte wasn't read. which meant that spectra were basically garbage after the first read.

If one of you could install from master and let me know if it works, I would prepare a new release. @FFY00 @drmcnelson

Cheers, Andreas 😃

ap-- avatar Feb 25 '23 16:02 ap--