Skip to content

Commit

Permalink
Add tango option with fastcs proposal API
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelldls committed Oct 28, 2024
1 parent 396d4a3 commit b011097
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
},
"remoteEnv": {
// Allow X11 apps to run inside the container
"DISPLAY": "${localEnv:DISPLAY}"
"DISPLAY": "${localEnv:DISPLAY}",
"TANGO_HOST": "localhost:10000"
},
"customizations": {
"vscode": {
Expand Down
4 changes: 4 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
"debug-test"
],
"console": "integratedTerminal",
"env": {
// Enable break on exception when debugging tests (see: tests/conftest.py)
"TANGO_HOST": "localhost:10000",
},
"args": [
"ioc",
"BL01C-EA-FLIP-01",
Expand Down
59 changes: 48 additions & 11 deletions src/thorlabs_mff_fastcs/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from typing import Optional

import typer
from fastcs.connections.serial_connection import SerialConnectionSettings
from fastcs import FastCS
from fastcs.connections import SerialConnectionSettings

from thorlabs_mff_fastcs.controllers import (
ThorlabsMFF,
Expand All @@ -23,6 +24,13 @@ def version_callback(value: bool):
raise typer.Exit()


def get_controller(port: str, baud: int) -> ThorlabsMFF:
serial_settings = SerialConnectionSettings(port=port, baud=baud)
settings = ThorlabsMFFSettings(serial_settings)
cont = ThorlabsMFF(settings)
return cont


@app.callback()
def main(
version: Optional[bool] = typer.Option(
Expand All @@ -38,7 +46,7 @@ def main(

@app.command()
def ioc(
pv_prefix: str = typer.Argument(..., help="Name of the IOC/service to attach to"),
pv_prefix: str = typer.Argument(..., help="IOC PV prefix"),
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
Expand All @@ -55,18 +63,47 @@ def ioc(
"""
Start up the service
"""
from fastcs.backends.epics.backend import EpicsBackend, EpicsGUIOptions
from fastcs.backends import EpicsGUIOptions, EpicsIOCOptions, EpicsOptions

backend = EpicsBackend(get_controller(port, baud), pv_prefix)
backend.create_gui(EpicsGUIOptions(output_path / "index.bob"))
backend.run()
options = EpicsOptions(
ioc=EpicsIOCOptions(pv_prefix=pv_prefix),
gui=EpicsGUIOptions(output_path / "index.bob"),
)

fast_cs = FastCS(get_controller(port, baud), options)
fast_cs.create_gui()
fast_cs.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

@app.command()
def dsr(
dev_name: str = typer.Argument(
..., help="Name of the device instance .e.g my/device/name"
),
dsr_name: str = typer.Argument(
..., help="Name of the device server instance e.g. my_server-instance"
),
port: str = typer.Argument(..., help="Serial port to open such as /dev/ttyUSB0"),
baud: int = typer.Option(115200, help="Baud rate"),
):
"""
Start up the service
"""

from fastcs.backends import TangoDSROptions, TangoOptions

controller = get_controller(port, baud)
device_options = TangoOptions(
TangoDSROptions(
dev_class=controller.__class__.__name__,
debug=False,
dev_name=dev_name,
dsr_instance=dsr_name,
)
)

fast_cs = FastCS(controller, device_options)
fast_cs.run()


# test with: python -m thorlabs_mff_fastcs
Expand Down

0 comments on commit b011097

Please sign in to comment.