-
Notifications
You must be signed in to change notification settings - Fork 14
/
ivctl.py
executable file
·47 lines (35 loc) · 922 Bytes
/
ivctl.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
#!/usr/bin/python
import sys, getopt
import time
from UPower import *
MaxAttempts = 10
def main(argv):
status = "none"
try:
opts, args = getopt.getopt(argv,"hi:")
except getopt.GetoptError:
print sys.argv[0], ' -i on|off'
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print sys.argv[0]," -i on|off"
print "Switches invertor on and off"
sys.exit()
elif opt in ("-i"):
status = arg
up = UPower()
if (up.connect() < 0):
print "Could not connect to the device"
exit -2
newstat = 0
if (status == "on"): newstat = 1
for x in range(MaxAttempts):
instat = up.getIV()
if (instat == newstat): break
print "Inverter status", instat
print 'Setting invertor to', newstat
up.switchIV(newstat)
time.sleep(3)
# main call
if __name__ == "__main__":
main(sys.argv[1:])