forked from LabExT/LabExT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jslaby6
committed
Jun 11, 2024
1 parent
e7a9b37
commit 5a517e3
Showing
7 changed files
with
358 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
""" | ||
LabExT Copyright (C) 2021 ETH Zurich and Polariton Technologies AG | ||
This program is free software and comes with ABSOLUTELY NO WARRANTY; for details see LICENSE file. | ||
""" | ||
|
||
from LabExT.Instruments.InstrumentAPI import Instrument, InstrumentException | ||
import numpy as np | ||
import win32com.client | ||
import os | ||
import numpy as np | ||
import pythoncom | ||
|
||
class OpticalVectorAnalyzer(Instrument): | ||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
|
||
def open(self): | ||
pythoncom.CoInitialize() | ||
|
||
self.labview_app = win32com.client.Dispatch("LabVIEW.Application") | ||
|
||
# Load the VI #TODO: Needs to be generic | ||
vi_path = os.path.join('C:\\', 'OVA_5000_SDK_v5.14.3','LabVIEW','ConfigureOVA.vi') | ||
vi = self.labview_app.GetVIReference(vi_path) | ||
|
||
vi.Run | ||
|
||
# Grab data in graph object | ||
instrFound = np.array(vi.GetControlValue("instrFound")) | ||
|
||
CfgOK = np.array(vi.GetControlValue("Cfg OK?")) | ||
|
||
if not instrFound or not CfgOK: | ||
raise InstrumentException("Instrument Not Found or Config is Wrong") | ||
else: | ||
return | ||
|
||
def grab_data(self, find_dut_L: bool = True, plot_data_type: str = "INSERTION_LOSS", center_wavelength: float = 1550.00, wl_range: float = 2.54): | ||
# Load the VI #TODO: Needs to be generic | ||
# labview_app = win32com.client.Dispatch("LabVIEW.Application") | ||
vi_path = os.path.join('C:\\', 'OVA_5000_SDK_v5.14.3','LabVIEW','Example Top-Level VIs','_AcquireSingleScan.vi') | ||
vi = self.labview_app.GetVIReference(vi_path) | ||
|
||
wl_range_dict = { | ||
'0.63': 0, | ||
'1.27': 1, | ||
'2.54': 2, | ||
'5.09': 3, | ||
'10.22': 4, | ||
'20.58': 5, | ||
'41.72': 6, | ||
'85.78': 7 | ||
} | ||
|
||
plot_data_dict = { | ||
'INSERTION_LOSS' : 0, | ||
'GROUP_DELAY' : 1, | ||
'CHROMATIC_DISPERSION' : 2, | ||
'POLARIZATION_DEPENDENT_LOSS' : 3, | ||
'POLARIZATION_MODE_DISPERSION' : 4, | ||
'LINEAR_PHASE_DEVIATION' : 5, | ||
'QUADRATIC_PHASE_DEVIATION' : 6, | ||
'JONES_MATRIX_ELEMENT_AMPLITUDES' : 7, | ||
'JONES_MATRIX_ELEMENT_PHASES' : 8, | ||
'TIME_DOMAIN_AMPLITUDE' : 9, | ||
'TIME_DOMAIN_WAVELENGTH' : 10, | ||
'MIN_MAX_LOSS' : 11, | ||
'SECOND_ORDER_PMD' : 12, | ||
'PHASE_RIPPLE_LINEAR' : 13, | ||
'PHASE_RIPPLE_QUADRATIC' : 14 | ||
} | ||
|
||
# Set control values if any | ||
vi.SetControlValue("Find DUT Length?", find_dut_L) | ||
vi.SetControlValue("New Scan", True) | ||
vi.SetControlValue("Plot Data", True) | ||
vi.SetControlValue("Graph Sel", plot_data_dict[plot_data_type]) | ||
vi.SetControlValue("Center WL", center_wavelength) | ||
vi.SetControlValue("WL Range", wl_range_dict[wl_range]) | ||
|
||
vi.Run | ||
|
||
# Grab data in graph object | ||
result = np.array(vi.GetControlValue("Graph")) | ||
|
||
return result | ||
|
||
def save_data(self): | ||
# labview_app = win32com.client.Dispatch("LabVIEW.Application") | ||
vi_path = os.path.join('C:\\', 'OVA_5000_SDK_v5.14.3','LabVIEW','WriteOVASprdshtFile.vi') | ||
vi = self.labview_app.GetVIReference(vi_path) | ||
|
||
# Set control values if any | ||
vi.SetControlValue("Output Spreadsheet File Path", "C:\\Users\\Luna\\Documents\\test.txt") | ||
vi.SetControlValue("Graph Data to Output", [True] * 20) | ||
|
||
vi.Run | ||
|
||
# def close(self): | ||
# pythoncom.CoUninitialize() | ||
# return | ||
|
||
def idn(self): | ||
return f"OVA" | ||
|
||
def get_instrument_parameter(self): | ||
return {'idn': self.idn()} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
from LabExT.Measurements.MeasAPI import * | ||
|
||
class Luna_sweep(Measurement): | ||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) # calling parent constructor | ||
|
||
self.name = 'Luna_sweep' | ||
self.settings_path = 'Luna_sweep_settings.json' | ||
self.ova = None | ||
|
||
@staticmethod | ||
def get_default_parameter(): | ||
return { | ||
'center wavelength': MeasParamFloat(value=1550.0, unit='nm'), | ||
'wavelength range': MeasParamList( | ||
options = ['0.63', '1.27', '2.54', '5.09', '10.22', '20.58', '41.72', '85.78'], | ||
unit = 'nm' | ||
), | ||
'Plot Measurement Type': MeasParamList( | ||
options = ["INSERTION_LOSS", "GROUP_DELAY", 'CHROMATIC_DISPERSION', 'POLARIZATION_DEPENDENT_LOSS', 'POLARIZATION_MODE_DISPERSION', 'LINEAR_PHASE_DEVIATION', 'QUADRATIC_PHASE_DEVIATION', 'JONES_MATRIX_ELEMENT_AMPLITUDES', 'JONES_MATRIX_ELEMENT_PHASES', 'TIME_DOMAIN_AMPLITUDE', 'TIME_DOMAIN_WAVELENGTH', 'MIN_MAX_LOSS', 'SECOND_ORDER_PMD', 'PHASE_RIPPLE_LINEAR', 'PHASE_RIPPLE_QUADRATIC'] | ||
) | ||
} | ||
|
||
@staticmethod | ||
def get_wanted_instrument(): | ||
return ['OVA'] | ||
|
||
def algorithm(self, device, data, instruments, parameters): | ||
self.ova = instruments["OVA"] | ||
self.ova.open() | ||
|
||
center_wavelength = parameters.get('center wavelength').value | ||
wl_range = parameters.get('wavelength range').value | ||
plot_data_type = parameters.get('Plot Measurement Type').value | ||
|
||
result = self.ova.grab_data( | ||
center_wavelength = center_wavelength, | ||
wl_range = wl_range, | ||
plot_data_type = plot_data_type, | ||
) | ||
|
||
self.ova.save_data() | ||
|
||
match plot_data_type: | ||
case "INSERTION_LOSS": | ||
data['values']['wavelength [nm]'] = result[0, 0, :].tolist() | ||
data['values']['Insertion Loss (dB)'] = result[0, 1, :].tolist() | ||
case "GROUP_DELAY": | ||
data['values']['wavelength [nm]'] = result[0, 0, :].tolist() | ||
data['values']['Group Delay (dB)'] = result[0, 1, :].tolist() | ||
case "CHROMATIC_DISPERSION": | ||
data['values']['wavelength [nm]'] = result[0, 0, :].tolist() | ||
data['values']['Chromatic Dispersion (dB)'] = result[0, 1, :].tolist() | ||
case "POLARIZATION_DEPENDENT_LOSS": | ||
data['values']['wavelength [nm]'] = result[0, 0, :].tolist() | ||
data['values']['Polarization Dependent Loss (dB)'] = result[0, 1, :].tolist() | ||
case "POLARIZATION_MODE_DISPERSION": | ||
data['values']['wavelength [nm]'] = result[0, 0, :].tolist() | ||
data['values']['Polarization Mode Dispersion (dB)'] = result[0, 1, :].tolist() | ||
case "LINEAR_PHASE_DEVIATION": | ||
data['values']['wavelength [nm]'] = result[0, 0, :].tolist() | ||
data['values']['Linear Phase Deviation(dB)'] = result[0, 1, :].tolist() | ||
case "QUADRATIC_PHASE_DEVIATION": | ||
data['values']['wavelength [nm]'] = result[0, 0, :].tolist() | ||
data['values']['Quadratic Phase Deviation (dB)'] = result[0, 1, :].tolist() | ||
case "JONES_MATRIX_ELEMENT_AMPLITUDES": | ||
data['values']['wavelength [nm]'] = result[0, 0, :].tolist() | ||
data['values']['Jones Matrix Element Amplitudes A'] = result[0, 1, :].tolist() | ||
data['values']['Jones Matrix Element Amplitudes B'] = result[1, 1, :].tolist() | ||
data['values']['Jones Matrix Element Amplitudes C'] = result[2, 1, :].tolist() | ||
data['values']['Jones Matrix Element Amplitudes D'] = result[3, 1, :].tolist() | ||
case "JONES_MATRIX_ELEMENT_PHASES": | ||
data['values']['wavelength [nm]'] = result[0, 0, :].tolist() | ||
data['values']['Jones Matrix Element Phases A'] = result[0, 1, :].tolist() | ||
data['values']['Jones Matrix Element Phases B'] = result[1, 1, :].tolist() | ||
data['values']['Jones Matrix Element Phases C'] = result[2, 1, :].tolist() | ||
data['values']['Jones Matrix Element Phases D'] = result[3, 1, :].tolist() | ||
case "TIME_DOMAIN_AMPLITUDE": | ||
data['values']['wavelength [nm]'] = result[0, 0, :].tolist() | ||
data['values']['Time Domain Amplitude (dB)'] = result[0, 1, :].tolist() | ||
case "TIME_DOMAIN_WAVELENGTH": | ||
data['values']['wavelength [nm]'] = result[0, 0, :].tolist() | ||
data['values']['Time Domain Wavelength (nm)'] = result[0, 1, :].tolist() | ||
case "MIN_MAX_LOSS": | ||
data['values']['wavelength [nm]'] = result[0, 0, :].tolist() | ||
data['values']['Min Insertion Loss (dB)'] = result[0, 1, :].tolist() | ||
data['values']['Max Insertion Loss (dB)'] = result[1, 1, :].tolist() | ||
case "SECOND_ORDER_PMD": | ||
data['values']['wavelength [nm]'] = result[0, 0, :].tolist() | ||
data['values']['Second Order PMD'] = result[0, 1, :].tolist() | ||
case "PHASE_RIPPLE_LINEAR": | ||
data['values']['wavelength [nm]'] = result[0, 0, :].tolist() | ||
data['values']['Phase Ripple Linear'] = result[0, 1, :].tolist() | ||
case "PHASE_RIPPLE_QUADRATIC": | ||
data['values']['wavelength [nm]'] = result[0, 0, :].tolist() | ||
data['values']['Phase Ripple Quadratic'] = result[0, 1, :].tolist() | ||
case _ : | ||
data['values']['wavelength [nm]'] = result[0, 0, :].tolist() | ||
data['values']['transmission (dB)'] = result[0, 1, :].tolist() | ||
|
||
return data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.