#!/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.1.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) -> None: pv = epics.PV(hostName + ":" + pv_name, connection_timeout=0.1) 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) -> int: 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 SetName(self, name : str): set_value(self.bdCh + "Name", name) 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 SetPowerOnOff(self, onOff): # off = 0, on = 1 set_value(self.bdCh + "Pw", onOff) def SetPowerOnOption(self, disEn : bool): #disable = 0, enable = 1, if enable, restart will restore in same condition set_value(self.bdCh + "POn", disEn) def SetPowerDownOptionWhenTrip(self, killRamp) : # kill = 0, Ramp = 1 set_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') def GetPV(self, PV_Name : str): pvList = [] for i in range(48): pvList.append('solarisHV:' + self.id + ":" + f"{i:03d}" + ":" + PV_Name) return epics.caget_many(pvList) def PutPV(self, PV_Name : str, ValueList ): pvList = [] for i in range(48): pvList.append('solarisHV:' + self.id + ":" + f"{i:03d}" + ":" + PV_Name) if len(ValueList) == len(pvList): epics.caput_many(pvList, ValueList) else: print("PutPV: Value List size does not match channel number")