-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThorLabs_K10CR1.py
226 lines (116 loc) · 5.75 KB
/
ThorLabs_K10CR1.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
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
217
218
219
220
221
222
223
224
225
226
#!/usr/bin/env python
import InstrumentDriver
import thorlabs_apt as apt
import thorlabs_apt.core as apt_core
from collections import Counter
import ctypes
import os, time
class Driver(InstrumentDriver.InstrumentWorker):
""" This class implements the Ocean Optics Spectrometer"""
def performOpen(self, options={}):
"""Perform the operation of opening the instrument connection"""
# init object
self.motor = None
try:
# open connection
#devices = sb.list_devices()
devices = apt.list_available_devices()
# check if devices available
if len(devices) == 0:
# no devices found
raise Exception('No motor found')
elif len(devices) == 1:
# one device, use
#self.spec = sb.Spectrometer(devices[0])
self.motor = apt.Motor(55000409)
self.motor.move_home()
else:
# many devices, look for serial
#self.spec = sb.Spectrometer.from_serial_number(self.comCfg.address)
self.motor = apt.Motor(55000409)
self.motor.move_home()
except Exception as e:
# re-cast errors as a generic communication error
raise InstrumentDriver.CommunicationError(str(e))
def performClose(self, bError=False, options={}):
"""Perform the close instrument connection operation"""
# check if digitizer object exists
try:
if self.motor is None:
# do nothing, object doesn't exist (probably was never opened)
return
except:
# never return error here, do nothing, object doesn't exist
return
try:
# close and remove object
self.motor._cleanup()
del self.motor
except:
# never return error here
pass
def performSetValue(self, quant, value, sweepRate=0.0, options={}):
"""Perform the Set Value instrument operation. This function should
return the actual value set by the instrument"""
# check quantity
##======================================================##
## loading the rotator motor to rotate the polarizer ##
## motor serial number :: 55000409 ##
## minimum velocity :: 0.000 degree/second ##
## accleration :: 9.999 degrees/second^2 ##
## maximum velocity :: 10.000 degrees/second ##
##======================================================##
if quant.name == 'Velocity':
# conversion from s -> us
#self.spec.integration_time_micros(int(value*1E6))
#self.motor.integration_time_micros(int(value*1E6))
self.motor.set_velocity_parameters(0.000, 9.999, value)
elif quant.name == 'Move To':
# temperature set point
#self.spec.tec_set_temperature_C(value)
self.motor.move_to(value,blocking=True)
#current_position = self.motor.position()
#if abs(self.motor.position() - value)>.5:
# self.motor.move_home()
#self.motor.move_to(value,blocking=True)
return value
def performGetValue(self, quant, options={}):
"""Perform the Get Value instrument operation"""
# check type of quantity
if quant.name == 'Current Position':
# temperature
value = self.motor.position
"""elif quant.name == 'Intensity':
# get number of averages
numavgs = self.getValue('Navgs')
# get wavelength and intensity
vX = self.spec.wavelengths()
vY = self.spec.intensities(correct_dark_counts=False, correct_nonlinearity=False)
for i in range(int(numavgs)-1):
vY += self.spec.intensities(correct_dark_counts=False, correct_nonlinearity=False)
vY /= numavgs
# assume equally-spaced waveform values
value = quant.getTraceDict(vY, dt=vX[1]-vX[0], t0=vX[0])
elif quant.name == 'DeltaR':
# get number of averages
numavgs = self.getValue('Navgs')
# get wavelength and intensity
vX = self.spec.wavelengths()
vY1 = self.spec.intensities(correct_dark_counts=False, correct_nonlinearity=False)
for i in range(int(numavgs)-1):
vY1 += self.spec.intensities(correct_dark_counts=False, correct_nonlinearity=False)
# write down the value on the sample. assume equally-spaced waveform values
vY1 /= numavgs
#move the stage
ctypes.windll.user32.MessageBoxA(0, "Move the stage!", "Stage Move Time", 1)
vY2 = self.spec.intensities(correct_dark_counts=False, correct_nonlinearity=False)
for i in range(int(numavgs)-1):
vY2 += self.spec.intensities(correct_dark_counts=False, correct_nonlinearity=False)
# write down the value off of the sample. assume equally-spaced waveform values
vY2 /= numavgs
#calculate deltaR / R
vY = 1 - vY1/vY2
value = Counter(quant.getTraceDict(vY, dt=vX[1]-vX[0], t0=vX[0]))"""
return value
if __name__ == '__main__':
pass