133133# Bit 7: Lower limit switch: 0 = open, 1 = closed
134134
135135
136- def parse_info (info : list ) -> dict [str , dict [str , Union [typing .Optional [str ], Any ]]]:
137-
136+ def parse_info (
137+ info : list ,
138+ ) -> dict [str , dict [str , Union [typing .Optional [str ], Any ]]]:
138139 items = []
139140 for line in info :
140141 if line in [b"" , b"\n " , b"\r " , b"\r \n " ]:
@@ -147,10 +148,14 @@ def parse_info(info: list) -> dict[str, dict[str, Union[typing.Optional[str], An
147148 settings = {}
148149 for item in items :
149150 match = re .search (pattern , item )
150- settings [match .group ('name' ).strip ()] = {
151- 'value' : match .group ('value' ),
152- 'command' : None if not match .group ('command' ) else match .group ('command' )[1 :- 1 ],
153- 'units' : match .group ('units' ) if len (match .group ('units' )) else None ,
151+ settings [match .group ("name" ).strip ()] = {
152+ "value" : match .group ("value" ),
153+ "command" : None
154+ if not match .group ("command" )
155+ else match .group ("command" )[1 :- 1 ],
156+ "units" : match .group ("units" )
157+ if len (match .group ("units" ))
158+ else None ,
154159 }
155160
156161 return settings
@@ -200,9 +205,7 @@ def __init__(self, port: str, baudrate: int, timeout: float) -> None:
200205 self .axis_info [axis ] = parse_info (answer )
201206 self ._axis_mapper [i ] = axis
202207 except :
203- print (
204- "Unable to read configuration. Is ASI controller connected?"
205- )
208+ print ("Unable to read configuration. Is ASI controller connected?" )
206209 return
207210 # parse config responce which tells us what devices are present
208211 # on this controller.
@@ -436,7 +439,9 @@ def __init__(self, conn: _ASIMotionController, **kwargs) -> None:
436439 self .homed = False
437440
438441 def _get_setting (self , command , axis , dtype ):
439- answer = self ._dev_conn .get_command (bytes (f"{ command } { axis } ?" , "ascii" ))
442+ answer = self ._dev_conn .get_command (
443+ bytes (f"{ command } { axis } ?" , "ascii" )
444+ )
440445 answer = answer .strip ().decode ()
441446 if answer [:2 ] == ":A" :
442447 if dtype == "int" :
@@ -457,33 +462,38 @@ def _get_setting(self, command, axis, dtype):
457462 def _set_setting (self , value , command , axis ):
458463 self ._dev_conn .set_command (bytes (f"{ command } { axis } ={ value } " , "ascii" ))
459464
460-
461465 def _add_settings (self , settings ) -> None :
462466 """INFO command returns a list of settings that is parsed into a dict. This function takes that dict and
463467 adds settings consequently to the stage object.
464468 """
465469 for axis , axis_settings in settings .items ():
466470 for setting_name , setting_params in axis_settings .items ():
467- if setting_params [' value' ].isdigit ():
468- value = int (setting_params [' value' ])
471+ if setting_params [" value" ].isdigit ():
472+ value = int (setting_params [" value" ])
469473 dtype = "int"
470- elif setting_params [' value' ].replace ('.' , '' , 1 ).isdigit ():
471- value = float (setting_params [' value' ])
474+ elif setting_params [" value" ].replace ("." , "" , 1 ).isdigit ():
475+ value = float (setting_params [" value" ])
472476 dtype = "float"
473477 else :
474- value = setting_params [' value' ]
478+ value = setting_params [" value" ]
475479 dtype = "str" # It might be a enum but we dont know
476480
477- if setting_params [' command' ] is not None :
481+ if setting_params [" command" ] is not None :
478482 read_only = False
479483 else :
480484 read_only = True
481485
482486 self .add_setting (
483487 name = f"{ setting_name } { axis } " ,
484488 dtype = dtype ,
485- get_func = lambda command = setting_params ['command' ], axis = axis , dtype = dtype : self ._get_setting (command , axis , dtype ),
486- set_func = lambda value , command = setting_params ['command' ], axis = axis : self ._set_setting (value , command , axis ),
489+ get_func = lambda command = setting_params [
490+ "command"
491+ ], axis = axis , dtype = dtype : self ._get_setting (
492+ command , axis , dtype
493+ ),
494+ set_func = lambda value , command = setting_params [
495+ "command"
496+ ], axis = axis : self ._set_setting (value , command , axis ),
487497 values = lambda : f"curr value is { value } . Units are { setting_params ['units' ]} " ,
488498 # readonly=read_only,
489499 )
@@ -589,7 +599,7 @@ class ASIMS2000(microscope.abc.Controller):
589599 """
590600
591601 def __init__ (
592- self , port : str , baudrate : int = 9600 , timeout : float = 0.5 , ** kwargs
602+ self , port : str , baudrate : int = 9600 , timeout : float = 0.5 , ** kwargs
593603 ) -> None :
594604 super ().__init__ (** kwargs )
595605 self ._conn = _ASIMotionController (port , baudrate , timeout )
0 commit comments