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.testsuite.mock_devices.CoherentSapphireLaserMock Class Reference
Inheritance diagram for microscope.testsuite.mock_devices.CoherentSapphireLaserMock:
microscope.testsuite.mock_devices.SerialMock

Public Member Functions

 __init__ (self, *args, **kwargs)
 
 write (self, data)
 
 handle (self, command)
 
- Public Member Functions inherited from microscope.testsuite.mock_devices.SerialMock
 open (self)
 
 close (self)
 
 read (self, size=1)
 
 readline (self, size=-1)
 
 reset_input_buffer (self)
 
 reset_output_buffer (self)
 

Public Attributes

str key = "on"
 
str status = "laser ready"
 
bool light = True
 
bool tec = True
 
bool echo = True
 
bool prompt = True
 
float power = CoherentSapphireLaserMock.default_power
 
str light = b"0.000"
 
str power = b"NOMP":
 
- Public Attributes inherited from microscope.testsuite.mock_devices.SerialMock
 in_buffer = io.BytesIO()
 
 out_buffer = io.BytesIO()
 
int out_pending_bytes = 0
 
int out_parsed_bytes = 0
 
int in_read_bytes = 0
 
 eol = self.out_buffer.read(self.out_pending_bytes)
 

Static Public Attributes

str eol = b"\r\n"
 
int baudrate = 19200
 
 parity = serial.PARITY_NONE
 
 bytesize = serial.EIGHTBITS
 
 stopbits = serial.STOPBITS_ONE
 
bool rtscts = False
 
bool dsrdtr = False
 
float default_power = 50.0
 
float min_power = 20.0
 
float max_power = 220.0
 

Additional Inherited Members

- Protected Member Functions inherited from microscope.testsuite.mock_devices.SerialMock
 _readx_wrapper (self, reader, *args, **kwargs)
 

Detailed Description

Modelled after a Coherent Sapphire LP 561nm laser.

This mocked device is constructed into the ready state.  That is,
after the laser has been turned on enough time to warmup (~ 30
seconds), and then the key has been turned on for enough time to
actual get the laser ready (~10 seconds).

We don't mock the turning of the key, that's much trickier and we
don't need it yet.  We'll do it if it ever becomes an issue, and
probably use a state machine library for that.

Definition at line 107 of file mock_devices.py.

Constructor & Destructor Documentation

◆ __init__()

microscope.testsuite.mock_devices.CoherentSapphireLaserMock.__init__ ( self,
* args,
** kwargs )

Reimplemented from microscope.testsuite.mock_devices.SerialMock.

Definition at line 136 of file mock_devices.py.

136 def __init__(self, *args, **kwargs):
137 super().__init__(*args, **kwargs)
138
139 self.key = "on"
140 self.status = "laser ready" # Laser ready, status code 5
141 self.light = True # Light Servo
142 self.tec = True # TEC (Thermo-Electric Cooler) Servo
143 self.echo = True
144 self.prompt = True
145 self.power = CoherentSapphireLaserMock.default_power
146

Member Function Documentation

◆ handle()

microscope.testsuite.mock_devices.CoherentSapphireLaserMock.handle ( self,
command )

Reimplemented from microscope.testsuite.mock_devices.SerialMock.

Definition at line 158 of file mock_devices.py.

