-
Notifications
You must be signed in to change notification settings - Fork 1
/
SetVoltageStep.py
59 lines (48 loc) · 1.96 KB
/
SetVoltageStep.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""
Test step to set the voltage on a PV1-3 pin
"""
from OpenTap import Display, Unit, Verdict
from System import Double
from opentap import *
from .PowerSupply import *
@attribute(Display("Set Voltage", "Sets pin to a specific voltage", Groups=["PSLab", "Power Supply"]))
class SetVoltageStep(TestStep):
# Properties
Pin = property(PowerPin, PowerPin.ONE) \
.add_attribute(Display("Pin", "The chosen PV pin", "", -50))
Voltage = property(Double, 0) \
.add_attribute(Display("Voltage", "The voltage to be output on the chosen PV pin", "", -40)) \
.add_attribute(Unit("V"))
PowerSupply = property(PowerSupply, None) \
.add_attribute(Display("Power Supply", "", "Resources", 0))
def __init__(self):
super(SetVoltageStep, self).__init__()
self.Rules.Add(
Rule("Voltage", lambda: self.Voltage >= self.get_min_voltage(),
lambda: f'Voltage must be at least {self.get_min_voltage()} V for {self.Pin}.'))
self.Rules.Add(
Rule("Voltage", lambda: self.Voltage <= self.get_max_voltage(),
lambda: f'Voltage must not exceed {self.get_max_voltage()} V for {self.Pin}.'))
def Run(self):
self.PowerSupply.setVoltage(self.Pin, self.Voltage)
self.UpgradeVerdict(Verdict.Pass)
def get_min_voltage(self):
"""Gets minimal voltage for current pin."""
match self.Pin:
case PowerPin.ONE:
return -5
case PowerPin.TWO:
return -3.3
case PowerPin.THREE:
return 0
case _:
raise Exception(f"Unsupported pin: {self.Pin}")
def get_max_voltage(self):
"""Gets maximum voltage for current pin."""
match self.Pin:
case PowerPin.ONE:
return 5
case PowerPin.TWO | PowerPin.THREE:
return 3.3
case _:
raise Exception(f"Unsupported pin: {self.Pin}")