BioImager  4.9.0
A .NET microscopy imaging application based on Bio library. Supports various microscopes by using imported libraries & GUI automation. Supports XInput game controllers to move stage, take images, run ImageJ macros on images or Bio C# scripts.
Loading...
Searching...
No Matches
microscope.lights.sapphire.SapphireLaser Class Reference
Inheritance diagram for microscope.lights.sapphire.SapphireLaser:
microscope._utils.OnlyTriggersBulbOnSoftwareMixin microscope.abc.SerialDeviceMixin microscope.abc.LightSource microscope.abc.TriggerTargetMixin microscope.abc.TriggerTargetMixin microscope.abc.Device

Public Member Functions

 __init__ (self, com=None, baud=19200, timeout=0.5, **kwargs)
 
 send (self, command)
 
 clearFault (self)
 
 flush_buffer (self)
 
 get_status (self)
 
 initialize (self)
 
 disable (self)
 
 get_is_on (self)
 
- Public Member Functions inherited from microscope._utils.OnlyTriggersBulbOnSoftwareMixin
microscope.TriggerType trigger_type (self)
 
microscope.TriggerMode trigger_mode (self)
 
None set_trigger (self, microscope.TriggerType ttype, microscope.TriggerMode tmode)
 
- Public Member Functions inherited from microscope.abc.TriggerTargetMixin
None trigger (self)
 
- Public Member Functions inherited from microscope.abc.SerialDeviceMixin
- Public Member Functions inherited from microscope.abc.LightSource
float power (self)
 
None power (self, float power)
 
float get_set_power (self)
 
- Public Member Functions inherited from microscope.abc.Device
None __del__ (self)
 
bool get_is_enabled (self)
 
None enable (self)
 
None shutdown (self)
 
None add_setting (self, name, dtype, get_func, set_func, values, typing.Optional[typing.Callable[[], bool]] readonly=None)
 
 get_setting (self, str name)
 
 get_all_settings (self)
 
None set_setting (self, str name, value)
 
 describe_setting (self, str name)
 
 describe_settings (self)
 
 update_settings (self, incoming, bool init=False)
 

Public Attributes

 connection
 
- Public Attributes inherited from microscope.abc.SerialDeviceMixin
 connection = None
 
- Public Attributes inherited from microscope.abc.Device
bool enabled = False
 

Static Public Attributes

dict laser_status
 

Protected Member Functions

 _write (self, command)
 
None _do_shutdown (self)
 
 _do_enable (self)
 
 _get_power_mw (self)
 
 _set_power_mw (self, mW)
 
None _do_set_power (self, float power)
 
float _do_get_power (self)
 
- Protected Member Functions inherited from microscope._utils.OnlyTriggersBulbOnSoftwareMixin
None _do_trigger (self)
 
- Protected Member Functions inherited from microscope.abc.TriggerTargetMixin
- Protected Member Functions inherited from microscope.abc.SerialDeviceMixin
bytes _readline (self)
 
- Protected Member Functions inherited from microscope.abc.LightSource
- Protected Member Functions inherited from microscope.abc.Device
 _do_disable (self)
 

Protected Attributes

 _max_power_mw = float(self.send(b"?maxlp"))
 
 _min_power = float(self.send(b"?minlp")) / self._max_power_mw
 
- Protected Attributes inherited from microscope.abc.SerialDeviceMixin
 _comms_lock = threading.RLock()
 
- Protected Attributes inherited from microscope.abc.LightSource
float _set_point = 0.0
 
- Protected Attributes inherited from microscope.abc.Device
dict _settings = {}
 

Additional Inherited Members

- Static Public Member Functions inherited from microscope.abc.SerialDeviceMixin
 lock_comms (func)
 

Detailed Description

Coherent Sapphire laser.

The Sapphire is a diode-pumped solid-state laser and only supports
`TriggerMode.SOFTWARE`.

Definition at line 34 of file sapphire.py.

Constructor & Destructor Documentation

◆ __init__()

microscope.lights.sapphire.SapphireLaser.__init__ ( self,
com = None,
baud = 19200,
timeout = 0.5,
** kwargs )

Reimplemented from microscope.abc.SerialDeviceMixin.

Definition at line 55 of file sapphire.py.

