Skip to content

Commit

Permalink
Rewrite SC10 shutter enable as toggle (#370)
Browse files Browse the repository at this point in the history
* Rewrite SC10 shutter enable as toggle

* Bool comparison with `is not`
  • Loading branch information
trappitsch committed Sep 21, 2022
1 parent 71913ab commit 4ec761d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
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

0 comments on commit 4ec761d

Please sign in to comment.