158 def handle(self, command):
159 # Operator's manual mentions all commands in uppercase.
160 # Experimentation shows that they are case insensitive.
161 command = command.upper()
162
163 answer = None
164
165 # Prompt
166 if command == b">=0":
167 self.prompt = False
168 elif command == b">=1":
169 self.prompt = True
170
171 # Echo
172 elif command == b"E=0":
173 self.echo = False
174 elif command == b"E=1":
175 self.echo = True
176
177 # Head ID
178 elif command == b"?HID":
179 answer = b"505925.000"
180
181 # Head hours
182 elif command == b"?HH":
183 answer = b" 257:34"
184
185 # Key switch
186 elif command == b"?K":
187 if self.key == "standby":
188 answer = b"0"
189 elif self.key == "on":
190 answer = b"1"
191 else:
192 raise RuntimeError("unknown key state '%s'" % self.key)
193
194 # Light servo
195 elif command == b"L=0":
196 self.light = False
197 elif command == b"L=1":
198 if self.tec:
199 if self.key == "on":
200 self.light = True
201 # if key switch is not on, keep light off
202 else:
203 answer = b"TEC must be ON (T=1) to enable Light Output!"
204 elif command == b"?L":
205 answer = b"1" if self.light else b"0"
206
207 # TEC servo
208 elif command == b"T=0":
209 # turning this off, also turns light servo off
210 self.tec = False
211 self.light = False
212 elif command == b"T=1":
213 self.tec = True
214 elif command == b"?T":
215 answer = b"1" if self.tec else b"0"
216
217 # Laser power
218 elif command == b"?MINLP":
219 answer = b"20.000"
220 elif command == b"?MAXLP":
221 answer = b"220.000"
222 elif command == b"?P":
223 if not self.light:
224 answer = b"0.000"
225 else:
226 answer = b"%.3f" % (self.power)
227 elif command == b"?SP":
228 answer = b"%.3f" % (self.power)
229 elif command.startswith(b"P="):
230 new_power = float(command[2:])
231 if new_power < 19.999999 or new_power > 220.00001:
232 answer = b"value must be between 20.000 and 220.000"
233 else:
234 if not self.light:
235 answer = b"Note: Laser_Output is OFF (L=0)"
236 self.power = new_power
237
238 # Nominal output power
239 elif command == b"NOMP":
240 answer = b"200"
241
242 # Laser type and nominal power
243 elif command == b"LT":
244 answer = b"Sapphire 200mW"
245
246 # Laser head status
247 elif command == b"?STA":
248 status_codes = {
249 "start up": b"1",
250 "warmup": b"2",
251 "standby": b"3",
252 "laser on": b"4",
253 "laser ready": b"5",
254 "error": b"6",
255 }
256 answer = status_codes[self.status]
257
258 # Fault related commands. We don't model any faults yet.
259 elif command == b"?F":
260 answer = b"0"
261 elif command == b"?FF":
262 # Two bytes with possible faults:
263 # 0 - external interlock fault
264 # 1 - diode temperature fault (both TEC and light
265 # servo off)
266 # 2 - base plate temperature fault (both TEC and light
267 # servo off)
268 # 3 - OEM controller LP temperature (both TEC and
269 # light servo off)
270 # 4 - diode current fault
271 # 5 - analog interface fault
272 # 6 - base plate temperature fault (only light servo
273 # turned off)
274 # 7 - diode temperature fault (only light servo turned
275 # off)
276 # 8 - system warning/waiting for TEC servo to reach
277 # target temperature
278 # 9 - head EEPROM fault
279 # 10 - OEM controller LP EEPROM fault
280 # 11 - EEPOT1 fault
281 # 12 - EEPOT2 fault
282 # 13 - laser ready
283 # 14 - not implemented
284 # 15 - not implemented
285 if self.light:
286 # Has a bit of its own, but it's not really a fault.
287 answer = b"8192" # 00100000 00000000
288 else:
289 answer = b"0"
290 elif command == b"?FL":
291 # Show faults in text. This is a multiline reply, one
292 # per fault, plus the header line.
293 answer = b"Fault(s):\r\n\tNone"
294
295 # Software version
296 elif command in [b"sv", b"svps"]:
297 answer = b"8.005"
298
299 # Nominal laser wavelength
300 elif command == b"?WAVE":
301 answer = b"561"
302
303 else:
304 raise NotImplementedError(
305 "no handling for command '%s'" % command.decode("utf-8")
306 )
307
308 if answer is not None:
309 self.in_buffer.write(answer + self.eol)
310
311 if self.prompt:
312 self.in_buffer.write(b"Sapphire:0-> ")
313 return
314
315

