diff --git a/ohmpi/hardware_components/abstract_hardware_components.py b/ohmpi/hardware_components/abstract_hardware_components.py index 27308832c6e9e7d1058368b7bbf47baab470b2f7..6aa90ef2d8ea14aa075357f24e458a311c76d9f3 100644 --- a/ohmpi/hardware_components/abstract_hardware_components.py +++ b/ohmpi/hardware_components/abstract_hardware_components.py @@ -289,7 +289,7 @@ class TxAbstract(ABC): pass @abstractmethod - def inject(self, polarity=1, injection_duration=None): + def inject(self, polarity=1, injection_duration=None, switch_pwr=False): """ Abstract method to define injection Parameters @@ -303,15 +303,20 @@ class TxAbstract(ABC): if injection_duration is None: injection_duration = self._injection_duration if np.abs(polarity) > 0: - self.pwr.turn_on() + if switch_pwr: + self.pwr.turn_on() self.tx_sync.set() time.sleep(injection_duration) - self.pwr.turn_off() + self.tx_sync.clear() + if switch_pwr: + self.pwr.turn_off() else: self.tx_sync.set() - self.pwr.turn_off() + if switch_pwr: + self.pwr.turn_off() time.sleep(injection_duration) - self.tx_sync.clear() + self.tx_sync.clear() + @property def injection_duration(self): diff --git a/ohmpi/hardware_components/mb_2023_0_X.py b/ohmpi/hardware_components/mb_2023_0_X.py index f6a47d9353d278979ad88416007a6f034c72b282..4269fd5497ebc348fa67cfcac90d355058794b1b 100644 --- a/ohmpi/hardware_components/mb_2023_0_X.py +++ b/ohmpi/hardware_components/mb_2023_0_X.py @@ -10,6 +10,7 @@ import numpy as np import os from ohmpi.hardware_components import TxAbstract, RxAbstract from ohmpi.utils import enforce_specs +import inspect # hardware characteristics and limitations # voltages are given in mV, currents in mA, sampling rates in Hz and data_rate in S/s @@ -36,6 +37,7 @@ SPECS = {'rx': {'sampling_rate': {'min': 2., 'default': 10., 'max': 100.}, # TODO: move low_battery spec in pwr + def _ads_1115_gain_auto(channel): # Make it a class method ? """Automatically sets the gain on a channel @@ -161,7 +163,10 @@ class Tx(TxAbstract): def polarity(self, polarity): assert polarity in [-1, 0, 1] self._polarity = polarity - print(f'asserted polarity: {self.polarity}') + # debugging code + curframe = inspect.currentframe() + calframe = inspect.getouterframes(curframe, 2) + print(f'polarity called from: {calframe}') if polarity == 1: print('pin0') diff --git a/ohmpi/hardware_components/mb_2024_0_2.py b/ohmpi/hardware_components/mb_2024_0_2.py index e8e64de60e71a454572bfb4da8ce6ec4184c4415..0278228fd9d5e2c17325a63a858a03ad7e1d2efb 100644 --- a/ohmpi/hardware_components/mb_2024_0_2.py +++ b/ohmpi/hardware_components/mb_2024_0_2.py @@ -33,6 +33,7 @@ SPECS = {'rx': {'sampling_rate': {'min': 2., 'default': 10., 'max': 100.}, # TODO: move low_battery spec in pwr + def _ads_1115_gain_auto(channel): # Make it a class method ? """Automatically sets the gain on a channel @@ -124,7 +125,6 @@ class Rx(Rx_mb_2023): self.pin_DG1.value = True # closed gain 1 active self.pin_DG2.value = False # open gain 0.5 inactive - def gain_auto(self): self._dg411_gain_auto() diff --git a/ohmpi/hardware_system.py b/ohmpi/hardware_system.py index 214729f9aa2e806240ddf0e243407ed2582e5f6d..798450102dde12234878b438935b634ce3df8446 100644 --- a/ohmpi/hardware_system.py +++ b/ohmpi/hardware_system.py @@ -178,13 +178,13 @@ class OhmPiHardware: rx_gains = [] for pol in polarities: # self.tx.polarity = pol - # self.tx_sync.wait() # set gains automatically injection = Thread(target=self._inject, kwargs={'injection_duration': 0.2, 'polarity': pol}) # readings = Thread(target=self._read_values) get_tx_gain = Thread(target=self.tx.gain_auto) get_rx_gain = Thread(target=self.rx.gain_auto) injection.start() + self.tx_sync.wait() get_tx_gain.start() # TODO: add a barrier to synchronize? get_rx_gain.start() get_tx_gain.join() @@ -404,7 +404,7 @@ class OhmPiHardware: assert 0. <= duty_cycle <= 1. if duty_cycle < 1.: durations = [cycle_duration/2 * duty_cycle, cycle_duration/2*(1.-duty_cycle)] * 2 * cycles - pol = [-int(1. * np.heaviside(i % 2, -1.)) for i in range(2 * cycles)] + pol = [-int(polarity * np.heaviside(i % 2, -1.)) for i in range(2 * cycles)] # pol = [-int(self.tx.polarity * np.heaviside(i % 2, -1.)) for i in range(2 * cycles)] polarities = [0] * (len(pol) * 2) polarities[0::2] = pol