# -*- coding: utf-8 -*- """ Created on Sat Nov 9 16:21:22 2024 @author: shen_t2 """ from toptica.lasersdk.dlcpro.v2_6_0 import DLCpro, NetworkConnection, DeviceNotFoundError from toptica.lasersdk.dlcpro.v2_6_0 import Subscription, Timestamp, SubscriptionValue import time def set_widescan_para(DLCPRO_IP, scan_channel, start_value, end_value, scan_speed, start_trig_threshold): try: with DLCpro(NetworkConnection(DLCPRO_IP)) as dlcpro: dlcpro.laser1.wide_scan.output_channel.set(scan_channel) if scan_channel == 79: dlcpro.laser1.ctl.wavelength_set.set(start_value) if scan_channel == 50: dlcpro.laser1.dl.pc.voltage_set.set(start_value) dlcpro.laser1.wide_scan.scan_begin.set(start_value) dlcpro.laser1.wide_scan.scan_end.set(end_value) dlcpro.laser1.wide_scan.shape.set(0) dlcpro.laser1.wide_scan.speed.set(scan_speed) dlcpro.laser1.wide_scan.trigger.output_enabled.set(False) dlcpro.laser1.wide_scan.trigger.output_channel.set(3) dlcpro.io.digital_out3.mode.set(2) dlcpro.laser1.wide_scan.trigger.output_threshold.set(start_trig_threshold) dlcpro.laser1.wide_scan.trigger.output_enabled.set(True) time.sleep(5) print("------------------------------") print("Laser wide scan has been set.") print("Expected scan time: {:.2f} s".format(dlcpro.laser1.wide_scan.duration.get())) except DeviceNotFoundError: print('DLCpro device not found.') return dlcpro def callback(subscription: Subscription, timestamp: Timestamp, value: SubscriptionValue): print("{}: Parameter '{}' changed its value to {}".format(timestamp.time(), subscription.name, value.get())) # %% callback test # if __name__ == '__main__': # with DLCpro(NetworkConnection(Laser_DLCPRO_IP)) as dlc: # with dlc.laser1.wide_scan.state_txt.subscribe(callback): # dlc.run() # time.sleep(5) # dlc.stop() # %% main if __name__ == '__main__': Laser_DLCPRO_IP = "129.129.131.110" wide_scan_output_channel = 79 # 50 = piezo V // 79 = CTL wl // # wide_scan_start_wl = 1530.00 # nm wide_scan_trigger_threshold = 1530.00 # nm wide_scan_end_wl = 1530.40 # nm wide_scan_speed = 0.0010 # nm/s wide_scan_start_wl = wide_scan_trigger_threshold - 15 * wide_scan_speed dlcpro = set_widescan_para(Laser_DLCPRO_IP, wide_scan_output_channel, wide_scan_start_wl, wide_scan_end_wl, wide_scan_speed, wide_scan_trigger_threshold) dlcpro.open() print(dlcpro.laser1.wide_scan.state.get(), dlcpro.laser1.wide_scan.state_txt.get()) dlcpro.laser1.wide_scan.start() # add DAQ tasks here time.sleep(20) dlcpro.laser1.wide_scan.stop() dlcpro.close()