-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactonpy.py
66 lines (57 loc) · 1.86 KB
/
actonpy.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
import serial
class actonpy():
def __init__(self, port='COM3'):
self.ser = serial.Serial(port, 9600, timeout=1)
if self.ser.isOpen():
ret = self.query('MODEL')
print('Spectrometer {} connected'.format(ret))
else:
print('Could not connect to serial port')
def query(self, cmd):
""" Queries the Spectrometer
send spectrometer commands (with added carriage return) as
documented in spectrometers manual and returns answer
Args:
cmd: Command to send
Returns:
Answer from spectrometer as a string stripped from newlines
and spectrometer 'ok'
Raises:
no error handling yet
"""
self.ser.write(cmd+'\r')
ret = self.ser.readall()
return ret[1:-6]
def write(self, cmd):
self.ser.write(cmd+'\r')
def closeConnection(self):
self.ser.close()
print('connection closed')
def get_wavelength(self):
# return wavelength as float in nm
ret = self.query('?NM')
return float(ret[:-3])
def get_scanrate(self):
# return scan rate as float in nm/min
ret = self.query('?NM/MIN')
return float(ret[:-7])
def set_scanrate(self, rate):
# set scan rate in nm/min
# return new rate
self.write('{:.2f} NM/MIN'.format(rate))
if self.ser.readline().find('ok') != -1:
ret = self.get_scanrate()
else:
ret = 'failed'
return ret
def goto(wavelength):
self.write('{:.3f} GOTO'.format(wavelength))
if self.ser.readline().find('ok') != -1:
ret = self.get_wavelength()
else:
ret = 'failed'
return ret
def get_info():
self.ser.write('MONO-EESTATUS\r')
ret = self.ser.readall()
print(ret)