analogdevicesinc / pyadi-iio

Python interfaces for ADI hardware with IIO drivers (aka peyote)
https://analogdevicesinc.github.io/pyadi-iio
Other
139 stars 101 forks source link

Add pyadi support for ADAQ4001 and ADAQ4003 #571

Open machschmitt opened 4 months ago

machschmitt commented 4 months ago

Description

This PR adds pyadi support for ADAQ4001 and ADAQ4003.

AD4003/AD4007/AD4011, AD4020/AD4021/AD4022, and ADAQ4001/ADAQ4003 belong to a series of differential SAR ADC devices which are supported by the same Linux kernel driver.

This PR:

Related JIRA task: https://jira.analog.com/browse/COSGTM-277

Type of change

How has this been tested?

Test Configuration:

Documentation

The new python class was added to the list of documented classes provided by the ad4020 python module.

Checklist:

thorenscientific commented 4 months ago

@machschmitt the only other peculiarity I notice is that the sampling_frequency can only be set if there's no buffer created. That is, initially I can set the sample rate, but after calling rx(), attempting to set the sample rate throws: OSError: [Errno 16] Resource device Calling rx_destroy_buffer() allows the sample rate to be changed again. If this is expected behavior that's fine, just wondering if there's a cleaner way of handling it, either by calling rx_destroy_buffer() within the sampling_frequency setter, or just calling it in the example with a comment to the effect of: "can't set the sampling frequency if a buffer is created" (@tfcollins any thoughts?)

tfcollins commented 4 months ago

@machschmitt the only other peculiarity I notice is that the sampling_frequency can only be set if there's no buffer created. That is, initially I can set the sample rate, but after calling rx(), attempting to set the sample rate throws: OSError: [Errno 16] Resource device Calling rx_destroy_buffer() allows the sample rate to be changed again. If this is expected behavior that's fine, just wondering if there's a cleaner way of handling it, either by calling rx_destroy_buffer() within the sampling_frequency setter, or just calling it in the example with a comment to the effect of: "can't set the sampling frequency if a buffer is created" (@tfcollins any thoughts?)

The "nice" way to do this is with a decorator that manages it for you like so: https://github.com/analogdevicesinc/pyadi-iio/blob/main/adi/cn0540.py#L81

machschmitt commented 3 months ago

Updated according to suggestions. Regarding the voltage0-voltage-1 nomenclature, the devices can be set in Single-Ended to Differential Configuration, where they would sample like a single-ended ADC, and thus the channel type would be configurable. The current driver version does not support that but it may in the future, at which point, the interface would not reflect the channel type configuration if it is called just voltage0.

Change log v1 -> v2:

machschmitt commented 2 months ago

I reverted the patch adding the reset_buffer convenience decorator because it was failing pytest and I am having trouble trying to run pytests with iio-emu locally. It looks like pytest is not starting iio-emu on my setup for it was failing with "Exception: No device found" and "Connection timed out".

The launch command was

pytest -vs --emu --emu-xml-dir=test/emu/devices/ --junitxml="results.xml" -k 'not prod' test/test_adaq4003.py

I updated and reinstalled libtinyiiod, iio-emu, and pyadi-iio, but the issue was not solved so I reverted the offending patch.