-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
86ea923
commit 3ca6b62
Showing
4 changed files
with
11 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,18 @@ | ||
from pathlib import Path | ||
|
||
import typer | ||
from fastcs.connections.serial_connection import SerialConnectionSettings | ||
from fastcs import launch | ||
|
||
from thorlabs_mff_fastcs.controllers import ( | ||
ThorlabsMFF, | ||
ThorlabsMFFSettings, | ||
) | ||
|
||
from . import __version__ | ||
|
||
__all__ = ["main"] | ||
|
||
|
||
app = typer.Typer() | ||
|
||
|
||
def version_callback(value: bool): | ||
if value: | ||
typer.echo(__version__) | ||
raise typer.Exit() | ||
|
||
|
||
@app.callback() | ||
def main( | ||
version: bool | None = typer.Option( | ||
None, | ||
"--version", | ||
callback=version_callback, | ||
is_eager=True, | ||
help="Print the version and exit", | ||
), | ||
): | ||
pass | ||
|
||
|
||
@app.command() | ||
def ioc( | ||
pv_prefix: str = typer.Argument(..., help="Name of the IOC/service to attach to"), | ||
port: str = typer.Argument(..., help="Serial port to open such as /dev/ttyUSB0"), | ||
baud: int = typer.Option(115200, help="Baud rate"), | ||
output_path: Path = typer.Option( # noqa: B008 | ||
Path.cwd(), # noqa: B008 | ||
help="folder of local service definition", | ||
exists=True, | ||
file_okay=False, | ||
dir_okay=True, | ||
writable=False, | ||
readable=True, | ||
resolve_path=True, | ||
), | ||
): | ||
""" | ||
Start up the service | ||
""" | ||
from fastcs.backends.epics.backend import EpicsBackend, EpicsGUIOptions | ||
|
||
backend = EpicsBackend(get_controller(port, baud), pv_prefix) | ||
backend.create_gui(EpicsGUIOptions(output_path / "index.bob")) | ||
backend.run() | ||
|
||
|
||
def get_controller(port: str, baud: int) -> ThorlabsMFF: | ||
serial_settings = SerialConnectionSettings(port=port, baud=baud) | ||
settings = ThorlabsMFFSettings(serial_settings) | ||
tcont = ThorlabsMFF(settings) | ||
return tcont | ||
def main() -> None: | ||
"""Argument parser for the CLI.""" | ||
launch(ThorlabsMFF) | ||
|
||
|
||
# test with: python -m thorlabs_mff_fastcs | ||
if __name__ == "__main__": | ||
app() | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
import subprocess | ||
import sys | ||
|
||
import pytest | ||
|
||
from thorlabs_mff_fastcs import __version__ | ||
|
||
|
||
@pytest.skip("FastCS will add version command") | ||
def test_cli_version(): | ||
cmd = [sys.executable, "-m", "thorlabs_mff_fastcs", "--version"] | ||
cmd = [sys.executable, "-m", "thorlabs_mff_fastcs", "version"] | ||
assert subprocess.check_output(cmd).decode().strip() == __version__ |