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 c2e859a
Show file tree
Hide file tree
Showing 18 changed files with 933 additions and 600 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()
22 changes: 7 additions & 15 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,7 +17,7 @@ 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("hostname", type=str, help="The host to connect to.")
parser.add_argument("prefix", type=str, help="The prefix for the IOC.")
parser.add_argument(
"--screens-dir",
Expand Down Expand Up @@ -52,19 +51,12 @@ def main():
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 c2e859a

Please sign in to comment.