-
Notifications
You must be signed in to change notification settings - Fork 0
/
PI_commands.py
165 lines (142 loc) · 5.11 KB
/
PI_commands.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
# -*- coding: utf-8 -*-
"""
Controls Princeton Instrument Acton SP2300 monochromator
@author: Ouri, Eric
"""
import visa
import time
import re
class pi_commands():
def __init__(self, com_number): # E.g., if the instrument is at ASRL4, use 4 as com_number
rm=visa.ResourceManager()
self.m=rm.open_resource('ASRL'+str(com_number)+'::INSTR', timeout=10000, read_termination='ok\r\n', write_termination='\r') # self.m stores the PyVisa instant pointing to the instrument
self.m.clear()
self.nm=self.get_nm(1)
def close_comm(self):
self.m.clear()
self.m.close()
def get_model_serial(self):
self.m.clear()
self.model=self.m.query('MODEL')
self.serialN=self.m.query('SERIAL')
return( self.model , self.serialN)
def get_nm(self,to_print):
self.m.clear()
self.curr_nm_reply=self.m.query('?NM')
temp=re.split(' ',self.curr_nm_reply)
self.curr_nm=float(temp[1])
if to_print:
print(self.curr_nm_reply)
return self.curr_nm
def is_done(self):
self.m.clear()
self.done=int(self.m.query('MONO-?DONE'))
return self.done
def get_speed(self):
self.m.clear()
speed=re.split(' ',self.m.query('?NM/MIN'))
self.speed=float(speed[1])
# print('scanning speed is '+str(self.speed)+ ' nm/min')
return self.speed
def get_active_grating(self):
self.m.clear()
self.active_grating=self.m.query('?GRATING')
return int(self.active_grating)
def get_available_gratings(self):
self.m.clear()
self.m.write('?GRATINGS')
self.m.read_termination='\n'
self.available_gratings=[]
for G in range(5):
self.available_gratings.append('\n'+self.m.read())
self.m.clear()
self.m.read_termination='ok\r\n'
print (self.available_gratings)
return self.available_gratings
def get_mirror(self):
self.m.clear()
self.mirror=self.m.query('?MIRROR')
return self.mirror
def get_mirror_bool(self):
self.m.clear()
self.mirror_bool=int(self.m.query('?MIR'))
return self.mirror_bool
#mirror control
def set_out_mirror(self,mirror_state):
self.m.write('EXIT-MIRROR')
self.m.write(mirror_state)
time.sleep(2)
self.m.clear()
state=pi_commands.get_mirror(self)
if state == ' '+ mirror_state+' ':
print([' output mirror in %s state' %(mirror_state)])
else:
print('Error in output mirror positioning')
return
def set_in_mirror(self,mirror_state):
self.m.write('ENT-MIRROR')
self.m.write(mirror_state)
time.sleep(2)
self.m.clear()
state=pi_commands.get_mirror(self)
if state == ' '+mirror_state+' ':
print('input mirror in %s state' %(mirror_state))
else:
print('Error in input mirror positioning')
return
#Grating control
def set_grating(self, gratingN):
self.m.timeout=30000
curr_gr=(pi_commands.get_active_grating(self))
self.m.write(str(gratingN)+' GRATING')
time.sleep(20)
self.m.timeout=2000
curr_gr=(pi_commands.get_active_grating(self))
if curr_gr!=gratingN:
print('Error in grating selection')
return
pi_commands.get_available_gratings(self)
return
#Wavelength positioning control
def set_NM(self, wavelength):
step=wavelength-self.nm
step=int(step*1000)
step=step/1000
self.m.write(str(step)+' >NM')
done_move=0
while done_move==0:
done_move=pi_commands.is_done(self)
time.sleep(1)
self.nm+=self.get_nm(0)
print('tuned wavelength is: '+str(self.nm) )
return
def set_speed(self, speed):
curr_speed=pi_commands.get_speed(self)
self.m.write(str(speed)+' NM/MIN')
count_max=10
count=0
while curr_speed!=speed:
self.m.clear()
if count>count_max:
print('Error in speed setting')
return
curr_speed=pi_commands.get_speed(self)
time.sleep(1)
count=count+1
print('set scaning speed is: '+str(pi_commands.get_speed(self))+ ' nm/min')
return
#initialization setting
def initial_config(self, gratingN, wavelength, speed) :
self.m.write(str(speed)+' INIT-SRATE')
self.m.write(str(gratingN)+' INIT-GRATING')
self.m.write(str(wavelength)+' INIT-WAVELENGTH')
return
#calibration methods
def cal_offset(self, gratingN, offset):
self.m.write(str(offset)+' '+str(gratingN-1)+' INIT-OFFSET')
self.m.write('MONO-RESET')
return
def cal_gadjust(self, gratingN, adjust ):
self.m.write(str(adjust)+' '+str(gratingN-1)+'INIT-GADJUST')
self.m.write('MONO-RESET')
return