Skip to content

Commit

Permalink
Merge pull request #498 from analogdevicesinc/tfcollins/dac-auto-type
Browse files Browse the repository at this point in the history
Tfcollins/dac auto type
  • Loading branch information
tfcollins authored Nov 17, 2023
2 parents a7c267c + fc60431 commit 2edc0a4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
18 changes: 14 additions & 4 deletions adi/rx_tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ class tx(dds, rx_tx_common):
_txdac: iio.Device = []
_tx_channel_names: List[str] = []
_complex_data = False
_tx_data_type = np.int16
_tx_data_type = None
__txbuf = None
_output_byte_filename = "out.bin"
_push_to_file = False
Expand Down Expand Up @@ -432,6 +432,16 @@ def tx(self, data_np=None):
is enabled containing samples from a channel or set of channels.
Data must be complex when using a complex data device.
"""

if not self._tx_data_type:
# Find channel data format
chan_name = self._tx_channel_names[self.tx_enabled_channels[0]]
chan = self._txdac.find_channel(chan_name, True)
df = chan.data_format
fmt = ("i" if df.is_signed is True else "u") + str(df.length // 8)
fmt = ">" + fmt if df.is_be else fmt
self._tx_data_type = np.dtype(fmt)

if not self.__tx_enabled_channels and data_np:
raise Exception(
"When tx_enabled_channels is None or empty,"
Expand Down Expand Up @@ -464,8 +474,8 @@ def tx(self, data_np=None):
for chan in data_np:
i = np.real(chan)
q = np.imag(chan)
data[indx::stride] = i.astype(int)
data[indx + 1 :: stride] = q.astype(int)
data[indx::stride] = i.astype(self._tx_data_type)
data[indx + 1 :: stride] = q.astype(self._tx_data_type)
indx = indx + 2
else:
if self._num_tx_channels_enabled == 1:
Expand All @@ -478,7 +488,7 @@ def tx(self, data_np=None):
stride = self._num_tx_channels_enabled
data = np.empty(stride * len(data_np[0]), dtype=self._tx_data_type)
for chan in data_np:
data[indx::stride] = chan.astype(int)
data[indx::stride] = chan.astype(self._tx_data_type)
indx = indx + 1

if not self.__txbuf:
Expand Down
1 change: 1 addition & 0 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ def checkparts(c):
"ad469x",
"ad777x",
"ad578x",
"adaq42xx",
]
for c in dir(mod):
if (
Expand Down

0 comments on commit 2edc0a4

Please sign in to comment.