forked from M-Labs/artiq
1
0
Fork 0

move controllers/clients to frontend

This commit is contained in:
Sebastien Bourdeauducq 2014-12-11 14:10:15 +08:00
parent c3953d85d5
commit d315268ddb
8 changed files with 78 additions and 75 deletions

View File

View File

@ -1,14 +1,9 @@
#!/usr/bin/env python3
import argparse
import logging import logging
import ctypes import ctypes
import struct import struct
from artiq.management.pc_rpc import simple_server_loop
logger = logging.getLogger("lda")
logger = logging.getLogger(__name__)
class HidError(Exception): class HidError(Exception):
@ -163,27 +158,4 @@ class Lda:
:type attenuation: int, float or Fraction :type attenuation: int, float or Fraction
""" """
self.set(0x8d, bytes(chr(int(round(attenuation*4))), 'ascii')) 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()

View File

@ -1,19 +1,13 @@
#!/usr/bin/env python3
# Based on code by Robert Jordens <jordens@gmail.com>, 2012 # Based on code by Robert Jordens <jordens@gmail.com>, 2012
import logging import logging
import struct import struct
import argparse
import asyncio
from scipy import interpolate from scipy import interpolate
import numpy as np import numpy as np
from artiq.management.pc_rpc import simple_server_loop
logger = logging.getLogger("pdq2")
logger = logging.getLogger("Pdq2")
Ftdi = None Ftdi = None
@ -328,37 +322,3 @@ class Pdq2:
board, dac = divmod(channel, self.num_dacs) board, dac = divmod(channel, self.num_dacs)
data = self._add_mem_header(board, dac, data) data = self._add_mem_header(board, dac, data)
self._write_data(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()

View File

@ -21,7 +21,7 @@ Each driver is run in a separate "controller" that exposes a RPC interface (base
:mod:`artiq.devices.lda` module :mod:`artiq.devices.lda` module
--------------------------------- ---------------------------------
.. automodule:: artiq.devices.lda.lda_controller .. automodule:: artiq.devices.lda.driver
:members: :members:

View File

@ -8,11 +8,11 @@ from artiq.management.pc_rpc import Client
def main(): def 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="hostname or IP of the controller to connect to")
parser.add_argument('-p', '--port', default=8890, type=int, 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, parser.add_argument('-a', '--attenuation', type=float,
help="The attenuation value you want to set") help="attenuation value to set")
args = parser.parse_args() args = parser.parse_args()
remote = Client(args.server, args.port, "lda") remote = Client(args.server, args.port, "lda")

30
frontend/lda_controller.py Executable file
View File

@ -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()

41
frontend/pdq2_controller.py Executable file
View File

@ -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()