# -*- coding: utf-8 -*- """ Created on Sat Nov 9 19:55:10 2024 @author: shen_t2 """ import PowerSupplyCaylarLib import traceback import time def EMagnet_connect_test(powerSupply, USER_PSUPPLY_IP, USER_PSUPPLY_PORT): print("==================================================") print("Test Caylar power supply library start !\n") # powerSupply = PowerSupplyCaylarLib.CaylarPowerSupply(2) try: print("Try to connect to " + USER_PSUPPLY_IP + " (port 1234) ...") powerSupply.connect(USER_PSUPPLY_IP,USER_PSUPPLY_PORT) print("Successfully connected to the power supply!\n") print("Power supply info:") print("---------------------------") print(" - IDN: " + powerSupply.getIDN()) print("\n - Températures infos:") print(" - Rack temp = " + powerSupply.getRackTemp().split(" ")[1]) print(" - Box temp = " + powerSupply.getBoxTemp().split(" ")[1]) print(" - ADC/DAC temp = " + powerSupply.getAdcDacTemp().split(" ")[1]) print("\n - Power infos:") power_state = int(powerSupply.getPowerState().split(" ")[1]) selector_pos = int(powerSupply.getSelectorPos().split(" ")[1]) print(" - Power is " + ("off", "on")[power_state]) print(" - Output tension = " + powerSupply.getVoltage().split(" ")[1]) print(" - Output current = " + powerSupply.getCurrent().split(" ")[1]) print(" - Current remote from " + ("front potentiometer", "internal DAC", "external voltage source")[selector_pos]) print("\n - Securities infos:") default_state = int(powerSupply.getDefaultState().split(" ")[1]) maintenance_state = int(powerSupply.getMaintenanceState().split(" ")[1]) print(" - Power supply power securitie is " + ("off", "on")[default_state]) print(" - Last default name is " + powerSupply.getDefaultName().split(" ")[1]) print(" - Maintenance is " + ("off", "on")[maintenance_state]) except: print("soft error ...") traceback.print_exc() finally: powerSupply.disconnect() def set_Bfield_Current(B_current, powerSupply, USER_PSUPPLY_IP, USER_PSUPPLY_PORT): try: # print("Try to connect to " + USER_PSUPPLY_IP + " (port 1234) ...") powerSupply.connect(USER_PSUPPLY_IP,USER_PSUPPLY_PORT) # print("Successfully connected to the power supply!\n") print("------------------------------") powerSupply.setCurrent_wait(B_current) print("Successfully set the current!\n") time.sleep(5) print(" - Output current = " + powerSupply.getCurrent().split(" ")[1]) # print(" - Hall probe field = " + powerSupply.getField().split(" ")[1]) except: print("soft error ...") traceback.print_exc() finally: powerSupply.disconnect() def set_Bfield_Gauss(Bfield_Gs, poles_gap, powerSupply, USER_PSUPPLY_IP, USER_PSUPPLY_PORT): try: # print("Try to connect to " + USER_PSUPPLY_IP + " (port 1234) ...") powerSupply.connect(USER_PSUPPLY_IP,USER_PSUPPLY_PORT) # print("Successfully connected to the power supply!\n") print("------------------------------") calib_name = "Caylar_{:}_center".format(poles_gap) powerSupply.import_calibration(calib_name) print("Successfully calibrated with [{:}]!\n".format(calib_name)) powerSupply.setField(Bfield_Gs) print("Successfully set the current!\n") time.sleep(5) print(" - Output current = " + powerSupply.getCurrent().split(" ")[1]) print(" - Set field = " + str(Bfield_Gs) + " Gauss") except: print("soft error ...") traceback.print_exc() finally: powerSupply.disconnect() # %% main if __name__ == '__main__': EMagnet_PSUPPLY_IP = "QPS-CAYLAR-1" EMagnet_PSUPPLY_PORT = 1234 EMagnet_poles_gap = "large" # "small" or "large" scanB = 1000 # Gauss powerSupply = PowerSupplyCaylarLib.CaylarPowerSupply(2) EMagnet_connect_test(powerSupply, EMagnet_PSUPPLY_IP, EMagnet_PSUPPLY_PORT) set_Bfield_Current(-100, powerSupply, EMagnet_PSUPPLY_IP, EMagnet_PSUPPLY_PORT) set_Bfield_Gauss(scanB, EMagnet_poles_gap, powerSupply, EMagnet_PSUPPLY_IP, EMagnet_PSUPPLY_PORT) # set_Bfield_Current(0, powerSupply, EMagnet_PSUPPLY_IP, EMagnet_PSUPPLY_PORT)