From 3c3d5663a68528f83f331af1d9e4e72fb15bbbcf Mon Sep 17 00:00:00 2001 From: raiden00pl Date: Sat, 30 Sep 2023 14:36:51 +0200 Subject: [PATCH] nxscope.py: disable all enabled channels when disconnecting --- src/nxslib/nxscope.py | 17 +++++++++++++++++ tests/test_nxscope.py | 14 ++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/nxslib/nxscope.py b/src/nxslib/nxscope.py index c27d185..fc32c71 100644 --- a/src/nxslib/nxscope.py +++ b/src/nxslib/nxscope.py @@ -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 @@ -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: diff --git a/tests/test_nxscope.py b/tests/test_nxscope.py index a874bc6..19f91e8 100644 --- a/tests/test_nxscope.py +++ b/tests/test_nxscope.py @@ -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()