-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLaser_controller_functions.py
More file actions
216 lines (186 loc) · 7.15 KB
/
Laser_controller_functions.py
File metadata and controls
216 lines (186 loc) · 7.15 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
import pyvisa
from pyvisa import constants
import time
time_change = 0.45 # sec/mA
currentResolution = 0.01
tempResolution = 1
rm = pyvisa.ResourceManager()
Arroyo = rm.open_resource("ASRL3::INSTR", baud_rate=38400, data_bits=8)
Arroyo.read_termination = "\r\n"
Arroyo.write_termination = "\r\n"
constants.VI_ASRL_STOP_ONE
constants.VI_ASRL_PAR_NONE
constants.VI_ASRL_FLOW_NONE
ThorLabs = rm.open_resource("GPIB0::10::INSTR")
def getID():
pass
def beep(LaserController):
if LaserController.lower() == "arroyo":
Arroyo.write("*BEEP")
elif LaserController.lower() == "thor labs":
ThorLabs.query("*IDN?")
else:
print("Laser Controller doesn't exist")
def turnOnLaser(LaserController):
if LaserController.lower() == "arroyo":
Arroyo.write("LASer:OUTput 1")
elif LaserController.lower() == "thor labs":
ThorLabs.write(":LASER ON")
else:
print("Laser Controller doesn't exist")
def turnOffLaser(LaserController):
if LaserController.lower() == "arroyo":
Arroyo.write("LASer:OUTput 0")
elif LaserController.lower() == "thor labs":
ThorLabs.write(":LASER OFF")
else:
print("Laser Controller doesn't exist")
def turnOnTemp(LaserController):
if LaserController.lower() == 'arroyo':
pass
elif LaserController.lower() == 'thor labs':
ThorLabs.write(":TEC ON")
else:
print("Laser Controller doesn't exist")
def turnOffTemp(LaserController):
if LaserController.lower() == 'arroyo':
pass
elif LaserController.lower() == 'thor labs':
ThorLabs.write(":TEC OFF")
else:
print("Laser Controller doesn't exist")
def getTempStatus(LaserController):
if LaserController.lower() == 'arroyo':
pass
elif LaserController.lower() == 'thor labs':
state = ThorLabs.write(":TEC?")
state = state.split(' ')
if state[1].rstrip() == "OFF":
return False
else:
return True
else:
print("Laser Controller doesn't exist")
def setCurrent(current, LaserController):
if LaserController.lower() == "arroyo":
actualCurrent = float(getCurrent("arroyo"))
while actualCurrent != current:
actualCurrent = float(getCurrent("arroyo"))
difference = current - actualCurrent
if difference < 0:
LDI = actualCurrent - 10 * currentResolution
else:
LDI = actualCurrent + 10 * currentResolution
Arroyo.write(f"LASer:LDI {LDI}")
actualCurrent = float(getCurrent("arroyo"))
time.sleep(time_change * 10 * currentResolution)
elif LaserController.lower() == "thor labs":
actualCurrent = float(getCurrent("thor labs"))
while not((actualCurrent <= 0.001 * current + 0.0001*currentResolution) and (actualCurrent >= 0.001 * current - 0.0001*currentResolution)):
actualCurrent = float(getCurrent("thor labs"))
difference = 0.001 * current - actualCurrent
if difference < 0:
LDI = actualCurrent - 0.001 * currentResolution # Convert to mA
else:
LDI = actualCurrent + 0.001 * currentResolution # Convert to mA
ThorLabs.write(f":ILD:SET {LDI}")
actualCurrent = float(getCurrent("thor labs"))
time.sleep(time_change * currentResolution)
else:
print("Laser Controller doesn't exist")
# Using the setCurrent as a model for set Temperature
def setTempurature(temperature, LaserController):
if LaserController.lower() == "arroyo":
actualTemp = float(getTemperature("arroyo"))
while actualTemp != temperature:
actualTemp = float(getTemperature("arroyo"))
difference = temperature - actualTemp
if difference < 0:
LDI = actualTemp - 10 * tempResolution
else:
LDI = actualTemp + 10 * tempResolution
#Arroyo.write(f"LASer:LDI {LDI}")
actualTemp = float(getTemperature("arroyo"))
time.sleep(time_change * 10 * tempResolution)
elif LaserController.lower() == "thor labs":
actualTemp = float(getTemperature("thor labs"))
while not((actualTemp <= 0.001 * temperature + 0.0001*tempResolution) and (actualTemp >= 0.001 * temperature - 0.0001*tempResolution)):
actualTemp = float(getTemperature("thor labs"))
difference = 0.001 * temperature - actualTemp
if difference < 0:
NR3 = actualTemp - tempResolution # Convert to mA
else:
NR3 = actualTemp + tempResolution # Convert to mA
ThorLabs.write(f":RESI:SET {NR3}")
actualTemp = float(getTemperature("thor labs"))
time.sleep(time_change * tempResolution)
else:
print("Laser Controller doesn't exist")
def getCurrent(LaserController):
if LaserController.lower() == "arroyo":
current = Arroyo.query("LASer:SET:LDI?")
return float(current)
elif LaserController.lower() == "thor labs":
current = ThorLabs.query(":ILD:SET?")
current = current.split(" ")
return float(current[1].rstrip())
else:
print("Laser Controller doesn't exist")
def getTemperature(LaserController):
if LaserController.lower() == "arroyo":
pass
elif LaserController.lower() == "thor labs":
temp = ThorLabs.query(":RESI:ACT?")
temp = temp.split(' ')
return float(temp[1].rstrip())
else:
print("Laser Controller doesn't exist")
def getLaserStatus(LaserController):
if LaserController.lower() == "arroyo":
response = Arroyo.query("LASer:OUTput?")
if response == 1:
return True
elif response == 0:
return False
elif LaserController.lower() == "thor labs":
response = ThorLabs.query(":LASER?")
response = response.split(" ")
if response[1].rstrip() == "OFF":
return False
elif response[1].rstrip() == "ON":
return True
else:
print("Laser Controller doesn't exist")
if __name__ == "__main__":
x = getLaserStatus("arroyo")
if not x:
print("Pass laser off")
setCurrent(50, "arroyo")
c = getCurrent("arroyo")
print(f"Laser current {c}")
setCurrent(0, "arroyo")
c = getCurrent("arroyo")
print(f"Laser current {c}")
print("Arroyo test end")
"""
x = getLaserStatus("Thor labs")
if not x:
print("Pass laser off")
turnOnLaser("thor labs")
x = getLaserStatus("Thor labs")
if x:
print("Pass laser on")
setCurrent(50, "thor labs")
c = getCurrent("thor labs")
print(f"Laser current {c}")
setCurrent(0, "thor labs")
c = getCurrent("thor labs")
print(f"Laser current {c}")
if c == 0:
turnOffLaser("thor labs")
else:
print("Error laser not at 0mA")
x = getLaserStatus("Thor labs")
if not x:
print("Pass laser off")
print("Thor labs test end")"""