def connection_func(PMX=None): # Connect to PMX power supply if PMX == None: if cg.use_moxa: PMX = pm.PMX(tcp_ip=cg.tcp_ip, tcp_port=cg.tcp_port, timeout=0.5) else: PMX = pm.PMX(rtu_port=cg.rtu_port) pass pass PMX.clean_serial() return PMX
def user_input(self, arg): """ Take user input and execute PMX command """ argv = arg.split() while len(argv): cmd = str(argv.pop(0)).upper() # No command if cmd is '': return # Check voltage elif cmd is self._cmds["check_v"]: ret = self._PMX.check_voltage() # Check current elif cmd is self._cmds["check_c"]: ret = self._PMX.check_current() # Check voltage and current elif cmd is self._cmds["check_vc"]: ret = self._PMX.check_voltage_current() # Check output state elif cmd is self._cmds["check_out"]: ret = self._PMX.check_output() # Turn output state ON elif cmd is self._cmds["set_on"]: ret = self._PMX.turn_on() # Turn output state OFF elif cmd is self._cmds["set_off"]: ret = self._PMX.turn_off() # Get HELP elif cmd is self._cmds["get_help"]: ret = self.get_help() # Exit the program elif cmd is self._cmds["stop"]: sy.exit("\nExiting...") # Set the RTU port elif cmd is self._cmds["set_port"]: if self._PMX.using_tcp: print("Connected via TCP rather than RTU. " "Cannot set RTU port") return False set_val = self._int(argv.pop(0)) if set_val is not None: del self._PMX self._PMX = px.PMX(set_val) else: return False elif cmd is self._cmds["set_v"]: set_val = self._float(argv.pop(0)) if set_val is not None: self._PMX.set_voltage(set_val) else: return False elif cmd.lower() is self.setC.lower(): set_val = self._float(argv.pop(0)) if set_val is not None: self._PMX.set_current(set_val) else: return False else: print("Command '%s' not understood..." % (cmd)) return False return True
# Built-in python functions import sys as sy import readline # Check the python version if sy.version_info.major == 2: print("\nKikusui PMX control only works with Python 3\n" "Usage: sudo python3 command_supply.py") sy.exit() # Import control modules import pmx_config as cg # noqa: E402 import src.pmx as pm # noqa: E402 import src.command as cm # noqa: E402 # Connect to PMX power supply if cg.use_moxa: PMX = pm.PMX(tcp_ip=cg.tcp_ip, tcp_port=cg.tcp_port, timeout=0.5) else: PMX = pm.PMX(rtu_port=cg.rtu_port) cmd = cm.Command(PMX) # Check if inputs were passed via the command line if len(sy.argv) > 1: val = ' '.join(sy.argv[1:]) cmd.user_input(val) else: while True: val = input("Enter command ('H' for help): ") cmd.user_input(val)
import readline # Check the python version if sy.version_info.major == 2: print( "\nKikusui PMX control only works with Python 3\n" "Usage: sudo python3 command_supply.py") sy.exit() # Import CHWP control modules sy.path.append('src') import pmx_config as cg # noqa: E402 import src.pmx as pm # noqa: E402 import src.command as cm # noqa: E402 # Connect to PMX power supply if cg.use_moxa: PMX = pm.PMX(tcp_ip=cg.tcp_ip, tcp_port=cg.tcp_port) else: PMX = pm.PMX(rtu_port=cg.rtu_port) cmd = cm.Command(PMX) # Check if inputs were passed via the command line if len(sy.argv) > 1: val = ' '.join(sy.argv[1:]) cmd.user_input(val) else: while True: val = input("Enter command ('H' for help): ") cmd.user_input(val)
f.write(mg) f.close() return True #Parameters for the test R = 24.0 #Ohms powers = np.array([6., 9.]) voltages = np.sqrt(R * powers) #V #Times in hours, 3600 sec per hour times = np.array([4.] * len(voltages)) * 3600. if len(times) != len(voltages): raise Exception("Problem with the times array!") #Initialize serial connection to the Kikusui pmx = pm.PMX(cg.port) #Step the voltage for i in range(len(times)): t = times[i] v = voltages[i] #Set the voltage write("Setting voltage = %.02f V" % (v)) pmx.setVoltage(v) if not i: pmx.turnOn() tm.sleep(2) c = pmx.checkCurrent() write("Checking initial current = %.03f A" % (float(c))) write("Checking initial power = %.03f W" % (float(c) * float(v))) tm.sleep(t)
def powerOn(voltagelim=0., currentlim=0., timeperiod=0., position=0., notmakesure=False, PMX=None): # Connect to PMX power supply if PMX == None: if cg.use_moxa: PMX = pm.PMX(tcp_ip=cg.tcp_ip, tcp_port=cg.tcp_port, timeout=0.5) else: PMX = pm.PMX(rtu_port=cg.rtu_port) pass pass PMX.clean_serial() # Open log file logfile = openlog(cg.log_dir) # Set voltage & current msg = PMX.set_voltage(voltagelim) msg = PMX.set_current(currentlim) if notmakesure == False: # Turn On PMX.turn_on() # include wait() x 4 (200 msec) msg, vol = PMX.check_voltage() msg, cur = PMX.check_current() wait_turn_on = PMX.waittime * 4. writelog(logfile, 'ON', voltagelim, currentlim, vol, cur, timeperiod) # Turn OFF after timeperiod # If timeperiod <= 0., the power is ON permanently. if timeperiod > 0.: # Sleep for the specified time period if timeperiod > wait_turn_on: time.sleep(timeperiod - wait_turn_on) else: msg = ("WARNING! The wait-time period is too short.\n\ The period should be larger than wait-time for turning on({:.3f} sec)." .format(wait_turn_on)) print(msg) pass PMX.turn_off() vol, cur = PMX.check_voltage_current() vollim, curlim = PMX.check_voltage_current_limit() writelog(logfile, 'OFF', vollim, curlim, vol, cur) pass pass else: # Turn On PMX.turn_on(notmakesure) writelog(logfile, 'ON', voltagelim, currentlim, timeperiod=timeperiod, position=position, notmakesure=notmakesure) if timeperiod > 0.: # Sleep for the specified time period time.sleep(timeperiod) PMX.turn_off(notmakesure) writelog(logfile, 'OFF', voltagelim, currentlim, notmakesure=notmakesure) pass pass return PMX