-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathattenuator_serial.py
More file actions
executable file
·90 lines (75 loc) · 2.59 KB
/
attenuator_serial.py
File metadata and controls
executable file
·90 lines (75 loc) · 2.59 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python3
"""
this file is used in tip for getting serial number of attenuators
"""
import sys
import os
import importlib
import time
import argparse
sys.path.append(os.path.join(os.path.abspath(__file__ + "../../../")))
lfcli_base = importlib.import_module("py-json.LANforge.lfcli_base")
LFCliBase = lfcli_base.LFCliBase
LFRequest = importlib.import_module("py-json.LANforge.LFRequest")
LFUtils = importlib.import_module("py-json.LANforge.LFUtils")
class AttenuatorSerial(LFCliBase):
def __init__(self, lfclient_host, lfclient_port, debug_=False):
super().__init__(lfclient_host, lfclient_port, debug_)
self.lfclient_host = lfclient_host
self.COMMANDS = ["show_attenuators", "set_attenuator"]
self.atten_serno = ""
self.atten_idx = ""
self.atten_val = ""
self.atten_data = {
"shelf": 1,
"resource": 1,
"serno": None,
"atten_idx": None,
"val": None,
"mode": None,
"pulse_width_us5": None,
"pulse_interval_ms": None,
"pulse_count": None,
"pulse_time_ms": None
}
def show(self, debug=False):
ser_no_list = []
response = self.json_get("/attenuators/")
time.sleep(0.01)
if response is None:
print(response)
raise ValueError("Cannot find any endpoints")
else:
attenuator_resp = response["attenuators"]
for i in attenuator_resp:
for key in i:
if key == "entity id":
print("entity id")
# print("%s " % (key))
ser_no_list.append(key)
return ser_no_list
def main():
parser = argparse.ArgumentParser(
prog='attenuator_serial.py',
formatter_class=argparse.RawTextHelpFormatter,
epilog='''\
Useful Information:
this file is used in tip for getting serial number of attenuators,
''',
description='''
attenuator_serial.py: this file is used in tip for getting serial number of attenuators,
''')
help_summary = '''\
attenuator_serial.py is used in tip for getting serial number of attenuators
'''
parser.add_argument('--help_summary', action="store_true", help='Show summary of what this script does')
# used for showing help
args = parser.parse_args()
if args.help_summary:
print(help_summary)
exit(0)
obj = AttenuatorSerial(lfclient_host="localhost", lfclient_port=8802)
x = obj.show()
print("out", x)
if __name__ == '__main__':
main()