-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add first-class support for discrete hardware (#98)
* add first-class support for discrete hardware * add * setter not getter (#94) * setter not getter * tests * rm print * add first-class support for discrete hardware * add * don't double count describe
- Loading branch information
Showing
7 changed files
with
100 additions
and
4 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[spectrometer] | ||
port = 38383 |
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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import pathlib | ||
import numpy as np | ||
import time | ||
import subprocess | ||
from yaqd_core import testing | ||
import yaqc_bluesky | ||
import bluesky | ||
from bluesky import plan_stubs as bps | ||
|
||
|
||
config = pathlib.Path(__file__).parent / "config.toml" | ||
|
||
|
||
@testing.run_daemon_entry_point("fake-discrete-hardware", config=config) | ||
def test_identifier_is_in_read(): | ||
d = yaqc_bluesky.Device(38383) | ||
read_keys = list(d.read().keys()) | ||
assert f"{d.name}_position_identifier" in read_keys | ||
|
||
|
||
@testing.run_daemon_entry_point("fake-discrete-hardware", config=config) | ||
def test_identifier_is_in_describe(): | ||
d = yaqc_bluesky.Device(38383) | ||
describe_keys = list(d.describe().keys()) | ||
assert f"{d.name}_position_identifier" in describe_keys | ||
|
||
|
||
@testing.run_daemon_entry_point("fake-discrete-hardware", config=config) | ||
def test_describe_read(): | ||
d = yaqc_bluesky.Device(38383) | ||
describe_keys = list(d.describe().keys()) | ||
read_keys = list(d.read().keys()) | ||
assert describe_keys == read_keys | ||
|
||
|
||
@testing.run_daemon_entry_point("fake-discrete-hardware", config=config) | ||
def test_hint_fields(): | ||
d = yaqc_bluesky.Device(38383) | ||
fields = d.hints["fields"] | ||
for field in fields: | ||
assert field in d.describe().keys() | ||
assert field in d.read().keys() | ||
|
||
|
||
@testing.run_daemon_entry_point("fake-discrete-hardware", config=config) | ||
def test_set_read(): | ||
d = yaqc_bluesky.Device(38383) | ||
d.set(470) | ||
time.sleep(1) | ||
out = d.read() | ||
assert out[f"{d.name}_position_identifier"]["value"] == "blue" | ||
d.set("green") | ||
time.sleep(1) | ||
out = d.read() | ||
assert np.isclose(out[d.name]["value"], 540.0) | ||
|
||
|
||
@testing.run_daemon_entry_point("fake-discrete-hardware", config=config) | ||
def test_mv(): | ||
def plan(): | ||
d = yaqc_bluesky.Device(38383) | ||
for identifier, position in d.yaq_client.get_position_identifiers().items(): | ||
yield from bps.mv(d, identifier) | ||
assert np.isclose(d.read()[d.name]["value"], position) | ||
|
||
RE = bluesky.RunEngine() | ||
RE(plan()) |
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
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from collections import OrderedDict | ||
import time | ||
import warnings | ||
|
||
from ._has_position import HasPosition | ||
|
||
|
||
class IsDiscrete(HasPosition): | ||
|
||
def set(self, value): | ||
try: | ||
self.yaq_client.set_position(value) | ||
except TypeError: | ||
self.yaq_client.set_identifier(value) | ||
return self._wait_until_still() |
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