Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ian/you yan celesta logging fix #138

Merged
merged 3 commits into from
Mar 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading