-
Notifications
You must be signed in to change notification settings - Fork 8
/
LeicaDMI.py
70 lines (54 loc) · 2 KB
/
LeicaDMI.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
import serial
import io
import numpy as np
class LeicaDMI(object):
def __init__(self, serial_port):
self.ser = serial.Serial(serial_port, 115200, timeout=3)
self.sio = io.TextIOWrapper(io.BufferedRWPair(self.ser, self.ser, 1), newline='\r', line_buffering=True)
def sendCmd(self, cmd, debug=False):
if debug:
print "sending: " + cmd
self.sio.write(unicode(cmd + '\r'))
self.sio.flush()
answer = self.sio.readline()
if debug:
print "received: " + answer
return answer
def get_AFC_image(self):
self.sendCmd("48066 -1")
Nloops = 50 # 323
my_array = np.zeros(Nloops * 8)
for index in np.arange(840, 1240, 8): # (0, 2584, 8):
vals = self.sendCmd("48066 " + str(index))
temp = np.array(map(int, vals.split()))
my_array[index-840:index-840 + 8] = temp[2:] # my_array[index:index + 8] = temp[2:]
return my_array
def get_AFC_score(self):
ans = self.sendCmd("48030")
score = ans.split()[-2]
return float(score)
def get_AFC_intensity(self):
ans = self.sendCmd("48036")
return int(ans.split()[1])
def set_AFC_intensity(self, intensity):
assert (intensity < 255)
assert (intensity > 0)
return self.sendCmd('48035 %d' % int(intensity))
def set_AFC_hold(self, hold=True):
if hold:
return self.sendCmd('48020 1')
else:
return self.sendCmd('48020 0')
def get_AFC_hold(self):
return int(self.sendCmd('48021').split(" ")[1]) == 1
def holdHere(self):
return self.sendCmd('48022')
def get_AFC_edgePosition(self):
return float(self.sendCmd('48023').split(" ")[1])
def set_AFC_setpoint(self, offset):
return self.sendCmd('48024 %f' % float(offset))
def get_AFC_setpoint(self):
ans = self.sendCmd('48025')
return float(ans.split(" ")[1])
def shutdown(self):
self.ser.close()