55 def __init__(self, com=None, baud=19200, timeout=0.5, **kwargs):
56 # laser controller must run at 19200 baud, 8+1 bits,
57 # no parity or flow control
58 # timeout is recomended to be over 0.5
59 super().__init__(**kwargs)
60 self.connection = serial.Serial(
61 port=com,
62 baudrate=baud,
63 timeout=timeout,
64 stopbits=serial.STOPBITS_ONE,
65 bytesize=serial.EIGHTBITS,
66 parity=serial.PARITY_NONE,
67 )
68 # Turning off command prompt
69 self.send(b">=0")
70
71 # The sapphire laser turns on as soon as the key is switched
72 # on. So turn radiation off before we start.
73 self.send(b"L=0")
74
75 # Head ID value is a float point value,
76 # but only the integer part is significant
77 headID = int(float(self.send(b"?hid")))
78 _logger.info("Sapphire laser serial number: [%s]", headID)
79
80 self._max_power_mw = float(self.send(b"?maxlp"))
81 self._min_power = float(self.send(b"?minlp")) / self._max_power_mw
82
83 self.initialize()
84

Member Function Documentation

◆ _do_enable()

microscope.lights.sapphire.SapphireLaser._do_enable ( self)
protected
Do any device specific work on enable.

Subclasses should override this method, rather than modify
`enable`.

Reimplemented from microscope.abc.Device.

Definition at line 153 of file sapphire.py.

153 def _do_enable(self):
154 _logger.info("Turning laser ON.")
155 # Turn on emission.
156 response = self.send(b"l=1")
157 _logger.info("l=1: [%s]", response.decode())
158
159 # Enabling laser might take more than 500ms (default timeout)
160 prevTimeout = self.connection.timeout
161 self.connection.timeout = max(1, prevTimeout)
162 isON = self.get_is_on()
163 self.connection.timeout = prevTimeout
164
165 if not isON:
166 # Something went wrong.
167 _logger.error("Failed to turn on. Current status:\r\n")
168 _logger.error(self.get_status())
169 return isON
170

◆ _do_get_power()

float microscope.lights.sapphire.SapphireLaser._do_get_power ( self)
protected
Internal function that actually returns the light source power.

Reimplemented from microscope.abc.LightSource.

Definition at line 201 of file sapphire.py.

201 def _do_get_power(self) -> float:
202 return self._get_power_mw() / self._max_power_mw

◆ _do_set_power()

None microscope.lights.sapphire.SapphireLaser._do_set_power ( self,
float power )
protected
Internal function that actually sets the light source power.

This function will be called by the `power` attribute setter
after clipping the argument to the [0, 1] interval.

Reimplemented from microscope.abc.LightSource.

Definition at line 194 of file sapphire.py.

194 def _do_set_power(self, power: float) -> None:
195 # power is already clipped to the [0 1] range but we need to
196 # clip it again since the min power we actually can do is 0.2
197 # and we get an error from the laser if we set it to lower.
198 power = max(self._min_power, power)
199 self._set_power_mw(power * self._max_power_mw)
200

◆ _do_shutdown()

None microscope.lights.sapphire.SapphireLaser._do_shutdown ( self)
protected
Private method - actual shutdown of the device.

Users should be calling :meth:`shutdown` and not this method.
Concrete implementations should implement this method instead
of `shutdown`.

Reimplemented from microscope.abc.Device.

Definition at line 141 of file sapphire.py.

141 def _do_shutdown(self) -> None:
142 # Disable laser.
143 self._write(b"l=0")
144 self.flush_buffer()
145

◆ _get_power_mw()

microscope.lights.sapphire.SapphireLaser._get_power_mw ( self)
protected

Definition at line 183 of file sapphire.py.

183 def _get_power_mw(self):
184 return float(self.send(b"?p"))
185

◆ _set_power_mw()

microscope.lights.sapphire.SapphireLaser._set_power_mw ( self,
mW )
protected

Definition at line 187 of file sapphire.py.

187 def _set_power_mw(self, mW):
188 mW_str = "%.3f" % mW
189 _logger.info("Setting laser power to %s mW.", mW_str)
190 # using send instead of _write, because
191 # if laser is not on, warning is returned
192 return self.send(b"p=%s" % mW_str.encode())
193

◆ _write()

microscope.lights.sapphire.SapphireLaser._write ( self,
command )
protected
Send a command to the device.

