Skip to content

Commit

Permalink
Added column valves state to Microscope classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
niermann committed Jun 24, 2022
1 parent 7427719 commit c52d1bb
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Version 2.0.1

* Added Talos as ProductFamily
* Added more graceful behavior for unsupported ProductFamily query and unknown future families.
* Added column valves state to Microscope classes.

Version 2.0.0
^^^^^^^^^^^^^
Expand Down
1 change: 1 addition & 0 deletions scripts/test_microscope.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
print("Microscope.get_version():", microscope.get_version())
print("Microscope.get_voltage():", microscope.get_voltage())
print("Microscope.get_vacuum():", microscope.get_vacuum())
print("Microscope.get_column_valves_open():", microscope.get_column_valves_open())
print("Microscope.get_stage_holder():", microscope.get_stage_holder())
print("Microscope.get_stage_status():", microscope.get_stage_status())
print("Microscope.get_stage_limits():", microscope.get_stage_limits())
Expand Down
23 changes: 23 additions & 0 deletions temscript/base_microscope.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,29 @@ def get_vacuum(self):
"""
raise NotImplementedError

@abstractmethod
def get_column_valves_open(self):
"""
Returns state of the column valves.
:return: `True`, if column valves are open. `False`, otherwise.
.. versionadded: 2.1.0
"""
raise NotImplementedError

@abstractmethod
def set_column_valves_open(self, state):
"""
Set state of the column valves. The column valves are opened, if `True` is passes as *state*
:param state: `True`, if column valves should be opened. `False`, if they should be closed.
:type state: bool
.. versionadded: 2.0.1
"""
raise NotImplementedError

@abstractmethod
def get_stage_holder(self):
"""Return holder currently in stage (see :class:`StageHolderType`)"""
Expand Down
8 changes: 7 additions & 1 deletion temscript/microscope.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,17 @@ def get_vacuum(self):
gauges[name] = g.Pressure
return {
"status": VacuumStatus(self._tem_vacuum.Status).name,
"column_valves_open": self._tem_vacuum.ColumnValvesOpen,
"column_valves_open": self.get_column_valves_open(),
"pvp_running": self._tem_vacuum.PVPRunning,
"gauges(Pa)": gauges,
}

def get_column_valves_open(self):
return self._tem_vacuum.ColumnValvesOpen

def set_column_valves_open(self, state):
self._tem_vacuum.ColumnValvesOpen = state

def get_stage_holder(self):
return self._tem_stage.Holder.name

Expand Down
6 changes: 6 additions & 0 deletions temscript/null_microscope.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ def get_vacuum(self):
"gauges(Pa)": {},
}

def get_column_valves_open(self):
return self._column_valves

def set_column_valves_open(self, state):
self._column_valves = bool(state)

def get_stage_holder(self):
return StageHolderType.SINGLE_TILT.name

Expand Down
6 changes: 6 additions & 0 deletions temscript/remote_microscope.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ def get_voltage(self):
def get_vacuum(self):
return self._request("GET", "/v1/vacuum")[1]

def get_column_valves_open(self):
return self._request("GET", "/v1/column_valves_open")[1]

def set_column_valves_open(self, state):
self._request_with_json_body("PUT", "/v1/column_valves_open", state)

def get_stage_holder(self):
return self._request("GET", "/v1/stage_holder")[1]

Expand Down
13 changes: 11 additions & 2 deletions temscript/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class MicroscopeHandler(BaseHTTPRequestHandler):
"condenser_stigmator", "diffraction_shift", "screen_current", "screen_position",
"illumination_mode", "condenser_mode", "illuminated_area", "probe_defocus", "convergence_angle",
"stem_magnification", "stem_rotation", "spot_size_index", "dark_field_mode", "beam_blanked",
"instrument_mode", 'optics_state', 'state')
"instrument_mode", 'optics_state', 'state', 'column_valves_open')

PUT_V1_FORWARD = ("image_shift", "beam_shift", "beam_tilt", "projection_mode", "magnification_index",
"defocus", "intensity", "diffraction_shift", "objective_stigmator", "condenser_stigmator",
Expand Down Expand Up @@ -126,6 +126,13 @@ def do_PUT_V1(self, endpoint, query):
response = self.get_microscope().set_detector_param(name, decoded_content)
elif endpoint == "normalize":
self.get_microscope().normalize(decoded_content)
elif endpoint == "column_valves_open":
state = bool(decoded_content)
assert isinstance(self.server, MicroscopeServer)
if self.server.allow_column_valves_open or not state:
self.get_microscope().set_column_valves_open(state)
else:
raise ValueError("Opening of column valves is prohibited.")
else:
raise KeyError("Unknown endpoint: '%s'" % endpoint)
return response
Expand Down Expand Up @@ -166,17 +173,19 @@ def do_PUT(self):


class MicroscopeServer(HTTPServer, object):
def __init__(self, server_address=('', 8080), microscope_factory=None):
def __init__(self, server_address=('', 8080), microscope_factory=None, allow_column_valves_open=True):
"""
Run a microscope server.
:param server_address: (address, port) tuple
:param microscope_factory: callable creating the BaseMicroscope instance to use
:param allow_column_valves_open: Allow remote client to open column valves
"""
if microscope_factory is None:
from .microscope import Microscope
microscope_factory = Microscope
self.microscope = microscope_factory()
self.allow_column_valves_open = allow_column_valves_open
super(MicroscopeServer, self).__init__(server_address, MicroscopeHandler)


Expand Down

0 comments on commit c52d1bb

Please sign in to comment.