qmi.instruments.thorlabs.mpc320

Module for a Thorlabs MPC320 motorised fibre polarisation controller.

This driver communicates with the device via a USB serial port, using the Thorlabs APT protocol. For details, see the document “Thorlabs APT Controllers Host-Controller Communications Protocol”, issue 25 from Thorlabs.

Classes

Thorlabs_Mpc320(context, name, transport)

Driver for a Thorlabs MPC320 motorised fibre polarisation controller.

Thorlabs_Mpc320_PolarisationParameters(...)

Data class for the polarisation parameters of the MPC320

Thorlabs_Mpc320_Status(channel, position, ...)

Data class for the status of the MPC320

class qmi.instruments.thorlabs.mpc320.Thorlabs_Mpc320_Status(channel: int, position: float, velocity: int, motor_current: int)

Data class for the status of the MPC320

channel

Channel number.

Type:

int

position

Absolute position of the channel in degrees.

Type:

float

velocity

Velocity in controller units.

Type:

int

motor_current

Current of motor in mA

Type:

int

class qmi.instruments.thorlabs.mpc320.Thorlabs_Mpc320_PolarisationParameters(velocity: float, home_position: float, jog_step1: float, jog_step2: float, jog_step3: float)

Data class for the polarisation parameters of the MPC320

velocity

The velocity in percentage of the max velocity 400 degrees/s.

Type:

float

home_position

The home position of all the paddles/channels in degrees.

Type:

float

jog_step1

The position to move paddle/channel 1 by for a jog step in degrees.

Type:

float

jog_step2

The position to move paddle/channel 2 by for a jog step in degrees.

Type:

float

jog_step3

The position to move paddle/channel 3 by for a jog step in degrees.

Type:

float

class qmi.instruments.thorlabs.mpc320.Thorlabs_Mpc320(context: QMI_Context, name: str, transport: str)

Driver for a Thorlabs MPC320 motorised fibre polarisation controller.

open() None

Connect to the instrument hardware.

When this method returns, the instrument must be ready for interaction via calls to instrument-specific methods.

Subclasses can extend this method to implement instrument-specific initialization. If they do, they should call super().open() as a last statement.

close() None

Close the connection to the instrument hardware and release associated resources.

When this method returns, the instrument must not be used again unless it is first re-opened by calling the open() method.

Subclasses can extend this method if they have specific resources to close. If they do, they should call super().close() as a last statement.

get_idn() QMI_InstrumentIdentification

Read instrument type and version and return QMI_InstrumentIdentification instance.

Returns:

an instance of QMI_InstrumentIdentification. The version refers to the firmware version.

identify() None

Identify device by flashing the front panel LEDs.

enable_channels(channel_numbers: list[int]) None

Enable the channel(s). Note that this method will disable any channel that is not provided as an argument. For example, if you enable channel 1, then 2 and 3 will be disabled. If you have previously enabled a channel(s) and fail to include it/them again in this call, that channel(s) will be disabled. For example, if you run the following: self.enable_channel([1]) self.enable_channel([2]) only channel 2 will be enabled and 1 and 3 will be disabled. The correct way to call this method in this case is self.enable_channel([1,2])

Parameters:

channel_numbers – The channel(s) to enable.

disable_all_channels() None

Disable all the channels. Note that this is done indirectly by “enabling” channel 0, which disables channels 1, 2 and 3.

get_channel_state(channel_number: int) AptChannelState

Get the state of the specified channel.

Parameters:

channel_number – The channel to check.

Returns:

The state of the channel as an AptChannelState enum.

start_auto_status_update() None

Start automatic status updates from device.

stop_auto_status_update() None

Stop automatic status updates from device.

home_channel(channel_number: int) None

Start the homing sequence for a given channel. After running this command, you must clear the buffer by checking if the channel was homed, using is_channel_homed()

Parameters:

channel_number – The channel to home.

is_channel_homed(channel_number: int, timeout: float = 0.5) bool

Check if a given channel is homed. This command should only be run after the method home_channel. Otherwise you will read bytes from other commands using this method.

Parameters:
  • channel_number – The channel to check.

  • timeout – The time to wait for a response to the homing command with default value DEFAULT_RESPONSE_TIMEOUT.

Returns:

True if the channel was homed.

Return type:

boolean

move_absolute(channel_number: int, position: float) None

