basic class.
This commit is contained in:
commit
4649664b55
9
HVGUI.py
Executable file
9
HVGUI.py
Executable file
|
@ -0,0 +1,9 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import HVLibrary as hv
|
||||
|
||||
from PyQt6.QtWidgets import QApplication, QMainWindow, QPushButton, QCheckBox, QLineEdit, QLabel, QVBoxLayout, QWidget, QTabWidget, QGridLayout, QMessageBox, QFileDialog, QProgressBar
|
||||
from PyQt6.QtCore import Qt, QThread, QTimer, QObject, pyqtSignal
|
||||
from functools import partial
|
||||
|
||||
|
160
HVLibrary.py
Executable file
160
HVLibrary.py
Executable file
|
@ -0,0 +1,160 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import os
|
||||
import epics
|
||||
|
||||
# Set the IP address or hostname of the remote IOC
|
||||
os.environ['EPICS_CA_ADDR_LIST'] = '192.168.0.1' # Replace with the actual IP address or hostname
|
||||
# Optionally disable automatic address list searching
|
||||
os.environ['EPICS_CA_AUTO_ADDR_LIST'] = 'NO'
|
||||
|
||||
hostName='solarisHV'
|
||||
|
||||
Model_PV_List = ['ModelName', 'IPAddr', 'ClearAlarm']
|
||||
Board_PV_List = ['BdStatus', 'HVMax', 'Temp', 'ClrAlarm']
|
||||
Ch_PV_List = ['Name', 'V0Set', 'I0Set', 'V1Set', 'I1Set', 'RUp', 'RDWn', 'Trip', 'SVMax', 'VMon', 'IMon', 'Status', 'Pw', 'POn', 'PDwn', 'TripInt', 'TripExt', 'ZCDetect', 'ZCAdjust']
|
||||
|
||||
def get_CtrlField(pv_name: str):
|
||||
name = hostName + ":" + pv_name
|
||||
pv = epics.PV(name, connection_timeout=0.1)
|
||||
value = pv.get_ctrlvars(timeout= 1)
|
||||
return value
|
||||
|
||||
def get_value(pv_name : str, show : bool = False):
|
||||
name = hostName + ":" + pv_name
|
||||
pv = epics.PV(name, connection_timeout=0.1)
|
||||
value = pv.get( use_monitor=False)
|
||||
if show :
|
||||
print(f"The current value of the PV {name} is: {value}")
|
||||
return value
|
||||
|
||||
|
||||
def set_value(pv_name : str, value):
|
||||
pv = epics.PV(hostName + ":" + pv_name, connection_timeout=0.1)
|
||||
return pv.put(value)
|
||||
|
||||
|
||||
#======= general
|
||||
#get_value(Model_PV_List[0])
|
||||
#get_value(Model_PV_List[1])
|
||||
|
||||
#====== board
|
||||
#get_value('03:' + Board_PV_List[1])
|
||||
|
||||
#====== ch
|
||||
#set_value('03:000:' + Ch_PV_List[1], 5)
|
||||
#get_value('03:000:' + Ch_PV_List[1])
|
||||
#get_value('03:000:' + Ch_PV_List[0])
|
||||
|
||||
|
||||
####################################################
|
||||
class Channel:
|
||||
def __init__(self, bd:int, ch:int) -> None:
|
||||
self.bdCh = f"{bd:02d}" + ":"+ f"{ch:03d}" + ":"
|
||||
|
||||
def GetName(self) -> str:
|
||||
return get_value(self.bdCh + "Name")
|
||||
|
||||
def GetV0Set(self) -> float:
|
||||
return get_value(self.bdCh + "V0Set")
|
||||
|
||||
def GetI0Set(self) -> float:
|
||||
return get_value(self.bdCh + "I0Set")
|
||||
|
||||
def GetV1Set(self) -> float:
|
||||
return get_value(self.bdCh + "V1Set")
|
||||
|
||||
def GetI1Set(self) -> float:
|
||||
return get_value(self.bdCh + "I1Set")
|
||||
|
||||
def GetRamUp(self) -> float:
|
||||
return get_value(self.bdCh + "RUp")
|
||||
|
||||
def GetRamDown(self) -> float:
|
||||
return get_value(self.bdCh + "RDWn")
|
||||
|
||||
def GetTripTime(self) -> float:
|
||||
return get_value(self.bdCh + "Trip")
|
||||
|
||||
def GetMaxVoltage(self) -> float:
|
||||
return get_value(self.bdCh + "SVMax")
|
||||
|
||||
def GetVMon(self) -> float:
|
||||
return get_value(self.bdCh + "VMon")
|
||||
|
||||
def GetIMon(self) -> float:
|
||||
return get_value(self.bdCh + "IMon")
|
||||
|
||||
def GetStatus(self) -> str:
|
||||
return get_value(self.bdCh + "Status")
|
||||
|
||||
def GetPowerOnOff(self) -> str:
|
||||
return get_value(self.bdCh + "Pw")
|
||||
|
||||
def GetPowerOnOption(self) -> str:
|
||||
return get_value(self.bdCh + "POn")
|
||||
|
||||
def GetPowerDownOptionWhenTrip(self) -> str:
|
||||
return get_value(self.bdCh + "PDown")
|
||||
|
||||
|
||||
def SetV0Set(self, volt: float):
|
||||
set_value(self.bdCh + "V0Set", volt)
|
||||
|
||||
def SetI0Set(self, uA: float):
|
||||
set_value(self.bdCh + "I0Set", uA)
|
||||
|
||||
def SetV1Set(self, volt: float):
|
||||
set_value(self.bdCh + "V1Set", volt)
|
||||
|
||||
def SetI1Set(self, uA: float):
|
||||
set_value(self.bdCh + "I1Set", uA)
|
||||
|
||||
def SetRamUp(self, Vps: float):
|
||||
set_value(self.bdCh + "RUp", Vps)
|
||||
|
||||
def SetRamDown(self, Vps: float):
|
||||
set_value(self.bdCh + "RDWn", Vps)
|
||||
|
||||
def SetTripTime(self, second: float):
|
||||
set_value(self.bdCh + "Trip", second)
|
||||
|
||||
def SetMaxVoltage(self, volt: float):
|
||||
set_value(self.bdCh + "SVMax", volt)
|
||||
|
||||
def GetPowerOnOff(self, onOff : bool): # off = 0, on = 1
|
||||
return get_value(self.bdCh + "Pw", onOff)
|
||||
|
||||
def GetPowerOnOption(self, disEn : bool): #disable = 0, enable = 1, if enable, restart will restore in same condition
|
||||
return get_value(self.bdCh + "POn", disEn)
|
||||
|
||||
def GetPowerDownOptionWhenTrip(self, killRamp) : # kill = 0, Ramp = 1
|
||||
return get_value(self.bdCh + "PDwn", killRamp)
|
||||
|
||||
|
||||
####################################################
|
||||
class Board:
|
||||
def __init__(self, id:int) -> None:
|
||||
self.id = f"{id:02d}"
|
||||
|
||||
self.numCh = 48
|
||||
self.Channel = []
|
||||
for i in range(self.numCh):
|
||||
self.Channel.append( Channel(id, i) )
|
||||
|
||||
def FindNumChannel(self) -> None:
|
||||
self.numCh = 0
|
||||
for i in range(48):
|
||||
chstr = f"{i:03d}"
|
||||
haha = get_value(self.id + ":" + chstr + ":Name" )
|
||||
if isinstance(haha, str) :
|
||||
self.numCh = self.numCh + 1
|
||||
print("Number of channel : " + str(self.numCh))
|
||||
|
||||
self.Channel.clear()
|
||||
for i in range(self.numCh):
|
||||
self.Channel.append( Channel(id, i) )
|
||||
|
||||
|
||||
def GetTemp(self) -> float:
|
||||
return get_value(self.id + ":" + 'Temp')
|
18
test.py
Executable file
18
test.py
Executable file
|
@ -0,0 +1,18 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import HVLibrary as hv
|
||||
|
||||
#set_value('03:000:' + Ch_PV_List[1], 5)
|
||||
#hv.get_value('03:000:' + hv.Ch_PV_List[1])
|
||||
#hv.get_value('03:000:' + hv.Ch_PV_List[0])
|
||||
|
||||
# index = 14
|
||||
# hv.get_value('03:000:' + hv.Ch_PV_List[index], True)
|
||||
# cf = hv.get_CtrlField('03:000:' + hv.Ch_PV_List[index])
|
||||
# print(cf)
|
||||
|
||||
bd = hv.Board(3)
|
||||
|
||||
print( bd.GetTemp())
|
||||
|
||||
print( bd.Channel[0].GetName() )
|
Loading…
Reference in New Issue
Block a user