Skip to content

Commit

Permalink
Merge pull request #138 from Cephla-Lab/ian/you-yan-celesta-logging-fix
Browse files Browse the repository at this point in the history
Ian/you yan celesta logging fix
  • Loading branch information
hongquanli authored Mar 4, 2025
2 parents 5aa67c6 + 4dbb5ee commit 2a6ab0f
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions software/control/celesta.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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":
Expand All @@ -109,44 +114,59 @@ 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:
ttl_enable = "0"
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":
max_int = float(self.message["message"].split(" ")[-1])
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
Expand All @@ -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


Expand Down

0 comments on commit 2a6ab0f

Please sign in to comment.