Skip to content

Commit

Permalink
nxscope.py: disable all enabled channels when disconnecting
Browse files Browse the repository at this point in the history
  • Loading branch information
raiden00pl committed Sep 30, 2023
1 parent 59a3691 commit 3c3d566
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/nxslib/nxscope.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ def disconnect(self) -> None:
if self._connected is True:
# stop stream
self.stream_stop()
# disable all channels now
self.ch_disable_all(True)
# disconnect
self._comm.disconnect()
self._connected = False
Expand Down Expand Up @@ -256,6 +258,21 @@ def ch_disable(
# write channels configuration
self.channels_write()

def ch_disable_all(self, writenow: bool = False) -> None:
"""Disable all channels.
The effects of this method are buffered and will
be applied to the device just before the stream starts
or can be forced to write with writenow flag.
:param writenow: write channels configuration now
"""
self._comm.ch_disable_all()

if writenow:
# write channels configuration
self.channels_write()

def ch_divider(
self, chans: list[int] | int, div: int, writenow: bool = False
) -> None:
Expand Down
14 changes: 14 additions & 0 deletions tests/test_nxscope.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,20 @@ def test_nxscope_channels_runtime():
_ = q1.get(block=True, timeout=1)
_ = q2.get(block=True, timeout=1)

# configuration not written
nxscope.ch_disable_all()

assert dev0.data.en is True
assert dev1.data.en is True
assert dev2.data.en is True

# configuration written
nxscope.ch_disable_all(True)

assert dev0.data.en is False
assert dev1.data.en is False
assert dev2.data.en is False

# stop stream
nxscope.stream_stop()

Expand Down

0 comments on commit 3c3d566

Please sign in to comment.