◆ write()

microscope.testsuite.mock_devices.CoherentSapphireLaserMock.write ( self,
data )

Reimplemented from microscope.testsuite.mock_devices.SerialMock.

Definition at line 147 of file mock_devices.py.

147 def write(self, data):
148 # Echo as soon as we get data, do not wait for an EOL. Also,
149 # echo before handling the command because if will echo even
150 # if the command is to turn the echo off.
151 if self.echo:
152 self.in_buffer.write(data)
153 else:
154 # If echo is off, we still echo EOLs
155 self.in_buffer.write(self.eol * data.count(self.eol))
156 return super().write(data)
157

Member Data Documentation

◆ baudrate

int microscope.testsuite.mock_devices.CoherentSapphireLaserMock.baudrate = 19200
static

Definition at line 124 of file mock_devices.py.

◆ bytesize

microscope.testsuite.mock_devices.CoherentSapphireLaserMock.bytesize = serial.EIGHTBITS
static

Definition at line 126 of file mock_devices.py.

◆ default_power

float microscope.testsuite.mock_devices.CoherentSapphireLaserMock.default_power = 50.0
static

Definition at line 132 of file mock_devices.py.

◆ dsrdtr

bool microscope.testsuite.mock_devices.CoherentSapphireLaserMock.dsrdtr = False
static

Definition at line 129 of file mock_devices.py.

◆ echo

bool microscope.testsuite.mock_devices.CoherentSapphireLaserMock.echo = True

Definition at line 143 of file mock_devices.py.

◆ eol

microscope.testsuite.mock_devices.CoherentSapphireLaserMock.eol = b"\r\n"
static

Definition at line 121 of file mock_devices.py.

◆ key

str microscope.testsuite.mock_devices.CoherentSapphireLaserMock.key = "on"

Definition at line 139 of file mock_devices.py.

◆ light [1/2]

str microscope.testsuite.mock_devices.CoherentSapphireLaserMock.light = True

Definition at line 141 of file mock_devices.py.

◆ light [2/2]

str microscope.testsuite.mock_devices.CoherentSapphireLaserMock.light = b"0.000"

Definition at line 223 of file mock_devices.py.

◆ max_power

float microscope.testsuite.mock_devices.CoherentSapphireLaserMock.max_power = 220.0
static

Definition at line 134 of file mock_devices.py.

◆ min_power

float microscope.testsuite.mock_devices.CoherentSapphireLaserMock.min_power = 20.0
static

Definition at line 133 of file mock_devices.py.

◆ parity

microscope.testsuite.mock_devices.CoherentSapphireLaserMock.parity = serial.PARITY_NONE
static

Definition at line 125 of file mock_devices.py.

◆ power [1/2]

float microscope.testsuite.mock_devices.CoherentSapphireLaserMock.power = CoherentSapphireLaserMock.default_power

Definition at line 145 of file mock_devices.py.

◆ power [2/2]

str microscope.testsuite.mock_devices.CoherentSapphireLaserMock.power = b"NOMP":

Definition at line 236 of file mock_devices.py.

◆ prompt

bool microscope.testsuite.mock_devices.CoherentSapphireLaserMock.prompt = True

Definition at line 144 of file mock_devices.py.

◆ rtscts

bool microscope.testsuite.mock_devices.CoherentSapphireLaserMock.rtscts = False
static

Definition at line 128 of file mock_devices.py.

◆ status

str microscope.testsuite.mock_devices.CoherentSapphireLaserMock.status = "laser ready"

Definition at line 140 of file mock_devices.py.

◆ stopbits

microscope.testsuite.mock_devices.CoherentSapphireLaserMock.stopbits = serial.STOPBITS_ONE
static

Definition at line 127 of file mock_devices.py.

◆ tec

bool microscope.testsuite.mock_devices.CoherentSapphireLaserMock.tec = True

Definition at line 142 of file mock_devices.py.


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