158 def handle(self, command):
159
160
161 command = command.upper()
162
163 answer = None
164
165
166 if command == b">=0":
167 self.prompt = False
168 elif command == b">=1":
169 self.prompt = True
170
171
172 elif command == b"E=0":
173 self.echo = False
174 elif command == b"E=1":
175 self.echo = True
176
177
178 elif command == b"?HID":
179 answer = b"505925.000"
180
181
182 elif command == b"?HH":
183 answer = b" 257:34"
184
185
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
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
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
208 elif command == b"T=0":
209
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
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
239 elif command == b"NOMP":
240 answer = b"200"
241
242
243 elif command == b"LT":
244 answer = b"Sapphire 200mW"
245
246
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
259 elif command == b"?F":
260 answer = b"0"
261 elif command == b"?FF":
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285 if self.light:
286
287 answer = b"8192"
288 else:
289 answer = b"0"
290 elif command == b"?FL":
291
292
293 answer = b"Fault(s):\r\n\tNone"
294
295
296 elif command in [b"sv", b"svps"]:
297 answer = b"8.005"
298
299
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