Skip to content

Commit

Permalink
implemented panda controller
Browse files Browse the repository at this point in the history
  • Loading branch information
evalott100 committed Oct 14, 2024
1 parent 9ef976c commit dd73c61
Show file tree
Hide file tree
Showing 19 changed files with 859 additions and 612 deletions.
44 changes: 39 additions & 5 deletions src/fastcs_pandablocks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,45 @@
"""Top level API.
"""Contains logic relevant to fastcs. Will use `fastcs_pandablocks.panda`."""

.. data:: __version__
:type: str
from pathlib import Path

Version number as calculated by https://github.com/pypa/setuptools_scm
"""
from fastcs.backends.epics.backend import EpicsBackend
from fastcs.backends.epics.gui import EpicsGUIFormat

from ._version import __version__
from .controller import PandaController
from .gui import PandaGUIOptions
from .types import EpicsName

__all__ = ["__version__"]


def ioc(
prefix: EpicsName,
hostname: str,
screens_directory: Path | None,
clear_bobfiles: bool = False,
):
controller = PandaController(prefix, hostname)
backend = EpicsBackend(controller, pv_prefix=str(prefix))

if clear_bobfiles and not screens_directory:
raise ValueError("`clear_bobfiles` is True with no `screens_directory`")

if screens_directory:
if not screens_directory.is_dir():
raise ValueError(
f"`screens_directory` {screens_directory} is not a directory"
)
if not clear_bobfiles:
if list(screens_directory.iterdir()):
raise RuntimeError("`screens_directory` is not empty.")

backend.create_gui(
PandaGUIOptions(
output_path=screens_directory / "output.bob",
file_format=EpicsGUIFormat.bob,
title="PandA",
)
)

backend.run()
48 changes: 24 additions & 24 deletions src/fastcs_pandablocks/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

import argparse
import logging
import asyncio

#from fastcs_pandablocks.fastcs import ioc
from fastcs_pandablocks.panda.panda import Panda
from pathlib import Path

from fastcs_pandablocks import ioc
from fastcs_pandablocks.types import EpicsName

from . import __version__

Expand All @@ -18,53 +17,54 @@ def main():
parser = argparse.ArgumentParser(
description="Connect to the given HOST and create an IOC with the given PREFIX."
)
parser.add_argument("host", type=str, help="The host to connect to.")
parser.add_argument("prefix", type=str, help="The prefix for the IOC.")
parser.add_argument(
"-v",
"--version",
action="version",
version=__version__,
)

subparsers = parser.add_subparsers(dest="command", required=True)
run_parser = subparsers.add_parser(
"run", help="Run the IOC with the given HOST and PREFIX."
)
run_parser.add_argument("hostname", type=str, help="The host to connect to.")
run_parser.add_argument("prefix", type=str, help="The prefix for the IOC.")
run_parser.add_argument(
"--screens-dir",
type=str,
help=(
"Provide an existing directory to export generated bobfiles to, if no "
"directory is provided then bobfiles will not be generated."
),
)
parser.add_argument(
run_parser.add_argument(
"--clear-bobfiles",
action="store_true",
help="Clear bobfiles from the given `screens-dir` before generating new ones.",
)
parser.add_argument(
"-v",
"--version",
action="version",
version=__version__,
)
parser.add_argument(

run_parser.add_argument(
"--log-level",
default="INFO",
choices=["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG"],
help="Set the logging level.",
)

parsed_args = parser.parse_args()
if parsed_args.command != "run":
return

# Set the logging level
level = getattr(logging, parsed_args.log_level.upper(), None)
logging.basicConfig(format="%(levelname)s:%(message)s", level=level)

async def meh():
await Panda(parsed_args.host).connect()
asyncio.run(meh())


"""
ioc(
parsed_args.host,
parsed_args.prefix,
parsed_args.screens_dir,
EpicsName(prefix=parsed_args.prefix),
parsed_args.hostname,
Path(parsed_args.screens_dir),
parsed_args.clear_bobfiles,
)
"""


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit dd73c61

Please sign in to comment.