22#
33# SPDX short identifier: ADIBSD
44
5+ from decimal import Decimal
6+
57import numpy as np
68
9+ from adi .attribute import attribute
710from adi .context_manager import context_manager
811from adi .rx_tx import rx
912
@@ -17,10 +20,11 @@ class ad4020(rx, context_manager):
1720 "ad4022" ,
1821 ]
1922
23+ channel = []
2024 _device_name = ""
2125 _rx_data_type = np .int32
2226 _complex_data = False
23- _rx_channel_names = ["voltage0" ]
27+ _rx_channel_names = ["voltage0-voltage1 " ]
2428
2529 def __init__ (self , uri = "" , device_name = "ad4020" ):
2630 if not device_name :
@@ -34,17 +38,44 @@ def __init__(self, uri="", device_name="ad4020"):
3438
3539 self ._rxadc = self ._ctx .find_device (_device_name )
3640 self ._ctrl = self ._ctx .find_device (_device_name )
41+ self .channel = []
42+ for ch in self ._ctrl .channels :
43+ name = ch ._id
44+ self ._rx_channel_names .append (name )
45+ self .channel .append (self ._channel (self ._ctrl , name ))
3746 rx .__init__ (self )
3847
39- @property
40- def sampling_frequency (self ):
41- """Get and set the sampling frequency."""
42- return self ._get_iio_dev_attr ("sampling_frequency" )
48+ class _channel (attribute ):
49+ """AD4020 channel"""
50+
51+ def __init__ (self , ctrl , channel_name ):
52+ self .name = channel_name
53+ self ._ctrl = ctrl
54+
55+ @property
56+ def raw (self ):
57+ """AD4020 channel raw value"""
58+ return self ._get_iio_attr (self .name , "raw" , False )
59+
60+ @property
61+ def scale (self ):
62+ """AD4020 channel scale"""
63+ return float (self ._get_iio_attr_str (self .name , "scale" , False ))
64+
65+ @scale .setter
66+ def scale (self , value ):
67+ self ._set_iio_attr (self .name , "scale" , False , str (Decimal (value ).real ))
4368
44- @sampling_frequency .setter
45- def sampling_frequency (self , value ):
46- """Set the sampling frequency."""
47- self ._set_iio_dev_attr ("sampling_frequency" , str (value ))
69+ @property
70+ def sampling_frequency (self ):
71+ """Get and set the sampling frequency."""
72+ return self ._get_iio_attr (self .name , "sampling_frequency" , False )
73+
74+ @sampling_frequency .setter
75+ def sampling_frequency (self , value ):
76+ """Set the sampling frequency."""
77+ # self._set_iio_attr("sampling_frequency", str(value))
78+ self ._set_iio_attr (self .name , "sampling_frequency" , False , value )
4879
4980
5081class ad4000 (ad4020 ):
@@ -54,7 +85,8 @@ class ad4000(ad4020):
5485 "ad4008" ,
5586 ]
5687
57- _rx_data_type = np .int16
88+ _rx_channel_names = ["voltage0" ]
89+ _rx_data_type = np .uint16
5890
5991 def __init__ (self , uri = "ip:analog.local" , device_name = "ad4000" ):
6092 super ().__init__ (uri , device_name )
@@ -79,7 +111,8 @@ class ad4002(ad4020):
79111 "ad4010" ,
80112 ]
81113
82- _rx_data_type = np .int32
114+ _rx_channel_names = ["voltage0" ]
115+ _rx_data_type = np .uint32
83116
84117 def __init__ (self , uri = "ip:analog.local" , device_name = "ad4002" ):
85118 super ().__init__ (uri , device_name )
0 commit comments