Repository navigation
Expand file tree
/
Copy pathPowerControl.py
More file actions
111 lines (79 loc) · 3.04 KB
/
Copy pathPowerControl.py
File metadata and controls
111 lines (79 loc) · 3.04 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#######################################################
# PowerControl
#
# Controls one or several power relays on an Agilent 34903A Actuator module
#
#################################################
# Modules used
#
from Agilent import tAgilent
from PySide6.QtCore import QObject, Signal
class tPowerControl(QObject):
###############################################
# Constants
#
#################################################
#
# Signals
#
# Outbound
PowerRelayStateUpdate = Signal(bool)
###############################################
# Constructor
#
# INPUTS:
# agilent - the Agilent unit with the 34903A Actuator card in it
# Name - a name for display
# PowerRelayChannels - an Agilent-spec list of channels to switch, e.g. '201:202,205'
# RelayType - tAgilent.RELAY_NORMALLY_OPEN or tAgilent.RELAY_NORMALLY_CLOSED
def __init__(self, Agilent: tAgilent, Name, PowerRelayChannels, RelayType, parent=None):
super().__init__(parent)
self.agilent = Agilent
self.Name = Name
self.RelayType = RelayType
self.RelayChannels = PowerRelayChannels
###############################################
# PowerOn
#
def PowerOn(self):
sChannelAction = 'opening' if self.RelayType == tAgilent.RELAY_NORMALLY_CLOSED else 'closing'
print(f'Powering on {self.Name} ({sChannelAction} Agilent channels {self.RelayChannels})', flush=True)
self.agilent.SetRelayState(self.RelayChannels, self.RelayType, True)
###############################################
# PowerOff
#
def PowerOff(self):
sChannelAction = 'closing' if self.RelayType == tAgilent.RELAY_NORMALLY_CLOSED else 'opening'
print(f'Powering off {self.Name} ({sChannelAction} Agilent channels {self.RelayChannels})', flush=True)
self.agilent.SetRelayState(self.RelayChannels, self.RelayType, False)
###############################################
# SetPowerState
#
# bState - false to turn off, true to turn on
def SetPowerState(self, bState):
if bState:
self.PowerOn()
else:
self.PowerOff()
self.PowerRelayStateUpdate.emit(bState)
###############################################
# GetPowerState
#
# If you provide a list of relays, this assumes they all have the same state and just
# returns the first one.
#
# RETURNS:
# True if power is on
# RAISES:
# TimeoutError if the operation times out
def GetPowerState(self) -> bool:
bPowerIsOn = self.agilent.GetRelayState(self.RelayChannels, self.RelayType)
print(f'{self.Name} power readback: {"ON" if bPowerIsOn else "OFF"} (Agilent channels {self.RelayChannels})', flush=True)
return bPowerIsOn
###############################################
# LogInstrumentError - Surfaces any instrument error queued by the last relay command
#
# For the user-initiated (checkbox) path only - see tAgilent.LogInstrumentError. Must NOT be
# called from the automatic sequencer paths.
def LogInstrumentError(self):
self.agilent.LogInstrumentError(self.Name)