Welcome to pypdm’s documentation!¶
Getting started!¶
PyPDM is a small and simple Python3 library for controlling Alphanov’s PDM laser sources. Currently supported PDM protocol version is 3.4. Daisy-chain configuration for multiple devices is supported, so it is possible to use many PDMs with only one serial link.
Connecting to PDM devices¶
The following example shows how to connect to a PDM device using the pypdm.PDM
class. The first argument is the PDM device address, which may be different depending on your PDM configuration. The second argument is the serial device path (may be ‘/dev/ttyUSB0’ on linux).
When connecting, the library will query the device version and raise a pypdm.ProtocolVersionNotSupported
exception if not correct.
import pypdm
pdm = pypdm.PDM(1, 'COM0')
If you use multiple laser sources in daisy-chain configuration, you can instantiate one pypdm.PDM
object for each device like in the following example:
import pypdm
pdm1 = pypdm.PDM(1, 'COM0')
pdm2 = pypdm.PDM(2, pdm1) # Use same serial as pdm1
pdm3 = pypdm.PDM(3, pdm1) # Use same serial as pdm1
Daisy-chain configuration must be used for PDM2+ or PDM4+ devices.
Alternatively, you can use the following equivalent code for daisy-chain configuration:
import pypdm
link = pypdm.Link('COM0')
pdm1 = pypdm.PDM(1, link)
pdm2 = pypdm.PDM(2, link)
pdm3 = pypdm.PDM(3, link)
Laser in continuous operation¶
The following example turns on a laser source in continuous mode. Current is set to 30 mA.
import pypdm
pdm = pypdm
pdm = pypdm.PDM(1, 'COM0')
pdm.offset_current = 30
pdm.activation = True
# Apply new settings to the device
pdm.apply()
Configuring the laser source¶
All configuration parameters of PDM devices can be modified using pypdm.PDM
member properties. When a setting is changed, call pypdm.PDM.apply()
to make it effective. Here is the list of properties which can be read or changed (see reference API for more details):
pypdm.PDM.sync_source
pypdm.PDM.delay_line_type
pypdm.PDM.frequency
pypdm.PDM.pulse_width
pypdm.PDM.delay
pypdm.PDM.offset_current
pypdm.PDM.current_percentage
pypdm.PDM.current
pypdm.PDM.temperature
pypdm.PDM.maximum_current
pypdm.PDM.current_source
pypdm.PDM.interlock_status
pypdm.PDM.activation
pypdm.PDM.mode
Laser in pulsed operation¶
The following example turns on a laser source for pulsed operation. Pulse power can be specified using the current_percentage or current properties.
import pypdm
pdm = pypdm
pdm = pypdm.PDM(1, 'COM0')
pdm.offset_current = 0
pdm.current_source = pypdm.CurrentSource.NUMERIC
pdm.current_percentage = 20
pdm.activation = True
# Apply new settings to the device
pdm.apply()
Safety¶
When a PDM object is deleted, the library may try to switch off the laser source for safety. However, you shall not rely on this behavior and always beware of dangers when using laser equipments! Please always wear laser safety glasses or use any appropriate safety equipment to prevent any harmful accident.
Python reference API¶
-
class
pypdm.
PDM
(address, link)¶ Class to command one Alphanov’s PDM laser sources.
-
MAX_DELAY
= 15000¶
-
MAX_PULSE_WIDTH
= 1275000¶
-
__del__
()¶ For safety, disable laser when the object is deleted.
-
__init__
(address, link)¶ Parameters:
-
activation
¶ True when laser is enabled, False when laser is off. Call
apply()
to make any change effective.
-
apply
()¶ Apply all the instructions which are in volatile memory. This makes all settings changes effectives.
-
current
¶ Current, in mA. Please note this property is in milli-amperes and is not a percentage of the maximum current, as the official PDM documentation may state. For the percentage, see current_percentage property. Call
apply()
to make any change effective.Getter: Return diode current configuration. Setter: Set the new current. Raise a ValueError if current is out of bounds.
-
current_percentage
¶ Current, in percentage of maximum. This is an alternative way of changing the
current
property. Callapply()
to make any change effective.
-
current_source
¶ Current source. Set to
CurrentSource.NUMERIC
to control the laser diode pulse current from software through thecurrent
orcurrent_percentage
attributes.Type: CurrentSource
-
delay
¶ Delay, in ps. int. Maximum value is defined in MAX_DELAY.
-
delay_line_type
¶ Delay line type,
DelayLineType
instance.
-
frequency
¶ Frequency, in Hz. int. Read-only.
-
interlock_status
¶ True if interlock is detected, False otherwise.
-
maximum_current
¶ Maximum current, in mA. The getter of this property queries the PDM device once then cache the value for next accesses.
-
offset_current
¶ Offset current, in mA. float.
-
pulse_width
¶ Pulse width, in ps. int. Maximum value is defined in MAX_PULSE_WIDTH.
-
read_address
()¶ Query laser source address.
-
read_protocol_version
()¶ Returns: Protocol version string, for instance ‘3.4’.
-
sync_source
¶ Synchronization source,
SyncSource
instance.
-
temperature
¶ Temperature, in degrees.
-
-
class
pypdm.
Link
(dev)¶ Base PDM communication implementation. An instance of
Link
uses a serial port and can be shared by multiplePDM
instances if the devices are daisy-chained.-
__init__
(dev)¶ Open serial device.
Parameters: dev – Serial device path. For instance ‘/dev/ttyUSB0’ on linux, ‘COM0’ on Windows.
-
-
class
pypdm.
SyncSource
¶ Possible PDM synchronization source.
-
EXTERNAL_LVDS
= 1¶
-
EXTERNAL_TTL_LVTTL
= 0¶
-
INTERNAL
= 2¶
-
-
class
pypdm.
ChecksumError
¶ Thrown if a communication checksum error is detected.
-
class
pypdm.
ProtocolError
¶ Thrown if an unexpected response from the device is received.
-
class
pypdm.
ProtocolVersionNotSupported
(version)¶ Thrown when a PDM protocol version is not (yet) supported by the library.
-
class
pypdm.
ConnectionFailure
¶
-
class
pypdm.
StatusError
(status)¶ Thrown when a PDM device did not respond with ‘OK’ status to the last command.
License¶
PyPDM is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.