pnpq.devices.switch_thorlabs_osw_e module#

class pnpq.devices.switch_thorlabs_osw_e.AbstractOpticalSwitchThorlabsE#

Bases: ABC

Thread-safe, blocking API for the Thorlabs OSWxx-yyyyE series of optical switches.

abstractmethod close()#

Close the serial connection to the switch.

Once closed, attempting to re-open the connection will cause an InvalidStateException.

Return type:

None

abstractmethod get_board_name()#
Returns:

The switch name and firmware version as a human-readable, unstructured string.

Return type:

str

abstractmethod get_state()#

Get the current state of the switch.

Returns:

The current state of the switch.

Return type:

State

abstractmethod get_type_code()#
Returns:

The board type code according to the configuration table, as a human-readable, unstructured string. The Thorlabs manual does not seem to explain what the configuration table is.

Return type:

str

abstractmethod open()#

Open the serial connection to the switch.

Once opened, attempting to call open() again will cause an InvalidStateException.

Return type:

None

abstractmethod set_state(state)#

Set the switch to the specified state. This function is idempotent; if the switch is already in the desired state, setting it to the same state again will not cause an error.

Parameters:

state (State) – The state to set the switch to.

Return type:

None

class pnpq.devices.switch_thorlabs_osw_e.OpticalSwitchThorlabsE(*, serial_number, serial_config=<factory>)#

Bases: AbstractOpticalSwitchThorlabsE

Thread-safe, blocking driver for the Thorlabs OSWxx-yyyyE series of optical switches.

This driver has been tested on the OSW22-1310E.

Although this driver is cross-platform, it may have difficulty finding devices on MacOS and Linux. These problems can be resolved by modifying your system’s udev configuration as described in Getting Started with PnPQ.

Parameters:
  • serial_number (str) – Required. The device’s serial number, which may contain non-numeric characters. To add to the confusion, the serial number printed on the device’s label may not be the same as the one visible via USB; on Linux, use lsusb -v to identify the correct value.

  • serial_config (SerialConfig) – Optional. Serial connection parameters. The defaults are used by all known devices supported by this class and do not need to be changed.

close()#

Close the serial connection to the switch.

Once closed, attempting to re-open the connection will cause an InvalidStateException.

Return type:

None

get_board_name()#
Returns:

The switch name and firmware version as a human-readable, unstructured string.

Return type:

str

get_state()#

Get the current state of the switch.

Returns:

The current state of the switch.

Return type:

State

get_type_code()#
Returns:

The board type code according to the configuration table, as a human-readable, unstructured string. The Thorlabs manual does not seem to explain what the configuration table is.

Return type:

str

open()#

Open the serial connection to the switch.

Once opened, attempting to call open() again will cause an InvalidStateException.

Return type:

None

serial_config: SerialConfig#
serial_number: str#
set_state(state)#

Set the switch to the specified state. This function is idempotent; if the switch is already in the desired state, setting it to the same state again will not cause an error.

Parameters:

state (State) – The state to set the switch to.

Return type:

None

class pnpq.devices.switch_thorlabs_osw_e.SerialConfig(*, baudrate=115200, bytesize=8, exclusive=True, parity='N', rtscts=True, stopbits=1, timeout=2.0, write_timeout=2.0)#

Bases: object

Serial connection configuration parameters, to be passed to serial.Serial. The defaults are used by all known devices supported by this class and do not need to be changed.

Parameters:
  • baudrate (int)

  • bytesize (int)

  • exclusive (bool)

  • parity (str)

  • rtscts (bool)

  • stopbits (int)

  • timeout (None | float)

  • write_timeout (None | float)

baudrate: int = 115200#
bytesize: int = 8#
exclusive: bool = True#
parity: str = 'N'#
rtscts: bool = True#
stopbits: int = 1#
timeout: None | float = 2.0#
write_timeout: None | float = 2.0#
class pnpq.devices.switch_thorlabs_osw_e.State(*values)#

Bases: Enum

BAR = 1#
CROSS = 2#