This repository has been archived by the owner on Jul 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlaser.py
101 lines (73 loc) · 2.28 KB
/
laser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
## This module defines the interface for a laser that can be controlled
# by cockpit.devices.laserpower.
import abc
import Pyro4
import serial
import socket
import threading
import time
# The name of the config section for this device
CONFIG_NAME = 'dummyLaser'
# The name of the class that provides the interface specified below.
CLASS_NAME = 'Laser'
## This is a prototype for a class to be used with laser_server.
class Laser(object):
__metaclass__ = abc.ABCMeta
@abc.abstractmethod
def __init__(self, serialPort, baudRate, timeout):
## Should connect to the physical device here and set self.connection
# to a type with read, readline and write methods (e.g. serial.Serial).
self.connection = None
## Simple passthrough.
@abc.abstractmethod
def read(self, numChars):
return self.connection.read(numChars)
## Simple passthrough.
@abc.abstractmethod
def readline(self):
return self.connection.readline().strip()
## Send a command.
@abc.abstractmethod
def write(self, command):
# Override if a specific format is required.
response = self.connection.write(command + '\r\n')
return response
## Query and return the laser status.
@abc.abstractmethod
def getStatus(self):
result = []
# ...
return result
## Turn the laser ON. Return True if we succeeded, False otherwise.
@abc.abstractmethod
def enable(self):
pass
## Turn the laser OFF.
@abc.abstractmethod
def disable(self):
pass
## Return True if the laser is currently able to produce light. We assume this is equivalent
# to the laser being in S2 mode.
@abc.abstractmethod
def getIsOn(self):
pass
## Set the laser power in native units.
@abc.abstractmethod
def setPower(self, level):
pass
## Return the max. power in mW.
@abc.abstractmethod
def getMaxPower_mW(self):
pass
## Return the current power in native units.
@abc.abstractmethod
def getPower(self):
pass
## Return the current power in mW.
@abc.abstractmethod
def getPower_mW(self):
pass
## Set the power from an argument in mW.
@abc.abstractmethod
def setPower_mW(self, mW):
pass