95 lines
3.1 KiB
Python
95 lines
3.1 KiB
Python
import bendev
|
|
from Bentham import Bentham
|
|
import time
|
|
import datetime
|
|
|
|
class Xenon():
|
|
def __init__(self):
|
|
self.ps_serial_num = '32540/2'
|
|
self.state = 0
|
|
self.default_current = 5.4010
|
|
|
|
def start(self):
|
|
"""
|
|
Starts xenon probe light lamp. Assumes lamp is connected
|
|
to given power supply.
|
|
Bentham TMC300 is also parked to ensure later operation.
|
|
"""
|
|
psu = self.apply_current(self.default_current)
|
|
psu.query(":SYST:ERR:COUNT?")
|
|
psu.write("OUTP ON"); psu.query("OUTP?")
|
|
print('Xenon lamp switched on')
|
|
Bentham().park()
|
|
self.state = 1
|
|
|
|
def stop(self):
|
|
psu = bendev.Device(self.ps_serial_num)
|
|
psu.query(":SYST:ERR:COUNT?")
|
|
psu.write("OUTP OFF"); psu.query("OUTP?")
|
|
print('Xenon lamp switched off')
|
|
self.state = 0
|
|
|
|
def reset_burntime(self):
|
|
# Burntime of first lamp: 2900h
|
|
# New lamp 25% light intensity increase
|
|
psu = bendev.Device(self.ps_serial_num)
|
|
psu.query(":SYST:ERR:COUNT?")
|
|
psu.write(":RESEt:BURNtime"); psu.query("OUTP?")
|
|
print('Xenon burntime reset')
|
|
|
|
def apply_current(self, current_to_set):
|
|
psu = bendev.Device(self.ps_serial_num)
|
|
argument = ":SOUR:CURR " + str(current_to_set)
|
|
psu.write(argument); psu.query(":CURR?")
|
|
return psu
|
|
|
|
def __status(self):
|
|
psu = bendev.Device(self.ps_serial_num)
|
|
if float(psu.query(":CURR?")) < 1:
|
|
self.state = 0
|
|
else:
|
|
self.state = 1
|
|
|
|
def initialize(self):
|
|
"""
|
|
Checks if xenon is switched on.
|
|
If not switches xenon on.
|
|
"""
|
|
self.__status()
|
|
if self.state == 0:
|
|
print('Xenon lamp was just started. A warm up time of at least 60min is necessary!')
|
|
self.start()
|
|
else:
|
|
self.apply_current(self.default_current)
|
|
print('Xenon current reset to default.')
|
|
|
|
def preset_start(self, hour=6, minute=00):
|
|
"""
|
|
Allows for delayed xenon start. Can be used to allow for warmup time in morning.
|
|
Max delay 23h 59m.
|
|
"""
|
|
current_time = datetime.datetime.today()
|
|
desired_day = current_time.day
|
|
if current_time.hour > hour:
|
|
desired_day += 1
|
|
desired_time = datetime.datetime(current_time.year, current_time.month, desired_day, hour, minute)
|
|
print('Xenon will be started: ', desired_time)
|
|
while int(desired_time.timestamp()) - int(datetime.datetime.today().timestamp()) > 0:
|
|
remaining = int(desired_time.timestamp()) - int(datetime.datetime.today().timestamp())
|
|
print('\rWaiting: ' + time.strftime('%H:%M:%S', time.gmtime(remaining)) + ' remaining until xenon startup', end='')
|
|
time.sleep(1)
|
|
print('')
|
|
self.start()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
from DeviceManager import DeviceManager
|
|
dm = DeviceManager()
|
|
#dm.xenon.apply_current(5.41)
|
|
#dm.xenon.initialize()
|
|
dm.xenon.stop()
|
|
#dm.xenon.initialize()
|
|
#dm.xenon.preset_start(8,00)
|
|
|
|
|