Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite SC10 shutter enable as toggle #370

Merged
merged 3 commits into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions src/instruments/thorlabs/sc10.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,27 @@ def name(self):
"""
return self.query("id?")

enable = bool_property(
"ens",
inst_true="1",
inst_false="0",
set_fmt="{}={}",
doc="""
@property
def enable(self):
"""
Gets/sets the shutter enable status, False for disabled, True if
enabled

If output enable is on (`True`), there is a voltage on the output.

:return: Status of the switch.
:rtype: `bool`
""",
)

:raises TypeError: Unexpected type given when trying to enable.
"""
return bool(int(self.query("ens?")))

@enable.setter
def enable(self, value):
if not isinstance(value, bool):
raise TypeError(f"Expected bool, got type {type(value)} instead.")
curr_status = self.enable
if curr_status is not value:
self.sendcmd("ens")

repeat = int_property(
"rep",
Expand Down
19 changes: 16 additions & 3 deletions tests/test_thorlabs/test_thorlabs_sc10.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,25 @@ def test_sc10_name():
assert sc.name == "bloopbloop"


def test_sc10_enable():
def test_sc10_enable_query():
with expected_protocol(
ik.thorlabs.SC10, ["ens?", "ens=1"], ["ens?", "0", "> ens=1", "> "], sep="\r"
ik.thorlabs.SC10, ["ens?"], ["ens?", "0", "> "], sep="\r"
) as sc:
assert sc.enable is False
sc.enable = True


@pytest.mark.parametrize("status", [0, 1])
@pytest.mark.parametrize("value", [0, 1])
def test_sc10_enable_send(status, value):
host_to_ins = ["ens?"]
ins_to_host = ["ens?", f"{status}"]
if value != status:
host_to_ins.append("ens")
ins_to_host += ["> ens", "> "]
else:
ins_to_host.append("> ")
with expected_protocol(ik.thorlabs.SC10, host_to_ins, ins_to_host, sep="\r") as sc:
sc.enable = bool(value)


def test_sc10_enable_invalid():
Expand Down