Fixed and extended csv_logging.py

This commit is contained in:
2021-09-28 19:42:38 +02:00
parent d02bde9631
commit de4e54e7e0
5 changed files with 179 additions and 62 deletions
+25 -6
View File
@@ -15,6 +15,7 @@ class PSUDevice(ABC):
"""PSUDevice assumes a serial connection"""
ui_print("\nConnecting to power supply...")
self.com_port = com_port
self.cached_state = dict.fromkeys(self.valid_channels()) # Used for components that require state on demand
@abstractmethod
def enable_channel(self, channel_nr):
@@ -53,10 +54,24 @@ class PSUDevice(ABC):
def poll_channel_state(self, channel_nr):
"""Return a dictionary with the entries below. WARNING: this call is blocking and potentially slow!
Can throw exceptions"""
# Should also set self.cached_state
# return {'active': False, 'remote_active': False,
# 'actual_voltage':0, 'limit_voltage':0, 'actual_current':0, 'limit_current':0}
pass
def cached_channel_state(self, channel_nr):
"""Return a dictionary with the entries below. Uses the values obtained during last poll.
May contain None-entries"""
if self.cached_state[channel_nr]:
return self.cached_state[channel_nr]
else:
return {'active': None, 'remote_active': None,
'actual_voltage': None,
'limit_voltage': None,
'actual_current': None,
'limit_current': None}
def idle(self):
"""Zero all outputs but activate channels so commands can be sent."""
for ch in self.valid_channels():
@@ -130,9 +145,11 @@ class PSUDevicePS2000B(PSUDevice):
time.sleep(self.MIN_DELAY)
# Format should match the provided template in abstract PSUDevice class.
return {'active': dev_status.output_active, 'remote_active': dev_status.remote_control_active,
'voltage': voltage, 'voltage_setpoint': voltage_setp,
'current': current, 'current_setpoint': current_setp}
self.cached_state[channel_nr] = {'active': dev_status.output_active,
'remote_active': dev_status.remote_control_active,
'voltage': voltage, 'voltage_setpoint': voltage_setp,
'current': current, 'current_setpoint': current_setp}
return self.cached_state[channel_nr]
def shutdown(self):
for ch in self.valid_channels():
@@ -161,6 +178,7 @@ class PSUDeviceQL355TP(PSUDevice):
self.set_output_range(0, 0) # Put the PSU into the 15V/5A range
self.set_output_range(1, 0)
self.reset_breaker() # Reset the breaker in case we are coming from an unclean state
self.cached_state = dict.fromkeys(self.valid_channels()) # Used for components that require state on demand
@staticmethod
def valid_channels():
@@ -216,9 +234,10 @@ class PSUDeviceQL355TP(PSUDevice):
# Format should match the provided template in abstract PSUDevice class.
# The remote_active property is assumed to always be True since it cant be read
# (it should be since we are talking to it)
return {'active': output_active, 'remote_active': True,
'voltage': voltage, 'voltage_setpoint': voltage_setp,
'current': current, 'current_setpoint': current_setp}
self.cached_state[channel_nr] = {'active': output_active, 'remote_active': True,
'voltage': voltage, 'voltage_setpoint': voltage_setp,
'current': current, 'current_setpoint': current_setp}
return self.cached_state[channel_nr]
def set_output_range(self, channel_nr, value_range):
"""The QL355TP supports various output ranges. We require the 15V/5A mode to achieve the greatest range."""