From 57e25c7af1cd6a2839d491a772447bb8a2359a55 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Tue, 25 Nov 2014 19:56:28 +0800 Subject: [PATCH] lda: minor fixes and refactoring --- .../lda/{lda_client.py => lda-client.py} | 17 ++++-------- .../devices/lda/{lda.py => lda-controller.py} | 26 +++++++++++++------ artiq/devices/lda/lda_controller.py | 19 -------------- 3 files changed, 23 insertions(+), 39 deletions(-) rename artiq/devices/lda/{lda_client.py => lda-client.py} (64%) rename artiq/devices/lda/{lda.py => lda-controller.py} (86%) delete mode 100755 artiq/devices/lda/lda_controller.py diff --git a/artiq/devices/lda/lda_client.py b/artiq/devices/lda/lda-client.py similarity index 64% rename from artiq/devices/lda/lda_client.py rename to artiq/devices/lda/lda-client.py index f09da6e35..6b2d2aad5 100755 --- a/artiq/devices/lda/lda_client.py +++ b/artiq/devices/lda/lda-client.py @@ -1,21 +1,15 @@ #!/usr/bin/env python3 -from artiq.management.pc_rpc import Client 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__": parser = argparse.ArgumentParser() parser.add_argument('-s', '--server', default="::1", 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") parser.add_argument('-a', '--attenuation', type=float, help="The attenuation value you want to set") @@ -25,9 +19,8 @@ if __name__ == "__main__": try: if args.attenuation is None: - print("Current attenuation: {}".format(get(remote))) + print("Current attenuation: {}".format(remote.get_attenuation())) else: - set(remote, args.attenuation) - except Exception as e: - print("exception: {}".format(e)) + remote.set_attenuation(args.attenuation) + finally: remote.close_rpc() diff --git a/artiq/devices/lda/lda.py b/artiq/devices/lda/lda-controller.py similarity index 86% rename from artiq/devices/lda/lda.py rename to artiq/devices/lda/lda-controller.py index 95c460347..72ef5fd05 100755 --- a/artiq/devices/lda/lda.py +++ b/artiq/devices/lda/lda-controller.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +import argparse import os import logging import atexit @@ -6,6 +7,9 @@ import ctypes import ctypes.util import struct +from artiq.management.pc_rpc import simple_server_loop + + logger = logging.getLogger(__name__) if "." not in os.environ["PATH"].split(";"): @@ -141,12 +145,18 @@ class Lda: print("[LDA-sim] setting attenuation to {}".format(attenuation)) self._attenuation = attenuation + if __name__ == "__main__": - logging.basicConfig(level=logging.DEBUG) - logger.info(list(Lda.enumerate("LDA-102"))) - l = Lda() - logger.info(l.get_attenuation()) - l.set_attenuation(50) - logger.info(l.get_attenuation()) - l.set_attenuation(60) - logger.info(l.get_attenuation()) + 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=8890, 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) diff --git a/artiq/devices/lda/lda_controller.py b/artiq/devices/lda/lda_controller.py deleted file mode 100755 index 74da58808..000000000 --- a/artiq/devices/lda/lda_controller.py +++ /dev/null @@ -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)