|
| 1 | +# Copyright (C) 2025-2026 Analog Devices, Inc. |
| 2 | +# |
| 3 | +# SPDX short identifier: ADIBSD |
| 4 | + |
| 5 | + |
| 6 | +from adi.attribute import attribute |
| 7 | +from adi.context_manager import context_manager |
| 8 | + |
| 9 | + |
| 10 | +class hmc7044(context_manager, attribute): |
| 11 | + """ |
| 12 | + hmc7044 IIO Device Interface |
| 13 | + This class provides a Python interface for interacting with the HMC7044 |
| 14 | + device via the Industrial I/O (IIO) framework. |
| 15 | + It allows users to access and modify device and channel attributes, as well |
| 16 | + as perform device-specific operations. |
| 17 | +
|
| 18 | + Attributes: |
| 19 | + mute_request (str): Get or set the mute request state of the device. |
| 20 | + reseed_request (str): Get or set the reseed request state of the device. |
| 21 | + reset_dividers_request (str): Get or set the reset dividers request state of the device. |
| 22 | + sleep_request (str): Get or set the sleep request state of the device. |
| 23 | + sync_pin_mode (str): Get or set the synchronization pin mode. |
| 24 | + sync_pin_mode_available (str): Get the available synchronization pin modes. |
| 25 | + sysref_request (str): Get or set the SYSREF request state of the device. |
| 26 | + status (str): Get the debug status of the device. |
| 27 | +
|
| 28 | + Channel Attributes (dynamically added per channel): |
| 29 | + <channel_label>_frequency (int): Get or set the frequency for the specified channel. |
| 30 | + <channel_label>_label (str): Get or set the label for the specified channel. |
| 31 | + <channel_label>_phase (int): Get or set the phase for the specified channel. |
| 32 | +
|
| 33 | + Args: |
| 34 | + uri (str, optional): URI of the IIO context. Defaults to "". |
| 35 | +
|
| 36 | + Raises: |
| 37 | + Exception: If the HMC7044 device is not found in the IIO context. |
| 38 | +
|
| 39 | + Usage Example: |
| 40 | + dev = hmc7044("ip:192.168.2.1") |
| 41 | + print(dev.status) |
| 42 | + dev.mute_request = "1" |
| 43 | + print(dev.altvoltage0_frequency) |
| 44 | + """ |
| 45 | + |
| 46 | + _device_name = "hmc7044" |
| 47 | + |
| 48 | + def __init__(self, uri=""): |
| 49 | + context_manager.__init__(self, uri, self._device_name) |
| 50 | + self._ctrl = self._ctx.find_device(self._device_name) |
| 51 | + if not self._ctrl: |
| 52 | + raise Exception("hmc7044 device not found") |
| 53 | + self._add_channel_properties() |
| 54 | + |
| 55 | + def _make_channel_property(self, channel, attr): |
| 56 | + def getter(self): |
| 57 | + return self._get_iio_attr(channel, attr, True, self._ctrl) |
| 58 | + |
| 59 | + def setter(self, value): |
| 60 | + self._set_iio_attr(channel, attr, True, value, self._ctrl) |
| 61 | + |
| 62 | + return property(getter, setter) |
| 63 | + |
| 64 | + # Device attributes |
| 65 | + @property |
| 66 | + def mute_request(self): |
| 67 | + return self._get_iio_dev_attr("mute_request", self._ctrl) |
| 68 | + |
| 69 | + @mute_request.setter |
| 70 | + def mute_request(self, value): |
| 71 | + self._set_iio_dev_attr("mute_request", value, self._ctrl) |
| 72 | + |
| 73 | + @property |
| 74 | + def reseed_request(self): |
| 75 | + return self._get_iio_dev_attr("reseed_request", self._ctrl) |
| 76 | + |
| 77 | + @reseed_request.setter |
| 78 | + def reseed_request(self, value): |
| 79 | + self._set_iio_dev_attr("reseed_request", value, self._ctrl) |
| 80 | + |
| 81 | + @property |
| 82 | + def reset_dividers_request(self): |
| 83 | + return self._get_iio_dev_attr("reset_dividers_request", self._ctrl) |
| 84 | + |
| 85 | + @reset_dividers_request.setter |
| 86 | + def reset_dividers_request(self, value): |
| 87 | + self._set_iio_dev_attr("reset_dividers_request", value, self._ctrl) |
| 88 | + |
| 89 | + @property |
| 90 | + def sleep_request(self): |
| 91 | + return self._get_iio_dev_attr("sleep_request", self._ctrl) |
| 92 | + |
| 93 | + @sleep_request.setter |
| 94 | + def sleep_request(self, value): |
| 95 | + self._set_iio_dev_attr("sleep_request", value, self._ctrl) |
| 96 | + |
| 97 | + @property |
| 98 | + def sync_pin_mode(self): |
| 99 | + return self._get_iio_dev_attr_str("sync_pin_mode", self._ctrl) |
| 100 | + |
| 101 | + @sync_pin_mode.setter |
| 102 | + def sync_pin_mode(self, value): |
| 103 | + self._set_iio_dev_attr_str("sync_pin_mode", value, self._ctrl) |
| 104 | + |
| 105 | + @property |
| 106 | + def sync_pin_mode_available(self): |
| 107 | + return self._get_iio_dev_attr_str("sync_pin_mode_available", self._ctrl) |
| 108 | + |
| 109 | + @property |
| 110 | + def sysref_request(self): |
| 111 | + return self._get_iio_dev_attr("sysref_request", self._ctrl) |
| 112 | + |
| 113 | + @sysref_request.setter |
| 114 | + def sysref_request(self, value): |
| 115 | + self._set_iio_dev_attr("sysref_request", value, self._ctrl) |
| 116 | + |
| 117 | + # Debug attribute |
| 118 | + @property |
| 119 | + def status(self): |
| 120 | + return self._get_iio_debug_attr_str("status", self._ctrl) |
| 121 | + |
| 122 | + # Channel attributes |
| 123 | + _channel_attrs = ["frequency", "label", "phase"] |
| 124 | + |
| 125 | + def _add_channel_properties(self): |
| 126 | + for ch in self._ctrl.channels: |
| 127 | + if not ch._id.startswith("altvoltage"): |
| 128 | + continue |
| 129 | + |
| 130 | + if "label" in ch.attrs: |
| 131 | + name = ch.attrs["label"].value |
| 132 | + else: |
| 133 | + name = ch._id |
| 134 | + |
| 135 | + for attr in self._channel_attrs: |
| 136 | + prop_name = f"{name}_{attr}" |
| 137 | + setattr( |
| 138 | + self.__class__, prop_name, self._make_channel_property(ch._id, attr) |
| 139 | + ) |
0 commit comments