This is not a simple passthrough to ``serial.Serial.write``,
it will append ``b'\\r\\n'`` to command.  Override this method
if a device requires a specific format.

Reimplemented from microscope.abc.SerialDeviceMixin.

Definition at line 85 of file sapphire.py.

85 def _write(self, command):
86 count = super()._write(command)
87 # This device always writes backs something. If echo is on,
88 # it's the whole command, otherwise just an empty line. Read
89 # it and throw it away.
90 self._readline()
91 return count
92

◆ clearFault()

microscope.lights.sapphire.SapphireLaser.clearFault ( self)

Definition at line 99 of file sapphire.py.

99 def clearFault(self):
100 self.flush_buffer()
101 return self.get_status()
102

◆ disable()

microscope.lights.sapphire.SapphireLaser.disable ( self)
Disable the device for a short period for inactivity.

Reimplemented from microscope.abc.Device.

Definition at line 173 of file sapphire.py.

173 def disable(self):
174 _logger.info("Turning laser OFF.")
175 return self._write(b"l=0")
176

◆ flush_buffer()

microscope.lights.sapphire.SapphireLaser.flush_buffer ( self)

Definition at line 103 of file sapphire.py.

103 def flush_buffer(self):
104 line = b" "
105 while len(line) > 0:
106 line = self._readline()
107

◆ get_is_on()

microscope.lights.sapphire.SapphireLaser.get_is_on ( self)
Return True if the light source is currently able to produce light.

Reimplemented from microscope.abc.LightSource.

Definition at line 179 of file sapphire.py.

179 def get_is_on(self):
180 return self.send(b"?l") == b"1"
181

◆ get_status()

microscope.lights.sapphire.SapphireLaser.get_status ( self)
Query and return the light source status.

Reimplemented from microscope.abc.LightSource.

Definition at line 109 of file sapphire.py.

109 def get_status(self):
110 result = []
111
112 status_code = self.send(b"?sta")
113 result.append(
114 (
115 "Laser status: "
116 + self.laser_status.get(status_code, "Undefined")
117 )
118 )
119
120 for cmd, stat in [
121 (b"?l", "Ligh Emission on?"),
122 (b"?t", "TEC Servo on?"),
123 (b"?k", "Key Switch on?"),
124 (b"?sp", "Target power:"),
125 (b"?p", "Measured power:"),
126 (b"?hh", "Head operating hours:"),
127 ]:
128 result.append(stat + " " + self.send(cmd).decode())
129
130 self._write(b"?fl")
131 faults = self._readline()
132 response = self._readline()
133 while response:
134 faults += b" " + response
135 response = self._readline()
136
137 result.append(faults.decode())
138 return result
139

◆ initialize()

microscope.lights.sapphire.SapphireLaser.initialize ( self)
Initialize the device.

If devices have this method (not required, and many don't),
then they should call it as part of the initialisation, i.e.,
they should call it on their `__init__` method.

Reimplemented from microscope.abc.Device.

Definition at line 148 of file sapphire.py.

148 def initialize(self):
149 self.flush_buffer()
150

◆ send()

microscope.lights.sapphire.SapphireLaser.send ( self,
command )
Send command and retrieve response.

Definition at line 93 of file sapphire.py.

93 def send(self, command):
94 """Send command and retrieve response."""
95 self._write(command)
96 return self._readline()
97

Member Data Documentation

◆ _max_power_mw

microscope.lights.sapphire.SapphireLaser._max_power_mw = float(self.send(b"?maxlp"))
protected

Definition at line 80 of file sapphire.py.

◆ _min_power

microscope.lights.sapphire.SapphireLaser._min_power = float(self.send(b"?minlp")) / self._max_power_mw
protected

Definition at line 81 of file sapphire.py.

◆ connection

microscope.lights.sapphire.SapphireLaser.connection
Initial value:
= serial.Serial(
port=com,
baudrate=baud,
timeout=timeout,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
parity=serial.PARITY_NONE,
)

Definition at line 60 of file sapphire.py.

◆ laser_status

dict microscope.lights.sapphire.SapphireLaser.laser_status
static
Initial value:
= {
b"1": "Start up",
b"2": "Warmup",
b"3": "Standby",
b"4": "Laser on",
b"5": "Laser ready",
b"6": "Error",
}

Definition at line 46 of file sapphire.py.


The documentation for this class was generated from the following file: