From d315268ddb0099336f9dbae3a392372329dfcae7 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Thu, 11 Dec 2014 14:10:15 +0800 Subject: [PATCH] move controllers/clients to frontend --- artiq/devices/lda/__init__.py | 0 .../lda/{lda_controller.py => driver.py} | 32 +------------- .../pdq2/{pdq2_controller.py => driver.py} | 42 +------------------ doc/manual/drivers_reference.rst | 2 +- {artiq/devices/lda => frontend}/lda_client.py | 6 +-- frontend/lda_controller.py | 30 +++++++++++++ .../devices/pdq2 => frontend}/pdq2_client.py | 0 frontend/pdq2_controller.py | 41 ++++++++++++++++++ 8 files changed, 78 insertions(+), 75 deletions(-) create mode 100644 artiq/devices/lda/__init__.py rename artiq/devices/lda/{lda_controller.py => driver.py} (83%) mode change 100755 => 100644 rename artiq/devices/pdq2/{pdq2_controller.py => driver.py} (89%) mode change 100755 => 100644 rename {artiq/devices/lda => frontend}/lda_client.py (76%) create mode 100755 frontend/lda_controller.py rename {artiq/devices/pdq2 => frontend}/pdq2_client.py (100%) create mode 100755 frontend/pdq2_controller.py diff --git a/artiq/devices/lda/__init__.py b/artiq/devices/lda/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/artiq/devices/lda/lda_controller.py b/artiq/devices/lda/driver.py old mode 100755 new mode 100644 similarity index 83% rename from artiq/devices/lda/lda_controller.py rename to artiq/devices/lda/driver.py index 4882743a2..b98777f2d --- a/artiq/devices/lda/lda_controller.py +++ b/artiq/devices/lda/driver.py @@ -1,14 +1,9 @@ -#!/usr/bin/env python3 - -import argparse import logging import ctypes import struct -from artiq.management.pc_rpc import simple_server_loop - -logger = logging.getLogger(__name__) +logger = logging.getLogger("lda") class HidError(Exception): @@ -163,27 +158,4 @@ class Lda: :type attenuation: int, float or Fraction """ - self.set(0x8d, bytes(chr(int(round(attenuation*4))), 'ascii')) - -def 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=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() - - if args.device == "sim": - lda = Ldasim() - else: - lda = Lda(args.serial, args.device) - - simple_server_loop(lda, "lda", - args.bind, args.port) - -if __name__ == "__main__": - main() + self.set(0x8d, bytes(chr(int(round(attenuation*4))), "ascii")) diff --git a/artiq/devices/pdq2/pdq2_controller.py b/artiq/devices/pdq2/driver.py old mode 100755 new mode 100644 similarity index 89% rename from artiq/devices/pdq2/pdq2_controller.py rename to artiq/devices/pdq2/driver.py index 579c72bc9..09b11d251 --- a/artiq/devices/pdq2/pdq2_controller.py +++ b/artiq/devices/pdq2/driver.py @@ -1,19 +1,13 @@ -#!/usr/bin/env python3 - # Based on code by Robert Jordens , 2012 import logging import struct -import argparse -import asyncio from scipy import interpolate import numpy as np -from artiq.management.pc_rpc import simple_server_loop - -logger = logging.getLogger("Pdq2") +logger = logging.getLogger("pdq2") Ftdi = None @@ -328,37 +322,3 @@ class Pdq2: board, dac = divmod(channel, self.num_dacs) data = self._add_mem_header(board, dac, data) self._write_data(data) - - -def _get_args(): - parser = argparse.ArgumentParser(description="PDQ2 controller") - parser.add_argument("--bind", default="::1", - help="hostname or IP address to bind to") - parser.add_argument("-p", "--port", default=8889, type=int, - help="TCP port to listen to") - parser.add_argument( - "-s", "--serial", default=None, - help="device (FT245R) serial string [first]") - parser.add_argument( - "-d", "--debug", default=False, action="store_true", - help="debug communications") - return parser.parse_args() - - -def main(): - args = _get_args() - - if args.debug: - logging.basicConfig(level=logging.DEBUG) - else: - logging.basicConfig(level=logging.WARNING) - - dev = Pdq2(serial=args.serial) - try: - simple_server_loop(dev, "pdq2", args.bind, args.port, - id_parameters="serial="+str(args.serial)) - finally: - dev.close() - -if __name__ == "__main__": - main() diff --git a/doc/manual/drivers_reference.rst b/doc/manual/drivers_reference.rst index bbc2ab013..3f2bc8d5a 100644 --- a/doc/manual/drivers_reference.rst +++ b/doc/manual/drivers_reference.rst @@ -21,7 +21,7 @@ Each driver is run in a separate "controller" that exposes a RPC interface (base :mod:`artiq.devices.lda` module --------------------------------- -.. automodule:: artiq.devices.lda.lda_controller +.. automodule:: artiq.devices.lda.driver :members: diff --git a/artiq/devices/lda/lda_client.py b/frontend/lda_client.py similarity index 76% rename from artiq/devices/lda/lda_client.py rename to frontend/lda_client.py index 17dd81ace..c11e52dd7 100755 --- a/artiq/devices/lda/lda_client.py +++ b/frontend/lda_client.py @@ -8,11 +8,11 @@ from artiq.management.pc_rpc import Client def main(): parser = argparse.ArgumentParser() parser.add_argument('-s', '--server', default="::1", - help="The IP address or hostname of the controller") + help="hostname or IP of the controller to connect to") parser.add_argument('-p', '--port', default=8890, type=int, - help="The TCP port the controller listens to") + help="TCP port to use to connect to the controller") parser.add_argument('-a', '--attenuation', type=float, - help="The attenuation value you want to set") + help="attenuation value to set") args = parser.parse_args() remote = Client(args.server, args.port, "lda") diff --git a/frontend/lda_controller.py b/frontend/lda_controller.py new file mode 100755 index 000000000..48a8af568 --- /dev/null +++ b/frontend/lda_controller.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 + +import argparse + +from artiq.devices.lda.driver import Lda, Ldasim +from artiq.management.pc_rpc import simple_server_loop + + +def 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=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() + + if args.device == "sim": + lda = Ldasim() + else: + lda = Lda(args.serial, args.device) + + simple_server_loop(lda, "lda", + args.bind, args.port) + +if __name__ == "__main__": + main() diff --git a/artiq/devices/pdq2/pdq2_client.py b/frontend/pdq2_client.py similarity index 100% rename from artiq/devices/pdq2/pdq2_client.py rename to frontend/pdq2_client.py diff --git a/frontend/pdq2_controller.py b/frontend/pdq2_controller.py new file mode 100755 index 000000000..340d10452 --- /dev/null +++ b/frontend/pdq2_controller.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 + +import argparse +import logging + +from artiq.devices.pdq2.driver import Pdq2 +from artiq.management.pc_rpc import simple_server_loop + + +def _get_args(): + parser = argparse.ArgumentParser(description="PDQ2 controller") + parser.add_argument("--bind", default="::1", + help="hostname or IP address to bind to") + parser.add_argument("-p", "--port", default=8889, type=int, + help="TCP port to listen to") + parser.add_argument( + "-s", "--serial", default=None, + help="device (FT245R) serial string [first]") + parser.add_argument( + "-d", "--debug", default=False, action="store_true", + help="debug communications") + return parser.parse_args() + + +def main(): + args = _get_args() + + if args.debug: + logging.basicConfig(level=logging.DEBUG) + else: + logging.basicConfig(level=logging.WARNING) + + dev = Pdq2(serial=args.serial) + try: + simple_server_loop(dev, "pdq2", args.bind, args.port, + id_parameters="serial="+str(args.serial)) + finally: + dev.close() + +if __name__ == "__main__": + main()