diff --git a/src/instruments/thorlabs/thorlabsapt.py b/src/instruments/thorlabs/thorlabsapt.py index 3771f0f6..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 @@ -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 ff89098c..18cd42d0 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("