<jupyter_start><jupyter_text>Closed loop laser scan with NI-DAQmx  Setup<jupyter_code>import time
import numpy as np
import socket

from pylabnet.utils.logging.logger import LogClient
from pylabnet.scripts.lasers import wlm_monitor
from pylabnet.network.client_server import sweeper, si_tt
from pylabnet.scripts.sweeper.sweeper import Sweep1D, MultiChSweep1D
from pylabnet.utils.helper_methods import create_server<jupyter_output><empty_output><jupyter_text>Enter host and port parameters here:<jupyter_code>logger_host = '172.16.58.3'
logger_port = 6265
wavemeter_host = '172.16.58.3'
wavemeter_port = 8298
ctr_host = '192.168.3.11'
ctr_port = 48067<jupyter_output><empty_output><jupyter_text>Instantiate all clients<jupyter_code>exp_log = LogClient(
    host=logger_host,
    port=logger_port,
    module_tag='laser_scan_closed_loop'
)
wm = wlm_monitor.Client(
    host=wavemeter_host,
    port=wavemeter_port,
)
ctr = si_tt.Client(
    host=ctr_host,
    port=ctr_port
)
ctr.start_rate_monitor(name='sweeper', ch_list=[8])
exp = Sweep1D(logger=exp_log)
update_log = LogClient(
    host=logger_host,
    port=logger_port,
    module_tag='1D_update_server'
)
pause_1d_service = sweeper.Service()
pause_1d_service.assign_module(module=exp)
pause_1d_service.assign_logger(logger=update_log)
pause_1d_server, pause_1d_port = create_server(
    service=pause_1d_service,
    logger=update_log,
    host=socket.gethostbyname_ex(socket.gethostname())[2][0]
)
update_log.update_data(data={'port': pause_1d_port})
pause_1d_server.start()<jupyter_output><empty_output><jupyter_text>Experiment Parameters, setup<jupyter_code>f0 = 406.568
f1 = 406.574
pts =401
exp.set_parameters(min=f0, max=f1, pts=pts)<jupyter_output><empty_output><jupyter_text>Experiment script<jupyter_code># wm.update_parameters([{
#         'channel': 7, 'min_voltage': 4
#     }])
def experiment(frequency):

    # Set frequency
    wm.update_parameters([{
        'channel': 6, 'setpoint': frequency
    }])

    return ctr.get_count_rate(name='sweeper', integration=0.1)
    
exp.configure_experiment(experiment)
exp.set_reps(reps=0)
exp.run(plot=True, autosave=True, filename='Sasha_on_scan')
f0 = 406.565
f1 = 406.75
pts = 201
exp.set_parameters(min=f0, max=f1, pts=pts)<jupyter_output><empty_output><jupyter_text>Multi-channel sweep<jupyter_code>mc_log = LogClient(
    host=logger_host,
    port=logger_port,
    module_tag='laser_scan_closed_loop_multichannel'
)

mc_pause_log = LogClient(
    host=logger_host,
    port=logger_port,
    module_tag='MultiCh1D_pause_server'
)

m_exp = MultiChSweep1D(logger=mc_log, channels=['Transmission', 'Reflection'])
pause_m_service = sweeper.Service()
pause_m_service.assign_module(module=exp)
pause_m_service.assign_logger(logger=mc_pause_log)
pause_m_server = create_server(
    service=pause_m_service,
    logger=mc_pause_log,
    host=logger_host
)
m_exp.set_parameters(min=f0, max=f1, pts=pts, reps=4)
def multi_experiment(frequency):
    time.sleep(0.02)
    diffusion = 0.0002*np.sin(2*np.pi*time.time()/50)
    return [
        100 + 0.01/((frequency-406.694+diffusion)**2+(0.0001)**2),
        100 - 0.01/((frequency-406.694+diffusion)**2+(0.0001)**2)
    ]
m_exp.configure_experiment(multi_experiment)
m_exp.run(plot=True)<jupyter_output><empty_output><jupyter_text>Close counter<jupyter_code>#ni.close_timed_counter('counter_0')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1215257244234181, 'fraction_numerical': 0.0446481371969249, 'mean_word_length': 6.534521158129176, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 3, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '340052', 'license': 'MIT', 'n_tokens_mistral': 1398, 'n_tokens_neox': 1304, 'n_words': 170, 'path': 'demo/wavemeter/laser_scan_closed_loop.ipynb', 'repo_name': 'wi11dey/pylabnet', 'size': '3390'}