Move a channel to the specified position. The specified position is in degrees. A conversion is done to convert this into encoder counts. This means that there may be a slight mismatch in the specified position and the actual position. You may use the get_status_update method to get the actual position or use is_move_completed to wait until the move is finished.

Parameters:
  • channel_number – The channel to address.

  • position – Absolute position to move to in degrees.

is_move_completed(channel_number: int, timeout: float = 0.5) bool

Check if a given channel has completed its move. This command should only be run after a relative or absolute move command. Otherwise you will read bytes from other commands.

NOTE: If the is_move_completed call is used in a loop to check the move status until a move is

finished (i.e. returns True), it is better to have a short time.sleep (0.01 seconds should suffice) in between the is_move_completed calls. Polling too fast seems to cause issues.

Parameters:
  • channel_number – The channel to check.

  • timeout – The time to wait for a response to the homing command. This is optional and is set to a default value of DEFAULT_RESPONSE_TIMEOUT.

Returns:

True if the move for the channel was completed.

Return type:

boolean

save_parameter_settings(channel_number: int, message_id: int) None

Save parameter settings for a specific message id. These parameters could have been edited via the QMI driver or the GUI provided by Thorlabs.

Parameters:
  • channel_number – The channel to address.

  • message_id – ID of message whose parameters need to be saved. Must be provided as a hex number e.g. 0x04B6

get_status_update(channel_number: int) Thorlabs_Mpc320_Status

Get the status update for a given channel. This call will return the position, velocity, motor current and status of the channel.

Parameters:

channel_number – The channel to query.

Returns:

An instance of Thorlabs_MPC320_Status.

Return type:

status

jog(channel_number: int, direction: AptChannelJogDirection = AptChannelJogDirection.FORWARD) None

Move a channel specified by its jog step.

Parameters:
  • channel_number – The channel to jog.

  • direction – The direction to jog. This can either be forward or backward. Default is forward.

set_polarisation_parameters(velocity: int, home_pos: int, jog_step1: int, jog_step2: int, jog_step3: int) None

Set the polarisation parameters.

Parameters:
  • velocity – Velocity in range 10% to 100% of 400 degrees/s.

  • home_pos – Home position in degrees.

  • jog_step1 – Size of jog step for paddle 1.

  • jog_step2 – Size of jog step for paddle 2.

  • jog_step3 – Size of jog step for paddle 3.

get_polarisation_parameters() Thorlabs_Mpc320_PolarisationParameters

Get the polarisation parameters.

Returns:

An instance of Thorlabs_Mpc320_PolarisationParameters.

Return type:

parameters

force_unlock() None

Forcefully unlock the remote object.

This unlocks the object, regardless of who owns the lock. This allows you to unlock an object if the locking proxy has been destroyed without unlocking.

Use this with care.

Do not override this stub method in subclasses. It has already been implemented in QMI_RpcProxy.

classmethod get_category() str | None

Return the optional name of the category this object belongs to.

A category name is a free-form string that has no special significance. Its purpose is to distinguish between groups of RPC objects that fulfill similar roles.

get_name() str

Return the name of this object.

Returns:

name attribute.

get_signals() list[SignalDescription]

Return a list of signals that can be published by this object.

Returns:

List consisting of qmi_signals attributes.

is_locked() bool

Query if the remote object is locked.

Do not override this stub method in subclasses. It has already been implemented in QMI_RpcProxy.

is_open() bool

Return True if the instrument is open (ready for interaction).

lock(timeout: float = 0.0, lock_token: str | None = None) bool

Lock the remote object. If timeout is given, try every 0.1s within the given timeout value. The remote object can be locked with an optional custom lock token by giving a string into lock_token keyword argument.

If successful, this proxy is the only proxy that can invoke RPC methods on the remote object; other proxies will receive an “object is locked” response. The return value indicates if the lock was granted; a denied lock means the object was already locked by another proxy.

Do not override this stub method in subclasses. It has already been implemented in QMI_RpcProxy.

release_rpc_object() None

Give a warning if the instrument is removed while still open.

unlock(lock_token: str | None = None) bool

Unlock the remote object.

Without optional parameters, this is only allowed by the proxy that initially locked the object. By giving the lock token as an input parameter, the specific object locked by this token can be unlocked. The return value indicates if the unlocking was successful.

Do not override this stub method in subclasses. It has already been implemented in QMI_RpcProxy.