diff --git a/configs/config_mb_2023_3_mux_2024.py b/configs/config_mb_2023_3_mux_2024.py index 680aba50f51187d814024c9be3392f41ced24b48..a4134e6d9321c52512c706cee7439d4b63073d7e 100644 --- a/configs/config_mb_2023_3_mux_2024.py +++ b/configs/config_mb_2023_3_mux_2024.py @@ -63,7 +63,8 @@ HARDWARE_CONFIG = { 'cabling': {(i+24, j): ('mux_04', i) for j in ['A', 'B', 'M', 'N'] for i in range(1, 9)}, 'voltage_max': 12.} }, - 'default': {'voltage_max': 100., + 'default': {'connection': 'i2c', + 'voltage_max': 100., 'current_max': 3.} } } diff --git a/configs/config_mb_2023_4_mux_2023.py b/configs/config_mb_2023_4_mux_2023.py index 6546b1182618ac31559ee8b2566a586092e4ab16..0c0309a29718a650f1eb684a012ee1f440bcf9e6 100644 --- a/configs/config_mb_2023_4_mux_2023.py +++ b/configs/config_mb_2023_4_mux_2023.py @@ -18,7 +18,7 @@ OHMPI_CONFIG = { } HARDWARE_CONFIG = { - 'ctl': {'model': 'raspberry_pi_i2c'}, + 'ctl': {'model': 'raspberry_pi'}, 'pwr': {'model': 'pwr_batt', 'voltage': 12.}, 'tx': {'model': 'ohmpi_card_3_15', 'mcp_board_address': 0x20, @@ -59,7 +59,8 @@ HARDWARE_CONFIG = { 'cabling': {(i, j): ('mux_4', i) for j in ['N'] for i in range(1, 65)}, 'voltage_max': 12.}, }, - 'default': {'voltage_max': 100., + 'default': {'connection': 'i2c', + 'voltage_max': 100., 'current_max': 3.} } } diff --git a/ohmpi/hardware_components/mux_2023_rev_0_0.py b/ohmpi/hardware_components/mux_2023_rev_0_0.py index 63f1f4fd020778cf6947228bc82baa9a8a042e6a..a9012710a904201c2cd2c38ab9bbc4a82ee17de4 100644 --- a/ohmpi/hardware_components/mux_2023_rev_0_0.py +++ b/ohmpi/hardware_components/mux_2023_rev_0_0.py @@ -71,7 +71,8 @@ class Mux(MuxAbstract): else: self.exec_logger.error(f'Invalid role assignment for {self.board_name}: {self._roles} !') self._mode = '' - self._tca = [adafruit_tca9548a.TCA9548A(self.ctl.bus, tca_address)[i] for i in np.arange(7, 3, -1)] + self.io = self.ctl.connections[MUX_CONFIG['connection']] + self._tca = [adafruit_tca9548a.TCA9548A(self.io, tca_address)[i] for i in np.arange(7, 3, -1)] # self._mcp_addresses = (kwargs.pop('mcp', '0x20')) # TODO: add assert on valid addresses.. self._mcp = [None, None, None, None] self.reset() diff --git a/ohmpi/hardware_components/mux_2024_rev_0_0.py b/ohmpi/hardware_components/mux_2024_rev_0_0.py index 470c3c1c9db79272a131f89d13222a126971f4a9..f2544dd4935084daeef5abdf7ca7f79a3a4972df 100644 --- a/ohmpi/hardware_components/mux_2024_rev_0_0.py +++ b/ohmpi/hardware_components/mux_2024_rev_0_0.py @@ -12,7 +12,7 @@ MUX_CONFIG.update({'voltage_max': 50., 'current_max': 3.}) # board default valu MUX_CONFIG.update({'activation_delay': 0.01, 'release_delay': 0.005}) # s # defaults to 4 roles cabling electrodes from 1 to 8 default_mux_cabling = {(elec, role) : ('mux_1', elec) for role in ['A', 'B', 'M', 'N'] for elec in range(1,9)} -# defaults to i2c connection +# defaults to ic connection ctl_connection = HARDWARE_CONFIG['ctl'].pop('connection', 'i2c') inner_cabling = {'4_roles' : {(1, 'X'): {'MCP': 0, 'MCP_GPIO': 0}, (1, 'Y'): {'MCP': 0, 'MCP_GPIO': 8}, @@ -76,10 +76,11 @@ class Mux(MuxAbstract): else: self.exec_logger.error(f'Invalid role assignment for {self.board_name}: {self._roles} !') self._mode = '' + self.io = self.ctl.connections[kwargs.pop('connection', MUX_CONFIG['connection'])] if tca_address is None: - self._tca = self.ctl.connections[kwargs.pop('connection', ctl_connection)] + self._tca = self.io else: - self._tca = adafruit_tca9548a.TCA9548A(self.ctl.bus, tca_address)[tca_channel] + self._tca = adafruit_tca9548a.TCA9548A(self.io, tca_address)[tca_channel] self._mcp_addresses = (kwargs.pop('mcp_0', '0x22'), kwargs.pop('mcp_1', '0x23')) # TODO: add assert on valid addresses.. self._mcp = [None, None] self.reset() diff --git a/ohmpi/hardware_components/pwr_dps5005.py b/ohmpi/hardware_components/pwr_dps5005.py index 4aa1a9f66a0153602d1513746038bd56c0383743..5f0a25cd54af8408585c618e3f480f6508c5fc56 100644 --- a/ohmpi/hardware_components/pwr_dps5005.py +++ b/ohmpi/hardware_components/pwr_dps5005.py @@ -6,7 +6,8 @@ import minimalmodbus # noqa import os CTL_CONFIG = HARDWARE_CONFIG['ctl'] -ctl_name = CTL_CONFIG.pop('board_name', 'raspberry_pi_modbus') +ctl_name = HARDWARE_CONFIG['ctl'].pop('board_name', 'raspberry_pi') +ctl_connection = HARDWARE_CONFIG['ctl'].pop('connection', 'modbus') ctl_module = importlib.import_module(f'ohmpi.hardware_components.{ctl_name}') CTL_CONFIG['baudrate'] = CTL_CONFIG.pop('baudrate', 9600) CTL_CONFIG['bitesize'] = CTL_CONFIG.pop('bitesize', 8) @@ -26,6 +27,7 @@ class Pwr(PwrAbstract): # if a controller is passed in kwargs, it will be instantiated if self.ctl is None: self.ctl = ctl_module.Ctl(**CTL_CONFIG) + self.io = self.ctl.connections[kwargs.pop('connection', ctl_connection)] self.voltage_adjustable = True self._voltage = voltage self._current_adjustable = False @@ -41,11 +43,11 @@ class Pwr(PwrAbstract): self.exec_logger.debug(f'Current cannot be set on {self.board_name}') def turn_off(self): - self.ctl.bus.write_register(0x09, 1) + self.io.write_register(0x09, 1) self.exec_logger.debug(f'{self.board_name} is off') def turn_on(self): - self.ctl.bus.write_register(0x09, 1) + self.io.write_register(0x09, 1) self.exec_logger.debug(f'{self.board_name} is on') @property @@ -54,11 +56,11 @@ class Pwr(PwrAbstract): @voltage.setter def voltage(self, value): - self.ctl.bus.write_register(0x0000, value, 2) + self.io.write_register(0x0000, value, 2) def battery_voltage(self): - self.ctl.bus.read_register(0x05, 2) + self.io.read_register(0x05, 2) @property def current_max(self,value): - self.ctl.bus.write_register(0x0001, value * 10, 0) + self.io.write_register(0x0001, value * 10, 0)