From 4649664b55184117a1863c702dae6c15ccd97aff Mon Sep 17 00:00:00 2001 From: "Ryan@SOLARIS-MAC" Date: Sat, 27 Jul 2024 14:55:13 -0400 Subject: [PATCH] basic class. --- HVGUI.py | 9 +++ HVLibrary.py | 160 +++++++++++++++++++++++++++++++++++++++++++++++++++ test.py | 18 ++++++ 3 files changed, 187 insertions(+) create mode 100755 HVGUI.py create mode 100755 HVLibrary.py create mode 100755 test.py diff --git a/HVGUI.py b/HVGUI.py new file mode 100755 index 0000000..ff7124c --- /dev/null +++ b/HVGUI.py @@ -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 + + diff --git a/HVLibrary.py b/HVLibrary.py new file mode 100755 index 0000000..6c7a7c4 --- /dev/null +++ b/HVLibrary.py @@ -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') diff --git a/test.py b/test.py new file mode 100755 index 0000000..18ce8dc --- /dev/null +++ b/test.py @@ -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() ) \ No newline at end of file