diff --git a/adi/ad4020.py b/adi/ad4020.py index 1ffa7cd01..2f52f63f5 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""" @@ -51,6 +64,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)) @@ -73,6 +87,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))