diff --git a/software/control/celesta.py b/software/control/celesta.py index 91e184ce..459a84b2 100755 --- a/software/control/celesta.py +++ b/software/control/celesta.py @@ -3,12 +3,14 @@ Bogdan 3/19 revised HL 2/2024 + +You Yan 12/2024 """ import urllib.request import traceback from squid.abc import LightSource -from control.lighting import LightSourceType, IntensityControlMode, ShutterControlMode +from control.lighting import ShutterControlMode import squid.logging @@ -49,7 +51,7 @@ def __init__(self, **kwds): except: log.error(traceback.format_exc()) self.live = False - log.error("Failed to connect to Lumencor Laser at ip:", ip) + log.error("Failed to connect to Lumencor Laser at ip: 192.168.201.200") if self.live: [self.pmin, self.pmax] = self.get_intensity_range() @@ -101,6 +103,9 @@ def get_IP(self): return self.message def get_shutter_control_mode(self): + """ + Return True/False the lasers can be controlled with TTL. + """ self.message = lumencor_httpcommand(command="GET TTLENABLE", ip=self.ip) response = self.message["message"] if response[-1] == "1": @@ -109,6 +114,9 @@ def get_shutter_control_mode(self): return ShutterControlMode.Software def set_shutter_control_mode(self, mode): + """ + Turn on/off external TTL control mode. + """ if mode == ShutterControlMode.TTL: ttl_enable = "1" else: @@ -116,12 +124,18 @@ def set_shutter_control_mode(self, mode): self.message = lumencor_httpcommand(command="SET TTLENABLE " + ttl_enable, ip=self.ip) def get_shutter_state(self, laser_id): + """ + Return True/False the laser is on/off. + """ self.message = lumencor_httpcommand(command="GET CH " + str(laser_id), ip=self.ip) response = self.message["message"] self.on = response[-1] == "1" return self.on def get_intensity_range(self): + """ + Return [minimum power, maximum power]. + """ max_int = 1000 # default self.message = lumencor_httpcommand(command="GET MAXINT", ip=self.ip) if self.message["message"][0] == "A": @@ -129,24 +143,30 @@ def get_intensity_range(self): return [0, max_int] def get_intensity(self, laser_id): + """ + Return the current laser power. + """ self.message = lumencor_httpcommand(command="GET CHINT " + str(laser_id), ip=self.ip) - log.debug(command="GET CHINT " + str(laser_id), ip=self.ip) + log.debug("command = 'GET CHINT " + str(laser_id) + "'") response = self.message["message"] power = float(response.split(" ")[-1]) intensity = power / self.pmax * 100 return intensity def set_shutter_state(self, laser_id, on): + """ + Turn the laser on/off. + """ if on: self.message = lumencor_httpcommand(command="SET CH " + str(laser_id) + " 1", ip=self.ip) self.on = True else: self.message = lumencor_httpcommand(command="SET CH " + str(laser_id) + " 0", ip=self.ip) self.on = False - log.info("Turning On/Off", self.on, self.message) + log.debug(f"Turning On/Off {self.on} {self.message}") def set_intensity(self, laser_id, intensity): - log.info("Setting intensity to ", intensity) + log.debug(f"Setting intensity to {intensity}") power_in_mw = self.pmax * intensity / 100 self.message = lumencor_httpcommand( command="SET CHINT " + str(laser_id) + " " + str(int(power_in_mw)), ip=self.ip @@ -156,12 +176,18 @@ def set_intensity(self, laser_id, intensity): return False def shut_down(self): + """ + Turn the laser off. + """ if self.live: for i in range(self.n_lasers): self.set_intensity(i, 0) self.set_shutter_state(i, False) def get_status(self): + """ + Get the status + """ return self.live