348 def handle(self, command):
349
350 command = command.strip()
351
352
353
354 answer = b"OK"
355
356 if command == b"sn?":
357 answer = b"7863"
358 elif command == b"gcn?":
359 answer = b"Macro-Gen5b-SHG-0501_4W-RevA"
360 elif command == b"ver?" or command == b"gfv?":
361 answer = b"50070"
362 elif command == b"gfvlas?":
363 answer = b"This laser head does not have firmware."
364 elif command == b"hrs?":
365 answer = b"828.98"
366
367
368
369
370
371
372
373
374
375 elif command == b"@cob1":
376 self.on_after_interlock = True
377 self.light = False
378 elif command == b"@cob0":
379 self.on_after_interlock = False
380 self.light = False
381
382 elif command == b"@cobas?":
383 answer = b"1" if self.auto_start else b"0"
384 elif command == b"@cobas 0":
385 self.auto_start = False
386 elif command == b"@cobas 1":
387 self.auto_start = True
388
389
390 elif command == b"l?":
391 answer = b"1" if self.light else b"0"
392 elif command == b"l1":
393 if self.auto_start:
394 answer = b"Syntax error: not allowed in autostart mode."
395 else:
396 self.light = True
397 elif command == b"l0":
398 self.light = False
399
400
401 elif command.startswith(b"p "):
402
403 new_power = float(command[2:]) * 1000.0
404 if new_power > self.max_power or new_power < self.min_power:
405 answer = b"Syntax error: Value is out of range."
406 else:
407 self.power = new_power
408 elif command == b"p?":
409 answer = b"%.4f" % (self.power / 1000.0)
410 elif command == b"pa?":
411 if self.light:
412 answer = b"%.4f" % (self.power / 1000.0)
413 else:
414 answer = b"0.0000"
415
416
417 elif command.startswith(b"@cobasp "):
418 return self.handle(command[6:])
419
420
421 elif command == b"@cobasdr?":
422 answer = b"1" if self.direct_control else b"0"
423 elif command == b"@cobasdr 0":
424 self.direct_control = False
425 elif command == b"@cobasdr 1":
426 self.direct_control = False
427
428
429 elif command == b"gmlp?":
430 answer = b"600.000000"
431
432
433 elif command == b"?":
434 answer = b"OK"
435
436
437 elif command == b"f?":
438
439
440
441
442 answer = b"0"
443
444
445 elif command == b"ilk?":
446 answer = b"1" if self.interlock_open else b"0"
447
448
449 elif command == b"cobast?":
450
451
452
453
454
455
456
457
458
459 if self.light:
460 answer = b"4"
461 else:
462 answer = b"1" if self.on_after_interlock else b"0"
463
464 else:
465 raise NotImplementedError(
466 "no handling for command '%s'" % command.decode("utf-8")
467 )
468
469
470
471 self.in_buffer.write(answer + b"\r\n")
472
473