Package: pyThorlabsAPT
pyThorlabsAPTpyThorlabsAPTis a Python library/GUI interface to control any motor compatible with the Thorlabs APT communication protocol. The package is composed of two parts, a
low-level driver to perform basic operations, and a high-level GUI, written with PyQt5, which can be easily embedded into other GUIs. The low-level driver is essentially a wrapper of the excellent
packagethorlabs_apt, with a few tweaks to speed up loading time and error handling.
Sincethorlabs_aptis not available viapip, its code has been embedded in the code of this package,here.Table of ContentsInstallationUsage via the low-level driverExamplesUsage as a stand-alone GUI interfaceEmbed the GUI within another GUIInstallationThe package uses the Thorlabs APT.dll shared library, and therefore it only works under Windows. To install, follow these steps:Install the script via the package manager pip,pipinstallpyThorlabsAPTInstall the APT software fromhere. The version of the software (32 or 64 bit) must match the one of your python installation.Locate the file APT.dll which has been installed on your computer by the APT software. This file will typically be in the folder "[APT Installation Folder]\APT Server", where
[APT Installation Folder] is the installation folder of the APT software (typically [APT Installation Folder] = C:\Program Files\Thorlabs\APT). Copy the APT.dll into one of these locations:C:\Windows\System32.The folder of your python application.Inside the "[Python packages folder]\pyThorlabsAPT	horlabs_apt". Most of the times [Python packages folder] = "[Python folder]\Lib\site-packages".These steps are enough to run the low-level driver ofpyThorlabsAPT. In order to use the GUI, it is necessary to install additional libraries,
specified in therequirements.txtfile,pipinstallabstract_instrument_interface>=0.6
pipinstall"PyQt5>=5.15.6"pipinstall"pyqtgraph>=0.12.4"pipinstallnumpyUsage via the low-level driverpyThorlabsAPTcan be used to control a device from the command line or from your Python script.ExamplefrompyThorlabsAPT.driverimportpyThorlabsAPTinstrument=pyThorlabsAPT()available_devices=instrument.list_devices()print(available_devices)instrument.connect_device(device_addr=available_devices[0][0])instrument.hardware_infoinstrument.move_home()instrument.move_by(10)instrument.is_in_motion# returns True when instrument is movinginstrument.position=10# Goes to position 10Most of the properties and methods of the classpyThorlabsAPTare actually inherited from thethorlabs_aptpackage.
Here below the main properties and methods are summarized for quick reference.PropertiesPropertyTypeDescriptionCan be set?NotespositionfloatRead or set current position of the motor.Yesstage_info(float,float,int,float)Read current stage parametersNoMethodsMethodReturnsDescriptionlist_devices()listReturns a list of all available devices. Each element of the list identifies a different device, and it is a three-element list in the form[address,identity,model]. The stringaddresscontains the physical address of the device. The stringidncontains the 'identity' of the device. The stringmodelcontains the device model.connect_device(device_addr: str)(str,int)Attempt to connect to the device identified by the address in the stringdevice_addr. It returns a list of two elements. The first element is a string containing either the address of the connected device or an error message. The second element is an integer, equal to 1 if connection was succesful or to 0 otherwise.disconnect_device()(str,int)Attempt to disconnect the currently connected device. It returns a list of two elements. The first element is a string containing info on succesful disconnection or an error message. The second element is an integer, equal to 1 if disconnection was succesful or to 0 otherwise.move_home()move_by(movement: float)intSet the zero to the currently connected (if any) console. The returned value is 1 if the operation was successful, or 0 if any error occurred.set_stage_axis_info(min:float, max:float, units:int, pitch:float)Usage as a stand-alone GUI interfaceThe installation sets up an entry point for the GUI. Just typingpyThorlabsAPTin the command prompt will start the GUI.Embed the GUI within another GUIThe GUI controller can also be easily integrated within a larger graphical interface, as shown in the [TO DO]