148 lines
5.0 KiB
Python
148 lines
5.0 KiB
Python
|
|
#!/user/bin/env python3
|
||
|
|
"""
|
||
|
|
WAY 6X Supercap Test App - way_6x_supercap_test_app.py
|
||
|
|
- ENTRY POINT OF APPLICATION
|
||
|
|
|
||
|
|
VERSION: 1.0
|
||
|
|
|
||
|
|
AUTHOR: D. RICE 20/06/2024
|
||
|
|
© 2024 FLOWBIRD TRANSPORT
|
||
|
|
"""
|
||
|
|
|
||
|
|
# Imports
|
||
|
|
import pyvisa
|
||
|
|
import time
|
||
|
|
from threading import Timer
|
||
|
|
import sys
|
||
|
|
from datetime import datetime
|
||
|
|
|
||
|
|
# Global variables
|
||
|
|
setup_del = 0.2 # Setup delay in seconds
|
||
|
|
meas_del = 0.05 # Measure delay in seconds
|
||
|
|
psu_on_trigger_flag = False
|
||
|
|
psu_off_trigger_flag = False
|
||
|
|
psu_on_trigger_target = 30
|
||
|
|
psu_off_trigger_target = 10
|
||
|
|
psu_toggle_flag = False
|
||
|
|
psu_voltage = 28.0
|
||
|
|
psu_current = 3.0
|
||
|
|
|
||
|
|
VISA_ADDRESS = "TCPIP::10.120.41.36::INSTR"
|
||
|
|
|
||
|
|
rm = pyvisa.ResourceManager()
|
||
|
|
|
||
|
|
SPD = rm.open_resource(
|
||
|
|
VISA_ADDRESS,
|
||
|
|
write_termination='\n',
|
||
|
|
read_termination='\n'
|
||
|
|
)
|
||
|
|
|
||
|
|
def main():
|
||
|
|
global SPD
|
||
|
|
global setup_del
|
||
|
|
global psu_on_trigger_flag
|
||
|
|
global psu_off_trigger_flag
|
||
|
|
global psu_on_trigger_target
|
||
|
|
global psu_off_trigger_target
|
||
|
|
global psu_toggle_flag
|
||
|
|
global psu_voltage
|
||
|
|
global psu_current
|
||
|
|
|
||
|
|
SPD.write('CH1:VOLT ' + str(psu_voltage)) # Send power supply source voltage
|
||
|
|
time.sleep(setup_del)
|
||
|
|
SPD.write('CH1:CURR ' + str(psu_current)) # Send power supply current limit
|
||
|
|
time.sleep(setup_del)
|
||
|
|
SPD.write('CH2:VOLT ' + str(psu_voltage)) # Send power supply source voltage
|
||
|
|
time.sleep(setup_del)
|
||
|
|
SPD.write('CH2:CURR ' + str(psu_current)) # Send power supply current limit
|
||
|
|
time.sleep(setup_del)
|
||
|
|
|
||
|
|
# Enable power supply output source
|
||
|
|
SPD.write('OUTP CH1,ON') # Enable supply output
|
||
|
|
time.sleep(setup_del)
|
||
|
|
SPD.write('OUTP CH2,ON') # Enable supply output
|
||
|
|
time.sleep(setup_del)
|
||
|
|
|
||
|
|
# Setup timer
|
||
|
|
psu_toggle_flag = False
|
||
|
|
test_timer = Timer(psu_on_trigger_target, test_timer_routine)
|
||
|
|
test_timer.daemon = True
|
||
|
|
test_timer.start()
|
||
|
|
|
||
|
|
now = datetime.now()
|
||
|
|
current_time = now.strftime("%H:%M:%S")
|
||
|
|
print ("TIME STAMP: " + current_time + " EVENT: PSU ON | CHANNEL #1 V (V) = " + str(psu_voltage) + " | CHANNEL #1 I (A) = " + str(psu_current) + " | CHANNEL #2 V (V) = " + str(psu_voltage) + " | CHANNEL #2 I (A) = " + str(psu_current))
|
||
|
|
|
||
|
|
while True:
|
||
|
|
if psu_on_trigger_flag == True:
|
||
|
|
psu_on_trigger_flag = False
|
||
|
|
test_timer = Timer(psu_on_trigger_target, test_timer_routine)
|
||
|
|
test_timer.daemon = True
|
||
|
|
test_timer.start()
|
||
|
|
|
||
|
|
now = datetime.now()
|
||
|
|
current_time = now.strftime("%H:%M:%S")
|
||
|
|
print ("TIME STAMP: " + current_time + " EVENT: PSU ON | CHANNEL #1 V (V) = " + str(psu_voltage) + " | CHANNEL #1 I (A) = " + str(psu_current) + " | CHANNEL #2 V (V) = " + str(psu_voltage) + " | CHANNEL #2 I (A) = " + str(psu_current))
|
||
|
|
|
||
|
|
SPD.write('CH1:VOLT ' + str(psu_voltage)) # Send power supply source voltage
|
||
|
|
time.sleep(setup_del)
|
||
|
|
SPD.write('CH1:CURR ' + str(psu_current)) # Send power supply current limit
|
||
|
|
time.sleep(setup_del)
|
||
|
|
SPD.write('CH2:VOLT ' + str(psu_voltage)) # Send power supply source voltage
|
||
|
|
time.sleep(setup_del)
|
||
|
|
SPD.write('CH2:CURR ' + str(psu_current)) # Send power supply current limit
|
||
|
|
time.sleep(setup_del)
|
||
|
|
|
||
|
|
# Enable power supply output source
|
||
|
|
SPD.write('OUTP CH1,ON') # Enable supply output
|
||
|
|
time.sleep(setup_del)
|
||
|
|
SPD.write('OUTP CH2,ON') # Enable supply output
|
||
|
|
time.sleep(setup_del)
|
||
|
|
|
||
|
|
if psu_off_trigger_flag == True:
|
||
|
|
psu_off_trigger_flag = False
|
||
|
|
test_timer = Timer(psu_off_trigger_target, test_timer_routine)
|
||
|
|
test_timer.daemon = True
|
||
|
|
test_timer.start()
|
||
|
|
|
||
|
|
now = datetime.now()
|
||
|
|
current_time = now.strftime("%H:%M:%S")
|
||
|
|
|
||
|
|
print ("TIME STAMP: " + current_time + " EVENT: PSU OFF | CHANNEL #1 V (V) = 0.0 | CHANNEL #1 I (A) = 0.0 | CHANNEL #2 V (V) = 0.0 | CHANNEL #2 I (A) = 0.0")
|
||
|
|
|
||
|
|
SPD.write('CH1:VOLT ' + '0.0') # Send power supply source voltage
|
||
|
|
time.sleep(setup_del)
|
||
|
|
SPD.write('CH1:CURR ' + '0.0') # Send power supply current limit
|
||
|
|
time.sleep(setup_del)
|
||
|
|
SPD.write('CH2:VOLT ' + '0.0') # Send power supply source voltage
|
||
|
|
time.sleep(setup_del)
|
||
|
|
SPD.write('CH2:CURR ' + '0.0') # Send power supply current limit
|
||
|
|
time.sleep(setup_del)
|
||
|
|
|
||
|
|
# Disbale power supply output source
|
||
|
|
SPD.write('OUTP CH1,OFF') # Disable supply output
|
||
|
|
time.sleep(setup_del)
|
||
|
|
SPD.write('OUTP CH2,OFF') # Disable supply output
|
||
|
|
time.sleep(setup_del)
|
||
|
|
|
||
|
|
def test_timer_routine():
|
||
|
|
global psu_on_trigger_flag
|
||
|
|
global psu_off_trigger_flag
|
||
|
|
global psu_toggle_flag
|
||
|
|
|
||
|
|
if psu_toggle_flag == False:
|
||
|
|
psu_toggle_flag = True
|
||
|
|
psu_off_trigger_flag = True
|
||
|
|
|
||
|
|
else:
|
||
|
|
psu_toggle_flag = False
|
||
|
|
psu_on_trigger_flag = True
|
||
|
|
|
||
|
|
|
||
|
|
# Run main
|
||
|
|
if __name__ == "__main__":
|
||
|
|
try:
|
||
|
|
main()
|
||
|
|
except (KeyboardInterrupt, SystemExit):
|
||
|
|
sys.exit()
|