-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontrollers.py
More file actions
106 lines (74 loc) · 2.56 KB
/
controllers.py
File metadata and controls
106 lines (74 loc) · 2.56 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
#!/usr/bin/env python
# -*- coding: UTF8 -*-
#
# stage.py - Python library to interface with the Micos MMC-100 stage
#
# AUTHOR: Douglas Watson <douglas@watsons.ch>
#
# DATE: started on 19 March 2012
#
# LICENSE: GNU GPL
#
#################################################
import serial
import time
import logging
##############################
# Configuration
##############################
# Define
x_axis = 3
y_axis = 1
z_axis = 2
##############################
# Class definitions
##############################
def needs_serial(original_method):
''' Decorator for methods that need serial communication.
Decorates the method with functions (such as error handling or delays) that
are common to all methods sending serial commands.
'''
def decorated_method(*args, **kwargs):
# wait a bit before executing the method.
time.sleep(3) # time in seconds
return_value = original_method(*args, **kwargs)
return return_value
return decorated_method
class Stage:
''' Represents a connection to the stage
ARGUMENTS
port (string) - the port to which the controller is connected
ATTRIBUTES
self.ser (serial.Serial) - actual connection to the controller.
'''
def __init__(self, port):
# TODO implement error handling
# 'con' stands for controller or connection. As you wish.
self.con = serial.Serial(port=port, baudrate=38400, parity='N',
bytesize=8, stopbits=1)
@needs_serial
def write(self, string):
''' Send 'string' to the stage. Automatically append carriage return.
This is just a wrapper around self.con.write(), to cut down on
repetition in following methods.
'''
logging.info("Sending: " + string)
return self.con.write(string + '\r')
def move_abs(self, x=None, y=None, z=None):
''' Move the stage to position (x, y, z) [mm], somewhat synchronously.
If any of the coordinates are None, no instruction will be sent for
that axis '''
self.write('%dMSA%.6f; %dMSA%.6f; %dMSA%.6f' % (x_axis, x,
y_axis, y,
z_axis, z))
self.write('0RUN')
def move_rel(x, y, z):
pass
def read_pos(x, y, z):
pass
def clear_errors(self):
''' Clear errors in all three axes. '''
for ax in (x_axis, y_axis, z_axis):
self.write('%dERR?' % ax)
class Shutter:
pass