-
Notifications
You must be signed in to change notification settings - Fork 0
/
PhaseCompensation.py
46 lines (40 loc) · 1.23 KB
/
PhaseCompensation.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
import sys
import serial
import time
port_name="/dev/ttyACM1"
if (len(sys.argv) < 2):
print ("Put 'off' or 'forward' or 'reverse' or 'stop'")
sys.exit(0)
else:
direction = sys.argv[1]
print (direction)
if(direction == "off"):
serPort = serial.Serial(port_name, 19200, timeout=1)
relay_off = [0, 1, 2, 5, 6, 7]
for i in relay_off:
serPort.write(str.encode("relay off "+str(i)+"\n\r"))
serPort.close()
if(direction == "forward"):
serPort = serial.Serial(port_name, 19200, timeout=1)
relay_on = [0, 1, 2]
relay_off = [5, 6, 7]
for i in relay_off:
serPort.write(str.encode("relay off "+str(i)+"\n\r"))
for i in relay_on:
serPort.write(str.encode("relay on "+str(i)+"\n\r"))
serPort.close()
if(direction == "reverse"):
serPort = serial.Serial(port_name, 19200, timeout=1)
relay_on = [0, 1, 2, 5, 6, 7]
for i in relay_on:
serPort.write(str.encode("relay on "+str(i)+"\n\r"))
serPort.close()
if(direction == "stop"):
serPort = serial.Serial(port_name, 19200, timeout=1)
relay_on = [0, 1, 2, 5]
relay_off = [6, 7]
for i in relay_off:
serPort.write(str.encode("relay off "+str(i)+"\n\r"))
for i in relay_on:
serPort.write(str.encode("relay on "+str(i)+"\n\r"))
serPort.close()