AnsweredAssumed Answered

Wavelength sweep with 8164B in Python

Question asked by deraLas on Nov 9, 2020
Latest reply on Nov 26, 2020 by mkelly

Hello,
I have a Keysight 8164B with PowerModule and LaserModule. I am trying to do a wavelength sweep. I am using Python. I manage to establish a connection to the device, I can also read ID and some values which are shown on the screen. But when I perform a measurement and then record results, it does not perform any measurements. Here is my code:

 

import pyvisa as pv
import numpy as np
import matplotlib.pyplot as plt
import math
# Build connection to device
agilent_IP = 'IP Adress'
rm = pv.ResourceManager()
print(rm.list_resources())
laser = rm.open_resource(agilent_IP)
laser.write('*CLS')
print(laser.query('*IDN?'))
# Set parameters
min_wvl = 1270 # minimum wavelength 
max_wvl = 1370 # maximum wavelength 
step = 15 # stepsize
speed = 40 # speed
power = 1 # power
# Set measurement
laser.write('outp0:path lows')
laser.write('trig:conf loop')
laser.write('sour0:pow:stat 1')
print(laser.query('sour0:pow:stat?'))
laser.write('trig0:outp stf')
laser.write('trig0:inp sws')
laser.write('sour0:wav:swe:star {}nm'.format(min_wvl))
laser.write('sour0:wav:swe:stop {}nm'.format(max_wvl))
laser.write('sour0:wav:swe:step {}pm'.format(step))
laser.write('sour0:wav:swe:spe {}nm/s'.format(speed))
laser.write('sour0:wav:swe:mode cont')
laser.write('sour0:wav:swe:llog 1')
print(laser.query('sour0:wav:swe:chec?'))
power = laser.query('sour0:wav:swe:pmax? {}nm,{}nm'.format(min_wvl, max_wvl))
power = 10*math.log10(1000*float(power))
laser.write('sour0:pow {}dbm'.format(power))
exp = laser.query('sour0:wav:swe:exp?')
laser.write('sour0:wav:swe 1')
# Set power meter parameter
laser.write('trig1:inp sme')
laser.write('sens1:pow:unit 1')
laser.write('sens1:pow:rang:auto 0')
laser.write('sens1:pow:rang 10dbm')
print(laser.query('sens1:pow:rang?'))
laser.write('sens1:pow:wav 1320nm')
laser.write('sens1:func:par:logg 20001,100us')
laser.write('sens1:func:stat logg,star')
# Check if sweep is waiting for trigger
var = 0
while var == 0:
var = int(laser.query('sour0:wav:swe:flag?'))
laser.write('sour0:wav:swe:soft')
# Stop measurement and save data
print(laser.query('sens1:func:stat?'))
data = laser.query_binary_values('sens1:func:res?')
flag = int(laser.query('sour0:wav:swe:flag?'))
var = 0
while var:
var = int(laser.query('sour0:wav:swe:flag?'))
data_lambda = laser.query_binary_values('sour0:read:data? llog')
print(laser.query('sour0:wav:swe?'))

# Save data in json file and plot to check results

wave = np.linspace(min_wvl, max_wvl, len(data))
plt.plot(wave, data, 'r')
plt.ylabel('Power in [W]')
plt.xlabel('Wavelenght in [nm]')
plt.show()

Thanks for your help

Outcomes