@@ -215,8 +215,7 @@ def __init__(self, port: str, baudrate: int, timeout: float) -> None:
215215 # if this is not a ProScan device it would never reach the
216216 # '\rEND\r' that signals the end of the description.
217217 self .axis_info = {}
218- self ._axis_mapper = {}
219- i = 1
218+ self .axis_list = []
220219 try :
221220 for axis in ["X" , "Y" , "Z" ]:
222221 self .command (bytes (f"INFO { axis } " , "ascii" ))
@@ -226,14 +225,13 @@ def __init__(self, port: str, baudrate: int, timeout: float) -> None:
226225 continue
227226 _logger .info (f"Axis { axis } present" )
228227 self .axis_info [axis ] = parse_info (answer )
229- self ._axis_mapper [i ] = axis
230- i += 1
231228 except :
232229 print ("Unable to read configuration. Is ASI controller connected?" )
233230 return
231+ self .axis_list .append (axis )
234232
235233 # As for this version, some MS2000 controllers have integrated control for 2 LEDs
236- self ._led_mapper = [b"X" , b"Y" ]
234+ self .led_list = [b"X" , b"Y" ]
237235
238236 # parse config response which tells us what devices are present
239237 # on this controller.
@@ -242,10 +240,10 @@ def is_busy(self):
242240 pass
243241
244242 def get_number_axes (self ):
245- return len (self ._axis_mapper )
243+ return len (self .axis_list )
246244
247245 def get_number_leds (self ):
248- return len (self ._led_mapper )
246+ return len (self .led_list )
249247
250248 def command (self , command : bytes ) -> None :
251249 """Send command to device."""
@@ -343,59 +341,67 @@ def move_command(self, command: bytes) -> None:
343341 # self.get_command(command)
344342
345343 def move_by_relative_position (
346- self , axis : int , delta : float , wait = True
344+ self , axis : str , delta : float , wait = True
347345 ) -> None :
348346 """Send a relative movement command to stated axis"""
349- axis_name = self ._axis_mapper [axis ]
350- self .move_command (bytes (f"MOVREL { axis_name } ={ str (delta )} " , "ascii" ))
347+ if axis not in self .axis_list :
348+ raise ValueError (f"Axis { axis } not present. Verify the name of the axis or your configuration files." )
349+ self .move_command (bytes (f"MOVREL { axis } ={ str (delta )} " , "ascii" ))
351350 if wait :
352351 self .wait_for_motor_stop (axis )
353352
354353 def move_to_absolute_position (
355- self , axis : int , pos : float , wait = True
354+ self , axis : str , pos : float , wait = True
356355 ) -> None :
357356 """Send a relative movement command to stated axis"""
358- axis_name = self ._axis_mapper [axis ]
359- self .move_command (bytes (f"MOVE { axis_name } ={ str (pos )} " , "ascii" ))
357+ if axis not in self .axis_list :
358+ raise ValueError (f"Axis { axis } not present. Verify the name of the axis or your configuration files." )
359+ self .move_command (bytes (f"MOVE { axis } ={ str (pos )} " , "ascii" ))
360360 if wait :
361361 self .wait_for_motor_stop (axis )
362362
363- def move_to_limit (self , axis : int , speed : int ):
364- axis_name = self ._axis_mapper [axis ]
365- self .get_command (bytes (f"SPIN { axis_name } ={ speed } " , "ascii" ))
363+ def move_to_limit (self , axis : str , speed : int ):
364+ if axis not in self .axis_list :
365+ raise ValueError (f"Axis { axis } not present. Verify the name of the axis or your configuration files." )
366+ self .get_command (bytes (f"SPIN { axis } ={ speed } " , "ascii" ))
366367
367- def motor_moving (self , axis : int ) -> int :
368- axis_name = self ._axis_mapper [axis ]
369- reply = self .get_command (bytes (f"RDSTAT { axis_name } " , "ascii" ))
368+ def motor_moving (self , axis : str ) -> int :
369+ if axis not in self .axis_list :
370+ raise ValueError (f"Axis { axis } not present. Verify the name of the axis or your configuration files." )
371+ reply = self .get_command (bytes (f"RDSTAT { axis } " , "ascii" ))
370372 flags = int (reply .strip ()[3 :])
371373 return flags & 1
372374
373- def set_speed (self , axis : int , speed : int ) -> None :
374- axis_name = self ._axis_mapper [axis ]
375- self .get_command (bytes (f"SPEED { axis_name } ={ speed } " , "ascii" ))
375+ def set_speed (self , axis : str , speed : int ) -> None :
376+ if axis not in self .axis_list :
377+ raise ValueError (f"Axis { axis } not present. Verify the name of the axis or your configuration files." )
378+ self .get_command (bytes (f"SPEED { axis } ={ speed } " , "ascii" ))
376379
377- def find_max_speed (self , axis : int ):
378- axis_name = self ._axis_mapper [axis ]
380+ def find_max_speed (self , axis : str ):
381+ if axis not in self .axis_list :
382+ raise ValueError (f"Axis { axis } not present. Verify the name of the axis or your configuration files." )
379383 speed = 100000000
380384 #set the speed
381- self .get_command (bytes (f"SPEED { axis_name } ={ speed } " , "ascii" ))
385+ self .get_command (bytes (f"SPEED { axis } ={ speed } " , "ascii" ))
382386 #read off the max speed set by controller
383- response = self .get_command (bytes (f"SPEED { axis_name } ?" , "ascii" ))
387+ response = self .get_command (bytes (f"SPEED { axis } ?" , "ascii" ))
384388 return (float (response .strip ()[5 :]))
385389
386- def wait_for_motor_stop (self , axis : int ):
390+ def wait_for_motor_stop (self , axis : str ):
387391 # give axis a chance to start maybe?
388392 time .sleep (0.2 )
389393 while self .motor_moving (axis ):
390394 time .sleep (0.1 )
391395
392- def reset_position (self , axis : int ):
393- axis_name = self ._axis_mapper [axis ]
394- self .get_command (bytes (f"HERE { axis_name } =0" , "ascii" ))
396+ def reset_position (self , axis : str ):
397+ if axis not in self .axis_list :
398+ raise ValueError (f"Axis { axis } not present. Verify the name of the axis or your configuration files." )
399+ self .get_command (bytes (f"HERE { axis } =0" , "ascii" ))
395400
396- def get_absolute_position (self , axis : int ) -> float :
397- axis_name = self ._axis_mapper [axis ]
398- position = self .get_command (bytes (f"WHERE { axis_name } " , "ascii" ))
401+ def get_absolute_position (self , axis : str ) -> float :
402+ if axis not in self .axis_list :
403+ raise ValueError (f"Axis { axis } not present. Verify the name of the axis or your configuration files." )
404+ position = self .get_command (bytes (f"WHERE { axis } " , "ascii" ))
399405 if position [3 :4 ] == b"N" :
400406 print (f"Error: { position } : { _ASI_ERRORS [int (position [4 :6 ])]} " )
401407 else :
@@ -406,16 +412,16 @@ def is_led_on(self, channel):
406412 return bool (self .get_led_power (channel ))
407413
408414 def get_led_power (self , channel ):
409- answer = self .get_command (b"LED " + self ._led_mapper [channel ] + b"?" )
415+ answer = self .get_command (b"LED " + self .led_list [channel ] + b"?" )
410416 return int (answer [3 :- 4 ]) / 100
411417
412418 def set_led_power (self , channel , power ):
413419 power = str (int (power * 100 )).encode ()
414- self .get_command (b"LED " + self ._led_mapper [channel ] + b"=" + power )
420+ self .get_command (b"LED " + self .led_list [channel ] + b"=" + power )
415421
416422
417423class _ASIStageAxis (microscope .abc .StageAxis ):
418- def __init__ (self , dev_conn : _ASIController , axis : int ) -> None :
424+ def __init__ (self , dev_conn : _ASIController , axis : str ) -> None :
419425 super ().__init__ ()
420426 self ._dev_conn = dev_conn
421427 self ._axis = axis
@@ -489,8 +495,8 @@ def __init__(self, conn: _ASIController, **kwargs) -> None:
489495 super ().__init__ (** kwargs )
490496 self ._dev_conn = conn
491497 self ._axes = {
492- str ( i ) : _ASIStageAxis (self ._dev_conn , i )
493- for i in range ( 1 , self ._dev_conn .get_number_axes () + 1 )
498+ a : _ASIStageAxis (self ._dev_conn , a )
499+ for a in self ._dev_conn .axis_list
494500 }
495501
496502 self ._add_settings (self ._dev_conn .axis_info )
@@ -616,7 +622,7 @@ def move_by(self, delta: typing.Mapping[str, float]) -> None:
616622 """Move specified axes by the specified distance."""
617623 for axis_name , axis_delta in delta .items ():
618624 self ._dev_conn .move_by_relative_position (
619- int ( axis_name ) , int (axis_delta ), wait = False
625+ axis_name , int (axis_delta ), wait = False
620626 )
621627 self ._dev_conn .wait_until_idle ()
622628
@@ -625,7 +631,7 @@ def move_to(self, position: typing.Mapping[str, float]) -> None:
625631 print (position )
626632 for axis_name , axis_position in position .items ():
627633 self ._dev_conn .move_to_absolute_position (
628- int ( axis_name ) , int (axis_position ), wait = False
634+ axis_name , int (axis_position ), wait = False
629635 )
630636 self ._dev_conn .wait_until_idle ()
631637
0 commit comments