diff --git a/adi/ad4020.py b/adi/ad4020.py
index 20d37ae9b..4c25924ae 100644
--- a/adi/ad4020.py
+++ b/adi/ad4020.py
@@ -4,6 +4,7 @@
import numpy as np
+from adi.attribute import attribute
from adi.context_manager import context_manager
from adi.rx_tx import rx
@@ -17,6 +18,7 @@ class ad4020(rx, context_manager):
"ad4022",
]
+ channel = []
_device_name = ""
_rx_data_type = np.int32
_complex_data = False
@@ -34,18 +36,44 @@ def __init__(self, uri="", device_name="ad4020"):
self._rxadc = self._ctx.find_device(_device_name)
self._ctrl = self._ctx.find_device(_device_name)
+ self.channel = []
+ for ch in self._ctrl.channels:
+ name = ch._id
+ self._rx_channel_names.append(name)
+ self.channel.append(self._channel(self._ctrl, name))
rx.__init__(self)
- @property
- def sampling_frequency(self):
- """Get and set the sampling frequency."""
- return self._get_iio_dev_attr("sampling_frequency")
-
- @sampling_frequency.setter
- def sampling_frequency(self, value):
- """Set the sampling frequency."""
- self._set_iio_dev_attr("sampling_frequency", str(value))
-
+ class _channel(attribute):
+ """AD4020 channel"""
+
+ def __init__(self, ctrl, channel_name):
+ self.name = channel_name
+ self._ctrl = ctrl
+
+ @property
+ def raw(self):
+ """AD4020 channel raw value"""
+ return self._get_iio_attr(self.name, "raw", False)
+
+ @property
+ def scale(self):
+ """AD4020 channel scale"""
+ return float(self._get_iio_attr_str(self.name, "scale", False))
+
+ @scale.setter
+ def scale(self, value):
+ self._set_iio_attr(self.name, "scale", False, str(Decimal(value).real))
+
+ @property
+ def sampling_frequency(self):
+ """Get and set the sampling frequency."""
+ return self._get_iio_attr(self.name, "sampling_frequency", False)
+
+ @sampling_frequency.setter
+ def sampling_frequency(self, value):
+ """Set the sampling frequency."""
+ #self._set_iio_attr("sampling_frequency", str(value))
+ self._set_iio_attr(self.name, "sampling_frequency", False, value)
class ad4000(ad4020):
_compatible_parts = [
diff --git a/test/emu/devices/ad4000.xml b/test/emu/devices/ad4000.xml
index 7eb66773e..7a11f0611 100644
--- a/test/emu/devices/ad4000.xml
+++ b/test/emu/devices/ad4000.xml
@@ -1 +1 @@
-]>
+]>
\ No newline at end of file
diff --git a/test/test_ad4000.py b/test/test_ad4000.py
index af895254a..7e2a4371a 100644
--- a/test/test_ad4000.py
+++ b/test/test_ad4000.py
@@ -8,16 +8,22 @@
@pytest.mark.iio_hardware(hardware)
@pytest.mark.parametrize("classname", [(classname)])
@pytest.mark.parametrize(
- "attr, val",
+ "attr, val, tol, repeats, sleep, sub_channel",
[
(
"sampling_frequency",
[10000, 50000, 100000, 200000, 500000, 1000000, 2000000],
+ 1,
+ 1,
+ 0,
+ "_channel",
),
],
)
-def test_ad4000_attr(test_attribute_multiple_values, iio_uri, classname, attr, val):
- test_attribute_multiple_values(iio_uri, classname, attr, val, 1)
+def test_ad4000_attr(test_attribute_multiple_values, iio_uri, classname, attr,
+ val, tol, repeats, sleep, sub_channel):
+ test_attribute_multiple_values(iio_uri, classname, attr, val, 1, repeats,
+ sleep, sub_channel)
#########################################
diff --git a/test/test_ad4001.py b/test/test_ad4001.py
index b48938e2d..db00d6f8a 100644
--- a/test/test_ad4001.py
+++ b/test/test_ad4001.py
@@ -8,16 +8,22 @@
@pytest.mark.iio_hardware(hardware)
@pytest.mark.parametrize("classname", [(classname)])
@pytest.mark.parametrize(
- "attr, val",
+ "attr, val, tol, repeats, sleep, sub_channel",
[
(
"sampling_frequency",
[10000, 50000, 100000, 200000, 500000, 1000000, 2000000],
+ 1,
+ 1,
+ 0,
+ "_channel",
),
],
)
-def test_ad4001_attr(test_attribute_multiple_values, iio_uri, classname, attr, val):
- test_attribute_multiple_values(iio_uri, classname, attr, val, 1)
+def test_ad4001_attr(test_attribute_multiple_values, iio_uri, classname, attr,
+ val, tol, repeats, sleep, sub_channel):
+ test_attribute_multiple_values(iio_uri, classname, attr, val, 1, repeats,
+ sleep, sub_channel)
#########################################
diff --git a/test/test_ad4002.py b/test/test_ad4002.py
index 74ef2d9a4..16286ea0d 100644
--- a/test/test_ad4002.py
+++ b/test/test_ad4002.py
@@ -8,16 +8,22 @@
@pytest.mark.iio_hardware(hardware)
@pytest.mark.parametrize("classname", [(classname)])
@pytest.mark.parametrize(
- "attr, val",
+ "attr, val, tol, repeats, sleep, sub_channel",
[
(
"sampling_frequency",
[10000, 50000, 100000, 200000, 500000, 1000000, 2000000],
+ 1,
+ 1,
+ 0,
+ "_channel",
),
],
)
-def test_ad4002_attr(test_attribute_multiple_values, iio_uri, classname, attr, val):
- test_attribute_multiple_values(iio_uri, classname, attr, val, 1)
+def test_ad4002_attr(test_attribute_multiple_values, iio_uri, classname, attr,
+ val, tol, repeats, sleep, sub_channel):
+ test_attribute_multiple_values(iio_uri, classname, attr, val, 1, repeats,
+ sleep, sub_channel)
#########################################
diff --git a/test/test_ad4003.py b/test/test_ad4003.py
index b99ebae4c..c9e40025f 100644
--- a/test/test_ad4003.py
+++ b/test/test_ad4003.py
@@ -8,16 +8,22 @@
@pytest.mark.iio_hardware(hardware)
@pytest.mark.parametrize("classname", [(classname)])
@pytest.mark.parametrize(
- "attr, val",
+ "attr, val, tol, repeats, sleep, sub_channel",
[
(
"sampling_frequency",
[10000, 50000, 100000, 200000, 500000, 1000000, 2000000],
+ 1,
+ 1,
+ 0,
+ "_channel",
),
],
)
-def test_ad4003_attr(test_attribute_multiple_values, iio_uri, classname, attr, val):
- test_attribute_multiple_values(iio_uri, classname, attr, val, 1)
+def test_ad4003_attr(test_attribute_multiple_values, iio_uri, classname, attr,
+ val, tol, repeats, sleep, sub_channel):
+ test_attribute_multiple_values(iio_uri, classname, attr, val, 1, repeats,
+ sleep, sub_channel)
#########################################