From 13f78d44803005ced4d2aff3e8a653ed1c4853e2 Mon Sep 17 00:00:00 2001 From: Reto Trappitsch Date: Sun, 2 Oct 2022 13:39:15 +0200 Subject: [PATCH 1/2] Fix multi-channel support and adjust tests --- src/instruments/thorlabs/thorlabsapt.py | 2 +- tests/test_thorlabs/test_thorlabs_apt.py | 78 ++++++++++++++---------- 2 files changed, 46 insertions(+), 34 deletions(-) diff --git a/src/instruments/thorlabs/thorlabsapt.py b/src/instruments/thorlabs/thorlabsapt.py index a165854e..b6b7c2b9 100644 --- a/src/instruments/thorlabs/thorlabsapt.py +++ b/src/instruments/thorlabs/thorlabsapt.py @@ -45,7 +45,7 @@ def __init__(self, apt, idx_chan): self._apt = apt # APT is 1-based, but we want the Python representation to be # 0-based. - self._idx_chan = idx_chan + 1 + self._idx_chan = 2**idx_chan @property def enabled(self): diff --git a/tests/test_thorlabs/test_thorlabs_apt.py b/tests/test_thorlabs/test_thorlabs_apt.py index ff89098c..d37405d2 100644 --- a/tests/test_thorlabs/test_thorlabs_apt.py +++ b/tests/test_thorlabs/test_thorlabs_apt.py @@ -31,6 +31,8 @@ (3, "Unknown type: 3"), ) +channels = [0, 1, 2, 3] # Possible channels for multi-channel instrument + @pytest.mark.parametrize("hw_type", hw_types_setup) def test_apt_hw_info(hw_type): @@ -324,11 +326,13 @@ def init_kpz001(): # CHANNELS # -def test_apt_pia_channel_drive_op_parameters(init_kim101): +@pytest.mark.parametrize("ch", channels) +def test_apt_pia_channel_drive_op_parameters(init_kim101, ch): """Test the drive op parameters for the APT Piezo Inertia Actuator. Tested with KIM101 driver connected to PIM1 mirror mount. """ + ch_send = 2**ch with expected_protocol( ik.thorlabs.APTPiezoInertiaActuator, [ @@ -336,7 +340,7 @@ def test_apt_pia_channel_drive_op_parameters(init_kim101): ThorLabsPacket( # receive a package message_id=ThorLabsCommands.PZMOT_REQ_PARAMS, param1=0x07, - param2=0x01, + param2=ch_send, dest=0x50, source=0x01, data=None, @@ -347,7 +351,7 @@ def test_apt_pia_channel_drive_op_parameters(init_kim101): param2=None, dest=0x50, source=0x01, - data=struct.pack(" Date: Tue, 16 Apr 2024 09:49:51 +0200 Subject: [PATCH 2/2] distinguish single and multi mode for channels --- src/instruments/thorlabs/thorlabsapt.py | 20 ++++++++- tests/test_thorlabs/test_thorlabs_apt.py | 56 ++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) diff --git a/src/instruments/thorlabs/thorlabsapt.py b/src/instruments/thorlabs/thorlabsapt.py index 98c65576..4d7cf7cf 100644 --- a/src/instruments/thorlabs/thorlabsapt.py +++ b/src/instruments/thorlabs/thorlabsapt.py @@ -21,6 +21,7 @@ logger = logging.getLogger(__name__) logger.addHandler(logging.NullHandler()) + # CLASSES ##################################################################### # pylint: disable=too-many-lines @@ -43,7 +44,7 @@ def __init__(self, apt, idx_chan): self._apt = apt # APT is 1-based, but we want the Python representation to be # 0-based. - self._idx_chan = 2**idx_chan + self._idx_chan = idx_chan + 1 @property def enabled(self): @@ -375,6 +376,15 @@ class PiezoChannel(APTPiezoDevice.PiezoDeviceChannel): on the Thorlabs APT controller. """ + def __init__(self, apt, idx_chan): + """Initialize speicaltiez with Piezo channels.""" + super().__init__(apt, idx_chan) + self._idx_chan_initial = idx_chan + if apt._is_multi: + self._idx_chan = 2**idx_chan + else: + self._idx_chan = idx_chan + 1 + # PROPERTIES # @property @@ -547,6 +557,10 @@ def enabled_single(self, newval): "controller is a {}.".format(self._apt.model_number) ) + if newval: + self._idx_chan = self._idx_chan_initial + 1 # single mode + else: + self._idx_chan = self._idx_chan_initial**2 # multi mode param = self._idx_chan if newval else 0x00 pkt = _packets.ThorLabsPacket( message_id=_cmds.ThorLabsCommands.PZMOT_SET_PARAMS, @@ -868,6 +882,7 @@ def move_jog_stop(self): self._apt.sendpacket(pkt) + _is_multi = True # activated until user changes it _channel_type = PiezoChannel # PROPERTIES # @@ -943,10 +958,13 @@ def enabled_multi(self, mode): if mode == 0: param = 0x00 + self._is_multi = False elif mode == 1: param = 0x05 + self._is_multi = True elif mode == 2: param = 0x06 + self._is_multi = True else: raise ValueError( "Please select a valid mode: 0 - all " diff --git a/tests/test_thorlabs/test_thorlabs_apt.py b/tests/test_thorlabs/test_thorlabs_apt.py index d37405d2..18cd42d0 100644 --- a/tests/test_thorlabs/test_thorlabs_apt.py +++ b/tests/test_thorlabs/test_thorlabs_apt.py @@ -606,6 +606,62 @@ def test_apt_pia_channel_move_abs(init_kim101, ch): apt.channel[ch].move_abs(100) +@pytest.mark.parametrize("ch", channels) +def test_apt_pia_channel_move_abs_single_mode(init_kim101, ch): + """Absolute movement of APT Piezo Inertia Actuator, first set to single mode. + + Tested with KIM101 driver connected to PIM1 mirror mount. + First send single mode, test correct channel address, then switch back to + multi mode and test again. + """ + ch_send_single = ch + 1 + ch_send_multi = ch**2 + with expected_protocol( + ik.thorlabs.APTPiezoInertiaActuator, + [ + init_kim101[0], + ThorLabsPacket( + message_id=ThorLabsCommands.PZMOT_SET_PARAMS, + param1=None, + param2=None, + dest=0x50, + source=0x01, + data=struct.pack("