This repository has been archived by the owner on May 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPowerSupplyRC.py
executable file
·60 lines (48 loc) · 2.07 KB
/
PowerSupplyRC.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
53
54
55
56
57
58
59
60
#!/usr/bin/env python
import argparse
import commands
import re
import cmd
from commands import HMC804xDevice
VERSION = 0.1
def ValidCommands(v):
choices=[x for x in dir(commands.Device) if not re.search("^(__|_).*", x)]
if not re.search("(?:" + '|'.join(choices) + ")\:\d(?:\:\d+\.\d+|\:\d+|)$", v):
raise argparse.ArgumentTypeError("Error")
else:
return v
class InterActiveConsole(cmd.Cmd):
def __init__(self):
cmd.Cmd.__init__(self)
#setattr(InterActiveConsole, name, value)
def do_greet(self, line):
print "hello"
def do_EOF(self, line):
return True
def main():
parser = argparse.ArgumentParser(description="Command line interface to send commands to power supplies")
parser.add_argument('-d', '--device', default='HMC8043', choices=['HMC8043'], help='specifies which device should be remote controlled')
parser.add_argument('-c', '--connection', default='/dev/usbtmc0', help='specifies the connection type to the remote device')
parser.add_argument('-V', '--version', help='returns the version', action='version', version='Power Supply Remote Control V' + str(VERSION))
parser.add_argument('-C', '--Command', type=ValidCommands, action='append', help='the command you want to send')
parser.add_argument('-i', '--interactive', action='store_true', help='entering the interactive mode where commands can send to the device. With this flag, all -C arguments will be ignored!')
args = vars(parser.parse_args())
# print args
#now must parsing the functions and call them
conn = args['connection']
dev = args['device']
if dev == 'HMC8043':
comm = HMC804xDevice(conn)
else:
comm = None
print args
if args['interactive']:
InterActiveConsole().cmdloop()
else:
if args['Command'] != None:
for arg in args['Command']:
param = arg.split(':')
method = getattr(comm, param[0])
method(int(param[1]), float(param[2]))
if __name__ == "__main__":
main()