Commit eef78c8e authored by Olivier Kaufmann's avatar Olivier Kaufmann
Browse files

Moves tx_sync.set in TxAbstract.inject

Showing with 15 additions and 10 deletions
+15 -10
...@@ -3,7 +3,7 @@ from abc import ABC, abstractmethod ...@@ -3,7 +3,7 @@ from abc import ABC, abstractmethod
import numpy as np import numpy as np
from ohmpi.logging_setup import create_stdout_logger from ohmpi.logging_setup import create_stdout_logger
import time import time
from threading import Barrier, BrokenBarrierError from threading import Event, Barrier, BrokenBarrierError
class CtlAbstract(ABC): class CtlAbstract(ABC):
...@@ -115,7 +115,7 @@ class MuxAbstract(ABC): ...@@ -115,7 +115,7 @@ class MuxAbstract(ABC):
self.cabling = {} self.cabling = {}
if cabling is not None: if cabling is not None:
for k, v in cabling.items(): for k, v in cabling.items():
if v[0]==self.board_id: if v[0] == self.board_id:
self.cabling.update({k: (v[1], k[1])}) self.cabling.update({k: (v[1], k[1])})
self.exec_logger.debug(f'{self.board_id} cabling: {self.cabling}') self.exec_logger.debug(f'{self.board_id} cabling: {self.cabling}')
self.addresses = kwargs.pop('addresses', None) self.addresses = kwargs.pop('addresses', None)
...@@ -168,7 +168,8 @@ class MuxAbstract(ABC): ...@@ -168,7 +168,8 @@ class MuxAbstract(ABC):
# check that none of M or N are the same as A or B # check that none of M or N are the same as A or B
# as to prevent burning the MN part which cannot take # as to prevent burning the MN part which cannot take
# the full voltage of the DPS # the full voltage of the DPS
if 'A' in elec_dict.keys() and 'B' in elec_dict.keys() and 'M' in elec_dict.keys() and 'N' in elec_dict.keys(): if 'A' in elec_dict.keys() and 'B' in elec_dict.keys() and 'M' in elec_dict.keys() \
and 'N' in elec_dict.keys():
if bypass_check: if bypass_check:
self.exec_logger.debug(f'Bypassing :{bypass_check}') self.exec_logger.debug(f'Bypassing :{bypass_check}')
elif (np.in1d(elec_dict['M'], elec_dict['A']).any() # noqa elif (np.in1d(elec_dict['M'], elec_dict['A']).any() # noqa
...@@ -250,6 +251,7 @@ class TxAbstract(ABC): ...@@ -250,6 +251,7 @@ class TxAbstract(ABC):
self._inj_time = None self._inj_time = None
self._adc_gain = 1. self._adc_gain = 1.
self.inj_time = inj_time self.inj_time = inj_time
self.tx_sync = kwargs.pop('tx_sync', Event())
self.exec_logger.debug(f'{self.board_name} TX initialization') self.exec_logger.debug(f'{self.board_name} TX initialization')
@property @property
...@@ -271,16 +273,19 @@ class TxAbstract(ABC): ...@@ -271,16 +273,19 @@ class TxAbstract(ABC):
@abstractmethod @abstractmethod
def inject(self, polarity=1, inj_time=None): def inject(self, polarity=1, inj_time=None):
assert polarity in [-1,0,1] assert polarity in [-1, 0, 1]
if inj_time is None: if inj_time is None:
inj_time = self._inj_time inj_time = self._inj_time
if np.abs(polarity) > 0: if np.abs(polarity) > 0:
self.pwr.turn_on() self.pwr.turn_on()
self.tx_sync.set()
time.sleep(inj_time) time.sleep(inj_time)
self.pwr.turn_off() self.pwr.turn_off()
else: else:
self.tx_sync.set()
self.pwr.turn_off() self.pwr.turn_off()
time.sleep(inj_time) time.sleep(inj_time)
self.tx_sync.clear()
@property @property
def inj_time(self): def inj_time(self):
...@@ -347,7 +352,6 @@ class RxAbstract(ABC): ...@@ -347,7 +352,6 @@ class RxAbstract(ABC):
def adc_gain(self): def adc_gain(self):
return self._adc_gain return self._adc_gain
@adc_gain.setter @adc_gain.setter
def adc_gain(self, value): def adc_gain(self, value):
self._adc_gain = value self._adc_gain = value
...@@ -376,4 +380,4 @@ class RxAbstract(ABC): ...@@ -376,4 +380,4 @@ class RxAbstract(ABC):
def voltage(self): def voltage(self):
""" Gets the voltage VMN in Volts """ Gets the voltage VMN in Volts
""" """
pass pass
\ No newline at end of file
...@@ -108,7 +108,7 @@ class Tx(TxAbstract): ...@@ -108,7 +108,7 @@ class Tx(TxAbstract):
self.polarity = 0 self.polarity = 0
self.adc_gain = 2 / 3 self.adc_gain = 2 / 3
self.pwr = None self.pwr = None # TODO: set a list of compatible power system with the tx
# I2C connexion to MCP23008, for current injection # I2C connexion to MCP23008, for current injection
self.pin4 = self.mcp_board.get_pin(4) # Ohmpi_run self.pin4 = self.mcp_board.get_pin(4) # Ohmpi_run
...@@ -202,7 +202,7 @@ class Tx(TxAbstract): ...@@ -202,7 +202,7 @@ class Tx(TxAbstract):
Polarity of the pulse Polarity of the pulse
""" """
self.exec_logger.event(f'{self.board_name}\ttx_voltage_pulse\tbegin\t{datetime.datetime.utcnow()}') self.exec_logger.event(f'{self.board_name}\ttx_voltage_pulse\tbegin\t{datetime.datetime.utcnow()}')
self.exec_logger.info(f'inj_time: {length}') # TODO: delete me # self.exec_logger.info(f'inj_time: {length}') # TODO: delete me
if length is None: if length is None:
length = self.inj_time length = self.inj_time
self.pwr.voltage = voltage self.pwr.voltage = voltage
......
...@@ -89,6 +89,7 @@ class OhmPiHardware: ...@@ -89,6 +89,7 @@ class OhmPiHardware:
self.pwr = kwargs.pop('pwr', pwr_module.Pwr(**HARDWARE_CONFIG['pwr'])) self.pwr = kwargs.pop('pwr', pwr_module.Pwr(**HARDWARE_CONFIG['pwr']))
HARDWARE_CONFIG['tx'].pop('model') HARDWARE_CONFIG['tx'].pop('model')
HARDWARE_CONFIG['tx'].update(**HARDWARE_CONFIG['tx']) HARDWARE_CONFIG['tx'].update(**HARDWARE_CONFIG['tx'])
HARDWARE_CONFIG['tx'].update({'tx_sync': self.tx_sync})
HARDWARE_CONFIG['tx'].update({'ctl': self.ctl}) HARDWARE_CONFIG['tx'].update({'ctl': self.ctl})
HARDWARE_CONFIG['tx'].update({'exec_logger': self.exec_logger, 'data_logger': self.data_logger, HARDWARE_CONFIG['tx'].update({'exec_logger': self.exec_logger, 'data_logger': self.data_logger,
'soh_logger': self.soh_logger}) 'soh_logger': self.soh_logger})
...@@ -146,9 +147,9 @@ class OhmPiHardware: ...@@ -146,9 +147,9 @@ class OhmPiHardware:
def _inject(self, polarity=1, inj_time=None): # TODO: deal with voltage or current pulse def _inject(self, polarity=1, inj_time=None): # TODO: deal with voltage or current pulse
self.exec_logger.event(f'OhmPiHardware\tinject\tbegin\t{datetime.datetime.utcnow()}') self.exec_logger.event(f'OhmPiHardware\tinject\tbegin\t{datetime.datetime.utcnow()}')
self.tx_sync.set() # self.tx_sync.set()
self.tx.voltage_pulse(length=inj_time, polarity=polarity) self.tx.voltage_pulse(length=inj_time, polarity=polarity)
self.tx_sync.clear() # self.tx_sync.clear()
self.exec_logger.event(f'OhmPiHardware\tinject\tend\t{datetime.datetime.utcnow()}') self.exec_logger.event(f'OhmPiHardware\tinject\tend\t{datetime.datetime.utcnow()}')
def _set_mux_barrier(self): def _set_mux_barrier(self):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment