diff --git a/adi/rx_tx.py b/adi/rx_tx.py index e9e1b23b0..2ed84cb3a 100644 --- a/adi/rx_tx.py +++ b/adi/rx_tx.py @@ -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 @@ -432,6 +432,15 @@ 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) + self._tx_data_type = np.dtype(fmt).type + if not self.__tx_enabled_channels and data_np: raise Exception( "When tx_enabled_channels is None or empty," @@ -464,8 +473,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: @@ -478,7 +487,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: