@@ -16,7 +16,7 @@ class MicroscopeHandler(BaseHTTPRequestHandler):
1616 "condenser_stigmator" , "diffraction_shift" , "screen_current" , "screen_position" ,
1717 "illumination_mode" , "condenser_mode" , "illuminated_area" , "probe_defocus" , "convergence_angle" ,
1818 "stem_magnification" , "stem_rotation" , "spot_size_index" , "dark_field_mode" , "beam_blanked" ,
19- "instrument_mode" , 'optics_state' , 'state' )
19+ "instrument_mode" , 'optics_state' , 'state' , 'column_valves_open' )
2020
2121 PUT_V1_FORWARD = ("image_shift" , "beam_shift" , "beam_tilt" , "projection_mode" , "magnification_index" ,
2222 "defocus" , "intensity" , "diffraction_shift" , "objective_stigmator" , "condenser_stigmator" ,
@@ -126,6 +126,13 @@ def do_PUT_V1(self, endpoint, query):
126126 response = self .get_microscope ().set_detector_param (name , decoded_content )
127127 elif endpoint == "normalize" :
128128 self .get_microscope ().normalize (decoded_content )
129+ elif endpoint == "column_valves_open" :
130+ state = bool (decoded_content )
131+ assert isinstance (self .server , MicroscopeServer )
132+ if self .server .allow_column_valves_open or not state :
133+ self .get_microscope ().set_column_valves_open (state )
134+ else :
135+ raise ValueError ("Opening of column valves is prohibited." )
129136 else :
130137 raise KeyError ("Unknown endpoint: '%s'" % endpoint )
131138 return response
@@ -166,17 +173,19 @@ def do_PUT(self):
166173
167174
168175class MicroscopeServer (HTTPServer , object ):
169- def __init__ (self , server_address = ('' , 8080 ), microscope_factory = None ):
176+ def __init__ (self , server_address = ('' , 8080 ), microscope_factory = None , allow_column_valves_open = True ):
170177 """
171178 Run a microscope server.
172179
173180 :param server_address: (address, port) tuple
174181 :param microscope_factory: callable creating the BaseMicroscope instance to use
182+ :param allow_column_valves_open: Allow remote client to open column valves
175183 """
176184 if microscope_factory is None :
177185 from .microscope import Microscope
178186 microscope_factory = Microscope
179187 self .microscope = microscope_factory ()
188+ self .allow_column_valves_open = allow_column_valves_open
180189 super (MicroscopeServer , self ).__init__ (server_address , MicroscopeHandler )
181190
182191
0 commit comments