-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaml.py
More file actions
executable file
·66 lines (49 loc) · 1.72 KB
/
aml.py
File metadata and controls
executable file
·66 lines (49 loc) · 1.72 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
#!/usr/bin/env python
import time, serial
"""
This is the AML object the controls communication between
the computer and the AML stepper motor driver.
"""
class AML(object):
def __init__(self, port='/dev/tty.USA19H1461P1.1'):
self.port = port
self.connected = False
self.start_serial(self.port)
#Open a port for serial communication.
def start_serial(self, port):
# Configure the serial connections
# These are specific to the AML SMD2 Stepper Controller
try:
self.ser = serial.Serial(
port=port,
baudrate=9600,
parity=serial.PARITY_ODD,
bytesize=serial.SEVENBITS,
stopbits=serial.STOPBITS_TWO
)
# Need to set the "request to send" pin low
self.ser.setRTS(False)
self.connected = True
time.sleep(.25)
except:
print("Something went wrong connecting to AML serial...")
def write(self, command):
self.ser.write(command + '\r') # appending a \r, required by the SMD2
time.sleep(.25) # .1 sec seems too fast, but maybe not...?
def close_serial(self):
self.ser.close()
def read(self):
out = []
while self.ser.inWaiting() > 0:
data = str(self.ser.read())
if data == '\r':
out.append('\n')
else:
out.append(data)
if out != '':
return ' '.join(out)
else:
return None
def write_and_read(self, command):
self.write(command)
return self.read()