forked from M-Labs/artiq
lda: minor fixes and refactoring
This commit is contained in:
parent
744e7841c6
commit
57e25c7af1
|
@ -1,21 +1,15 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from artiq.management.pc_rpc import Client
|
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
|
from artiq.management.pc_rpc import Client
|
||||||
|
|
||||||
def get(remote):
|
|
||||||
return remote.get_attenuation()
|
|
||||||
|
|
||||||
|
|
||||||
def set(remote, attenuation):
|
|
||||||
remote.set_attenuation(attenuation)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('-s', '--server', default="::1",
|
parser.add_argument('-s', '--server', default="::1",
|
||||||
help="The IP address or hostname of the controller")
|
help="The IP address or hostname of the controller")
|
||||||
parser.add_argument('-p', '--port', default=7777, type=int,
|
parser.add_argument('-p', '--port', default=8890, type=int,
|
||||||
help="The TCP port the controller listens to")
|
help="The TCP port the controller listens to")
|
||||||
parser.add_argument('-a', '--attenuation', type=float,
|
parser.add_argument('-a', '--attenuation', type=float,
|
||||||
help="The attenuation value you want to set")
|
help="The attenuation value you want to set")
|
||||||
|
@ -25,9 +19,8 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if args.attenuation is None:
|
if args.attenuation is None:
|
||||||
print("Current attenuation: {}".format(get(remote)))
|
print("Current attenuation: {}".format(remote.get_attenuation()))
|
||||||
else:
|
else:
|
||||||
set(remote, args.attenuation)
|
remote.set_attenuation(args.attenuation)
|
||||||
except Exception as e:
|
finally:
|
||||||
print("exception: {}".format(e))
|
|
||||||
remote.close_rpc()
|
remote.close_rpc()
|
|
@ -1,4 +1,5 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
import argparse
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
import atexit
|
import atexit
|
||||||
|
@ -6,6 +7,9 @@ import ctypes
|
||||||
import ctypes.util
|
import ctypes.util
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
|
from artiq.management.pc_rpc import simple_server_loop
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
if "." not in os.environ["PATH"].split(";"):
|
if "." not in os.environ["PATH"].split(";"):
|
||||||
|
@ -141,12 +145,18 @@ class Lda:
|
||||||
print("[LDA-sim] setting attenuation to {}".format(attenuation))
|
print("[LDA-sim] setting attenuation to {}".format(attenuation))
|
||||||
self._attenuation = attenuation
|
self._attenuation = attenuation
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
parser = argparse.ArgumentParser()
|
||||||
logger.info(list(Lda.enumerate("LDA-102")))
|
parser.add_argument('-d', '--device', default="LDA-102",
|
||||||
l = Lda()
|
choices=["LDA-102", "LDA-602", "sim"])
|
||||||
logger.info(l.get_attenuation())
|
parser.add_argument('--bind', default="::1",
|
||||||
l.set_attenuation(50)
|
help="hostname or IP address to bind to")
|
||||||
logger.info(l.get_attenuation())
|
parser.add_argument('-p', '--port', default=8890, type=int,
|
||||||
l.set_attenuation(60)
|
help="TCP port to listen to")
|
||||||
logger.info(l.get_attenuation())
|
parser.add_argument('-s', '--serial', default=None,
|
||||||
|
help="USB serial number of the device")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
simple_server_loop(Lda(args.serial, args.device), "lda",
|
||||||
|
args.bind, args.port)
|
|
@ -1,19 +0,0 @@
|
||||||
#!/usr/bin/env python3
|
|
||||||
from artiq.management.pc_rpc import simple_server_loop
|
|
||||||
from lda import Lda
|
|
||||||
import argparse
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
parser = argparse.ArgumentParser()
|
|
||||||
parser.add_argument('-d', '--device', default="LDA-102",
|
|
||||||
choices=["LDA-102", "LDA-602", "sim"])
|
|
||||||
parser.add_argument('--bind', default="::1",
|
|
||||||
help="hostname or IP address to bind to")
|
|
||||||
parser.add_argument('-p', '--port', default=7777, type=int,
|
|
||||||
help="TCP port to listen to")
|
|
||||||
parser.add_argument('-s', '--serial', default=None,
|
|
||||||
help="USB serial number of the device")
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
simple_server_loop(Lda(args.serial, args.device), "lda",
|
|
||||||
args.bind, args.port)
|
|
Loading…
Reference in New Issue