-
Notifications
You must be signed in to change notification settings - Fork 0
/
laser_control.py
71 lines (63 loc) · 2.16 KB
/
laser_control.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
#Script for initializing laser and checking values on laser usage settings.
# ---------------------------------------------------------------------------- #
# Dependencies
# ---------------------------------------------------------------------------- #
from TSL550 import TSL550
import time
# ---------------------------------------------------------------------------- #
# Reference Data
# ---------------------------------------------------------------------------- #
class limits:
"""Constants for the laser settings."""
class sweep_rate:
type = "laser sweep"
units = "nm/s"
min = 1.0
max = 100
class wavelength:
type = "wavelength"
units = "nm"
min = 1550
max = 1630
# ---------------------------------------------------------------------------- #
# Functions
# ---------------------------------------------------------------------------- #
def initLaser(address="COM4"):
return TSL550.TSL550(address)
#Generic function to check if a value is in range.
#Uses ranges from limits class.
def checkRange(value, range):
if not (range.min <= value <= range.max):
error_msg = "Invalid {0} of {1} {4}. Must be between {2} and {3} {4}."
error_msg = error_msg.format(
range.type,
value,
range.min,
range.max,
range.units
)
raise AttributeError(error_msg)
def checkSweepRate(sweep_rate):
checkRange(sweep_rate, limits.sweep_rate)
def checkWavelength(wavelength):
checkRange(wavelength, limits.wavelength)
# ---------------------------------------------------------------------------- #
# Unit Testing
# ---------------------------------------------------------------------------- #
if __name__ == "__main__":
print('-' * 20)
print("Testing sweep rate limits.")
print('-' * 20)
for i in range(0, 105):
try:
checkSweepRate(i)
except Exception as err:
print(err)
print('-' * 20)
print("Testing wavelength limits.")
print('-' * 20)
for i in range(1545, 1635):
try:
checkWavelength(i)
except Exception as err:
print(err)