Examples
This page gives examples on how to control a CRONUS-3P remotely through Light Composer using Python.
Light Conversion provides the lightcon Python package which contains the lightcon.cronus3p
module for remote CRONUS-3P control. You will need lightcon v1.5.0 or later.
Remote control in lightcon.cronus3p
is provided by C3PControl
class. Connection to the device is established using:
When controlling a real device you need to make sure that the ip_address
points to the machine that is connected to the CRONUS-3P device and running Light Composer. The serial correct dev_sn
serial number must also be supplied.
You can also test your code on a virtual CRONUS-3P device as described here. The virtual device can run on the same machine in which case ip_address='127.0.0.1'
, or it can run on a different machine which allows you test network connectivity as well.
Remote control is actually performed using HTTP requests. The purpose of the lightcon.cronus3p
module is to simplify device control for Python users that don't want to deal HTTP. If you want to control the CRONUS-3P directly using HTTP refer to the Light Composer API documentation.
The example Python code provided here can also be downloaded as part of the CRONUS-3P SDK.
Quick start
Download lightcon
using pip:
The following example shows how to set wavelength, GDD, and how to open and close the tunable output shutter:
# c3p_quick_start_example.py
# Set wavelength, GDD, and open and close the tunable output shutter.
# Make sure the dev_sn and ip_address arguments match the SN and IP of CRONUS-3P.
from lightcon.cronus3p import C3PControl
target_wavl = 1300
target_gdd = -2500
c3p = C3PControl(dev_sn='C3PV2-Virtual', ip_address='127.0.0.1')
if c3p.connected:
curr_wavl = c3p.get_wavelength()
print("Current wavelength is: {} nm".format(curr_wavl))
curr_gdd = c3p.get_gdd()
print("Current GDD is: {} fs2".format(curr_gdd))
print("Setting wavelength to {} nm".format(target_wavl))
c3p.set_wavelength(target_wavl)
print("Setting GDD to {} fs2".format(target_gdd))
c3p.set_gdd(target_gdd)
input("Press ENTER to OPEN tunable output shutter...")
print("Opening main output shutter")
c3p.open_all_shutters()
input("Press ENTER to CLOSE tunable output shutter...")
print("Closing shutters and setting back to {} nm and {} fs2".format(
curr_wavl, curr_gdd))
c3p.close_all_shutters()
c3p.set_wavelength(curr_wavl)
c3p.set_wavelength(curr_gdd)
Basic operation
Get status
# c3p_get_status.py
# Get CRONUS-3P info and status and the status of its pump laser.
from lightcon.cronus3p import C3PControl
import pprint
c3p = C3PControl(dev_sn='C3PV2-Virtual', ip_address='127.0.0.1')
if c3p.connected:
print("\nCRONUS-3P Info:")
pprint.pprint(c3p.get_info())
print("\nCRONUS-3P Status:")
pprint.pprint(c3p.get_status())
print("\nCRONUS-3P Pump laser status:")
pprint.pprint(c3p.get_pump_laser_status())
Set wavelength
# c3p_set_wavelength.py
# Set the wavelength of the tunable output.
from lightcon.cronus3p import C3PControl
target_wavl = 1300
c3p = C3PControl(dev_sn='C3PV2-Virtual', ip_address='127.0.0.1')
if c3p.connected:
curr_wavl = c3p.get_wavelength()
print("Current wavelength is: {} nm".format(curr_wavl))
print("Setting wavelength to {} nm".format(target_wavl))
c3p.set_wavelength(target_wavl)
Set GDD
# c3p_set_gdd.py
from lightcon.cronus3p import C3PControl
target_gdd = 2000
c3p = C3PControl(dev_sn='C3PV2-Virtual', ip_address='127.0.0.1')
if c3p.connected:
curr_gdd = c3p.get_gdd()
print("Current GDD is: {} fs2".format(curr_gdd))
print("Setting GDD to {} fs2".format(target_gdd))
c3p.set_gdd(target_gdd)
Open and close shutters
# c3p_open_close_shutters.py
# Open and close the tunable output shutter.
from lightcon.cronus3p import C3PControl
c3p = C3PControl(dev_sn='C3PV2-Virtual', ip_address='127.0.0.1')
if c3p.connected:
input("Press ENTER to OPEN all shutters...")
c3p.open_all_shutters()
input("Press ENTER to CLOSE all shutters...")
c3p.close_all_shutters()
Advanced control
Z-stack power control
# c3p_scan_attenuator.py
# Adjust tunable output attenuator during a z-scan.
from time import sleep
import numpy as np
from packaging import version
import lightcon
if version.parse(lightcon.__version__) < version.parse("1.5.6"):
input("This example requires lightcon v1.5.6 or newer")
raise RuntimeError("This example requires lightcon v1.5.6 or newer")
from lightcon.cronus3p import C3PControl
ATTN_FROM = 0
ATTN_TO = 5200
NUM_PTS = 10
c3p = C3PControl(dev_sn='C3PV2-Virtual', ip_address='127.0.0.1',
with_attenuator_control=True, idl_attn_motor_id=12)
if c3p.connected and c3p.check_attenuator():
original_pos = c3p.get_attenuator_pos()
print("Scanning attenuator...")
attn_arr = np.linspace(ATTN_FROM, ATTN_TO, NUM_PTS).astype('int')
for pos in attn_arr:
print("Setting attenuator position to {:.0f} steps".format(pos))
c3p.set_attenuator_pos(pos, wait_until_done=True)
print("Attenuator set, acquire image now")
sleep(3)
print("Attenuator scanning completed")
print("Setting attenuator position back to original {:.0f} steps".format(original_pos))
c3p.set_attenuator_pos(original_pos)
input("Press any key to close this window")
Working with a virtual CRONUS-3P
A virtual CRONUS-3P device is emulated by Light Composer and Topas4 Server, and provides a fully functioning GUI and a REST server that responds just as a real CRONUS-3P would with the following limitations:
- Interlock cannot be activated
- Beam steering is emulated to show random motion, beam steering and centering will not work
To start a virtual CRONUS-3P device launch WinTopas4, click Tools>Launch Demo Device, and select 'Cronus-3P'.
Troubleshooting
CRONUS-3P is controlled remotely by making HTTP requests to a REST server hosted by Light Composer. Simple GET requests (e.g., get status, get current wavelength, etc.) can be made using a web browser by entering the correct URL. Requests to change something (e.g., open a shutter, set wavelength, etc.) need a valid request body, so entering the URL in a browser will not work. The lightcon
examples craft the requests using Python, but you can use any method at your disposal.
We suggest using the provided Python examples first, they should work out of the box. If you can't connect to the device or nothing works, please make sure that the correct IP address and device SN are used. You can also use Postman to test whether the HTTP requests work at all.
For further assistance contact Light Conversion support.
Postman
We recommend using Postman to test whether HTTP requests can be sent to Light Composer and for advanced troubleshooting. A Postman collection is provided for this purpose.
Make sure to set the correct URL for your device after you import the collection. A typical URL is: http://127.0.0.1:35120/CR23000/v0/, where CR23000
is the serial number of your device, 127.0.0.1
is the IP address of the machine running Light Composer, 35120
is the REST service port, and v0
is the REST API version.