-
Notifications
You must be signed in to change notification settings - Fork 0
/
instSpectrometer_AQ6370D.m
108 lines (95 loc) · 3.67 KB
/
instSpectrometer_AQ6370D.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
%% instSpectrometer_AQ6370D.m MN 2023-09-08
% Interface for AQ6370D OSA
%
% Requirements:
% - VISA interface functions in path
% - Equipment is connected on specified VISA address
%
% Usage: measurement = instSpectrometer_AQ6370D(visaAddr, option[, value])
% Returns:
% measurement: Selected measurement, if requested
%
% Parameters:
% visaAddr: Valid VISA address with a DMM connected
% 'option': One of available options below
% 'value': Value for options that require it
%
% Options:
% 'reset': Resets/initializes to defaults
% 'span', [%f %f]: Set span
% 'avg', %i: Set trace averaging
% 'res', %f: Set resolution
% 'N', %i: Set number of trace points
% 'mode': Sense mode; valid [NORM, MID, HIGH1, HIGH2, HIGH3]
% 'trig': Trigger new measurement
% 'meas', 0|1: Return new measurement when ready, with (defauult) or without triggering
%
% TODO:
% - Add more options?
% - Confirm units
function measurement = instSpectrometer_AQ6370D(visaAddr, option, value)
measurement = [];
%% Helper functions
specWrite = @(x) visaWrite(visaAddr, x);
specQuery = @(x) str2double(visaRead(visaAddr, x));
%% Execute selected command
switch lower(option)
case 'reset'
% Set standard settings
specWrite('*RST'); pause(0.5);
specWrite('*CLS');
specWrite(':FORM:DATA REAL,64; :SENS:WAV:STAR 900nm; :SENS:WAV:STOP 1400nm; :SENS:SWE:POIN 501');
case 'span'
if ~exist('value', 'var'); error('Value not provided for span!'); end
if numel(value) < 2; error('Insufficient elements provided for span!'); end
% Set measurement span
specWrite(sprintf(':SENS:WAV:STAR %gnm; :SENS:WAV:STOP %gnm', double(value)));
case 'res'
if ~exist('value', 'var'); error('Value not provided for averaging count!'); end
% Set resolution
specWrite(sprintf(':SENS:BAND %fnm', double(value)));
case 'avg'
if ~exist('value', 'var'); error('Value not provided for resolution!'); end
% Set averaging count
specWrite(sprintf(':SENS:AVER:COUN %i', round(value)));
case 'n'
% Set measurement points
if ~exist('value', 'var'); error('Value not provided for measurement points!'); end
specWrite(sprintf(':SENS:SWE:POIN %i', round(value)));
case 'mode'
% Set measurement mode
if ~exist('value', 'var'); error('Value not provided for measurement mode!'); end
specWrite(sprintf(':SENS:SENS %s', value));
case 'trig'
% Trigger new measurement
specWrite(':ABOR; *CLS; :INIT:IMM'); measurement = NaN;
case 'meas'
% Set data format
specWrite(':FORM:DATA REAL,64; :TRAC:ACT TRA');
% Trigger unless specified otherwise
if exist('value', 'var') && value > 0; specWrite(':ABOR; :INIT:SMOD SING; :INIT:IMM'); end
% Wait for sweep complete
i = 0;
while ~(specQuery(':STAT:OPER:COND?') & 1)
fprintf('.'); i = i+1;
pause(0.5);
if i>3; fprintf(repmat(sprintf('\b'), [1 i])); i = 0; end
end
fprintf(repmat(sprintf('\b'), [1 i]));
% Retrieve spectrum
visaObj = visaConn(visaAddr);
flushinput(visaObj); flushoutput(visaObj);
specWrite(':TRAC:X? TRA');
L = readbinblock(visaObj, 'double');
specWrite(':TRAC:Y? TRA');
P = readbinblock(visaObj, 'double');
measurement = [L(:), P(:)];
% Resume continuous measurements for user
specWrite(':INIT:SMOD REP; :INIT:IMM');
otherwise
if ~isempty(option)
error('Unexpected option "%s"', num2str(option));
end
end
%% Clean up
end