diff --git a/adi/ad4020.py b/adi/ad4020.py index 1ffa7cd01..6a9682014 100644 --- a/adi/ad4020.py +++ b/adi/ad4020.py @@ -10,6 +10,19 @@ from adi.rx_tx import rx +def reset_buffer(func): + """Wrapper for set calls that require device configuration. + Without disabling the buffer, direct access will return -EBUSY + """ + + def wrapper(*args, **kwargs): + if args[0]._reset_on_spi_writes: + args[0].rx_destroy_buffer() + func(*args, **kwargs) + + return wrapper + + class ad4020(rx, context_manager): """AD4000 series of differential SAR ADC device""" @@ -23,6 +36,7 @@ class ad4020(rx, context_manager): _rx_data_type = np.int32 _complex_data = False _rx_channel_names = ["voltage0"] + _reset_on_spi_writes = True def __init__(self, uri="", device_name="ad4020"): if not device_name: @@ -51,6 +65,7 @@ def sampling_frequency(self): return self._get_iio_dev_attr("sampling_frequency") @sampling_frequency.setter + @reset_buffer def sampling_frequency(self, value): """Set the sampling frequency.""" self._set_iio_dev_attr("sampling_frequency", str(value)) @@ -58,6 +73,8 @@ def sampling_frequency(self, value): class _channel_adc(attribute): """AD4000 series differential input voltage channel""" + _reset_on_spi_writes = True + # AD4000 series ADC channel def __init__(self, ctrl, channel_name, output): self.name = channel_name @@ -73,6 +90,7 @@ def scale(self): return float(self._get_iio_attr_str(self.name, "scale", self._output)) @scale.setter + @reset_buffer def scale(self, value): self._set_iio_attr(self.name, "scale", False, str(Decimal(value).real))