-
Notifications
You must be signed in to change notification settings - Fork 0
/
encoder.py
52 lines (36 loc) · 978 Bytes
/
encoder.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
import serial
import time
import datetime
import logging
FILENAME = '/home/pi/Desktop/' + str(datetime.datetime.now()) + '.log'
logging.basicConfig(filename=FILENAME,
level=logging.DEBUG,
format='%(message)s',
datefmt='%m-%d %H:%M:%S',
filemode='a')
#%(asctime)s
with serial.Serial('/dev/ttyACM0', timeout=1) as ser:
ser.baudrate = 115200
with serial.Serial('/dev/ttyACM1', timeout=1) as ser1:
ser1.baudrate = 115200
ser.open()
time.sleep(2)
ser.write(b'$X\n') # Turn on the machine
time.sleep(2)
ser.write(b'M7\n') # Initialization of the machine
time.sleep(2)
ser1.open()
time.sleep(1)
ser.write(b'$HX\n')
time.sleep(10)
ser1.write(b'a\n')
time.sleep(2)
ser1.write(b'b\n')
ser.write(b'X168\n')
ser1.write(b'c\n')
for i in range(0,20000):
logging.info(ser1.readline())
time.sleep(1/1000)
ser.write(b'M9\n')
ser.close()
ser1.close()