Package: pyPhotonLLTFContrast
pyThorlabsPM100xpyThorlabsPM100xis a Python library/GUI interface to control the Thorlabs consoles PM100A and PM100D. The package is composed of two parts, a
low-level driver to perform basic operations, and high-level GUI, written with PyQt5, which can be easily embedded into other GUIs.Table of ContentsInstallationUsage as a stand-alone GUI interfaceUsage via the low-level driverExamplesInstallationUse the package manager pip to install,pipinstallpyThorlabsPM100xThis should automatically install all libraries needed bypyThorlabsPM100x. If any error occurs during installation, try installing first
the required dependencies separately (one by one), viapipinstall"PyQt5>=5.15.6"pipinstall"pyqtgraph>=0.12.4"pipinstallpyvisa
pipinstallnumpyand then run againpip install pyThorlabsPM100xImportant:in order to be accessible from this library, the console needs to be set to "NI-VISA driver" modality, and not to
"TLPM modality". Typically, if you used recent Thorlabs software to acquire from a console, that will automatically set the console to "TLPM modality".
You can use the utilityPower Meter Driver Switcherto switch between modalities.Usage as a stand-alone GUI interfaceThe installation should set up an entry point for the GUI. Just typingpyThorlabsPM100xin the command prompt will start the GUI.Usage via the low-level driverpyThorlabsPM100xprovides also a low-level driver, based on the librarypyvisa, to directly interface with the powermeter console.frompyThorlabsPM100x.driverimportThorlabsPM100xpowermeter=ThorlabsPM100x()available_devices=powermeter.list_devices()print(available_devices)powermeter.connect_device(device_addr=available_devices[0][0])print(powermeter.power)powermeter.disconnect_device()The methodlist_devices()returns a list, with each element representing one available device in the format[address,identity,model]. The stringaddresscontains
the physical address of the device. The linepowermeter.connect_device(device_addr = available_devices[0][0])establishes a connection to the first device found.
We then print the power currently read by the console, and finally disconnect from it.The classThorlabsPM100xsupports several properties and methods to communicate with the console and to read/change its settings. Some of the properties are read-only, while others can be set. A full list of properties and methods is available here belowPropertiesPropertyTypeDescriptionCan be set?Notespower(float,str)First element of list is the power currently read by the console, second element is the power units.Nopower_unitsstrPower unitsNowavelengthintOperating wavelength (in nanometers) of the console.YesEach powermerter head has a different range of acceptable wavelengths. The driver willnotreturn an error when trying to set a wavelength outside of this range.power_rangefloatCurrent power range, defined as the maximum power measurable in the current rangeYesWhen setting this property to a particular value X, the console will change the power range to the smallest power range which allows to measure the desired power X.min_power_rangefloatMinimum power range available.NoFor the same console/head, this value might vary for different wavelengths.max_power_rangefloatMaximum power range available.NoFor the same console/head, this value might vary for different wavelengths.auto_power_rangeboolDetermines whether the consol is in auto power range or not.Yesbeing_zeroedboolIt is True if zero of the device is currently being set.NoThe propertypowerwill return (None,'') if read whilebeing_zeroed==TrueMethodsMethodReturnsDescriptionlist_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 (which is the answer of the device to the visa query '*IDN?'. The stringmodelcontains the device model (either 'PM100A' or 'PM100D').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 ID number 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. If no device is currently connected, it raises aRuntimeError. 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.read_min_max_wavelength()(float,float)Returns the minimum and maximum operating wavelengths for the connected device. If no device is currently connected, it raises aRuntimeError.set_zero()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.move_to_next_power_range(direction: int)NoneIt increases or decreases the power range of the console, depending on whether the input parameter isdirection=+1ordirection=-1.ExamplesfrompyThorlabsPM100x.driverimportThorlabsPM100xpowermeter=ThorlabsPM100x()available_devices=powermeter.list_devices()#Check which devices are availableprint(available_devices)powermeter.connect_device(device_addr=available_devices[0][0])#Connect to the first available deviceprint(powermeter.power)#print the power currently readprint(powermeter.wavelength)#print the operating wavelength(minWL,maxWL)=powermeter.read_min_max_wavelength()#read max and min available wavelengthspowermeter.wavelength=maxWL#set wavelength to the maxprint(powermeter.power_range)#print current power rangepowermeter.move_to_next_power_range(direction=+1)#increaase power rangeprint(powermeter.power_range)#print new power rangepowermeter.disconnect_device()#disconnect the device