-
Notifications
You must be signed in to change notification settings - Fork 1
/
PowerSupply.py
71 lines (57 loc) · 2.34 KB
/
PowerSupply.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
60
61
62
63
64
65
66
67
68
69
70
71
"""
Instrument wrapper for PSLab python API
"""
from enum import Enum
from OpenTap import Display
from opentap import *
from .ConnectionHandler import ConnectionHandler
class PowerPin(Enum):
ONE = 0
TWO = 1
THREE = 2
@attribute(Display("Power Supply", "Power supply instrument", "PSLab"))
class PowerSupply(Instrument):
def __init__(self):
"""Set up the properties, methods and default values of the instrument."""
super(PowerSupply, self).__init__() # The base class initializer must be invoked.
self.instrument = None
self.Name = "Power Supply"
def Open(self):
super(PowerSupply, self).Open()
# Open COM connection to instrument through ConnectionHandler
self.instrument = ConnectionHandler.instance().getPowerSupply()
"""Called by TAP when the test plan starts."""
def Close(self):
"""Called by TAP when the test plan ends."""
super(PowerSupply, self).Close()
def setPcs(self, current):
self.instrument.pcs = current
self.log.Debug(f"PSLab Power Supply PCS Current set to {current} A")
def getPcs(self):
current = self.instrument.pcs
self.log.Debug(f"PSLab Power Supply PCS Current is {current} A")
return current
def setVoltage(self, pin, voltage):
match pin:
case PowerPin.ONE:
self.instrument.pv1 = voltage
case PowerPin.TWO:
self.instrument.pv2 = voltage
case PowerPin.THREE:
self.instrument.pv3 = voltage
case _:
raise Exception(f"Bad pin number: {pin}")
self.log.Debug(f"PSLab Power Supply {pin} pin voltage set to {voltage} V")
def getVoltage(self, pin):
match pin:
case PowerPin.ONE:
self.log.Debug(f"PSLab Power Supply {pin} pin voltage is {self.instrument.pv1} V")
return self.instrument.pv1
case PowerPin.TWO:
self.log.Debug(f"PSLab Power Supply {pin} pin voltage set to {self.instrument.pv2} V")
return self.instrument.pv2
case PowerPin.THREE:
self.log.Debug(f"PSLab Power Supply {pin} pin voltage set to {self.instrument.pv3} V")
return self.instrument.pv3
case _:
raise Exception(f"Bad pin number: {pin}")