Commit 36c2b8ec authored by Arnaud WATLET's avatar Arnaud WATLET
Browse files

Adds pwr_dps5005 in hardware component (yet to be tested)

Showing with 86 additions and 0 deletions
+86 -0
from ohmpi.hardware_components.abstract_hardware_components import PwrAbstract
from ohmpi.config import HARDWARE_CONFIG
import importlib
import numpy as np
import os
ctl_name = HARDWARE_CONFIG['ctl'].pop('board_name', 'raspberry_pi_modbus')
ctl_module = importlib.import_module(f'ohmpi.hardware_components.{ctl_name}')
class Pwr(PwrAbstract):
def __init__(self, **kwargs):
kwargs.update({'board_name': os.path.basename(__file__).rstrip('.py')})
voltage = kwargs.pop('voltage', 12.)
super().__init__(**kwargs)
if self.ctl is None:
self.ctl = ctl_module.Ctl()
self.ctl.bus.configure_modbus()
self.voltage_adjustable = True
self._voltage = voltage
self._current_adjustable = False
self._current = np.nan
self._current_max = kwargs.pop('current_max', 100.)
@property
def current(self):
return self._current
@current.setter
def current(self, value, **kwargs):
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.exec_logger.debug(f'{self.board_name} is off')
def turn_on(self):
self.ctl.bus.write_register(0x09, 1)
self.exec_logger.debug(f'{self.board_name} is on')
@property
def voltage(self):
return PwrAbstract.voltage.fget(self)
@voltage.setter
def voltage(self, value):
self.ctl.bus.write_register(0x0000, value, 2)
def battery_voltage(self):
self.ctl.bus.read_register(0x05, 2)
@property
def current_max(self,value):
self.ctl.bus.write_register(0x0001, value * 10, 0)
from ohmpi.hardware_components import CtlAbstract
import board # noqa
import busio # noqa
import os
from ohmpi.utils import get_platform
from gpiozero import CPUTemperature # noqa
import minimalmodbus # noqa
class Ctl(CtlAbstract):
def __init__(self, **kwargs):
kwargs.update({'board_name': os.path.basename(__file__).rstrip('.py')})
super().__init__(**kwargs)
self.bus = minimalmodbus.Instrument(port='/dev/ttyUSB0', slaveaddress=1) # port name, address (decimal)
self.configure_modbus() # TODO: check if this works on init
platform, on_pi = get_platform()
assert on_pi
self.board_name = platform
self._cpu_temp_available = True
self.max_cpu_temp = 85. # °C
@property
def _cpu_temp(self):
return CPUTemperature().temperature
def configure_modbus(self, baudrate=9600, bitesize=8, timeout=1, debug=False, parity='N',
mode=minimalmodbus.MODE_RTU):
self.bus.serial.baudrate = baudrate # Baud rate 9600 as listed in doc
self.bus.serial.bytesize = bitesize #
self.bus.serial.timeout = timeout # greater than 0.5 for it to work
self.bus.debug = debug #
self.bus.serial.parity = parity # No parity
self.bus.mode = mode # RTU mode
\ No newline at end of file
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