-
Notifications
You must be signed in to change notification settings - Fork 4
/
awgcntrl.m
executable file
·165 lines (147 loc) · 5.33 KB
/
awgcntrl.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
function val = awgcntrl(cntrl, chans)
% awgcntrl(cntrl, chans)
% cntrl: stop, start, on off, wait, raw|amp, israw, extoff|exton, isexton, err, clr
% several commands given are processed in order.
% isamp and isexton return a vector of length chans specifying which are
% amp or in exton mode
% (c) 2010 Hendrik Bluhm. Please see LICENSE and COPYRIGHT information in plssetup.m.
global awgdata;
val=[];
if nargin <2
chans = [];
end
breaks = [regexp(cntrl, '\<\w'); regexp(cntrl, '\w\>')];
for k = 1:size(breaks, 2);
switch cntrl(breaks(1, k):breaks(2, k))
case 'stop'
for a=1:length(awgdata)
fprintf(awgdata(a).awg, 'AWGC:STOP');
end
case 'start'
for a=1:length(awgdata)
fprintf(awgdata(a).awg, 'AWGC:RUN');
end
awgcntrl('wait');
case 'off'
for a=1:length(awgdata)
for i = ch(awgdata(a), chans)
fprintf(awgdata(a).awg, 'OUTPUT%i:STAT 0', i);
end
end
case 'on'
for a=1:length(awgdata)
for i = ch(awgdata(a), chans)
fprintf(awgdata(a).awg, 'OUTPUT%i:STAT 1', i);
end
end
case 'wait'
for a=1:length(awgdata)
to = awgdata(a).awg.timeout;
awgdata(a).awg.timeout = 600;
query(awgdata(a).awg, '*OPC?');
awgdata(a).awg.timeout = to;
end
case 'raw'
if any(any(~awgcntrl('israw')))
for a=1:length(awgdata)
if ~is7k(awgdata(a))
for i = ch(awgdata(a), chans)
fprintf(awgdata(a).awg, 'AWGC:DOUT%i:STAT 1', i);
end
end
end
else
fprintf('Already raw\n');
end
case 'amp'
if any(any(awgcntrl('israw')))
for a=1:length(awgdata)
if ~is7k(awgdata(a))
for i = ch(awgdata(a), chans)
fprintf(awgdata(a).awg, 'AWGC:DOUT%i:STAT 0', i);
end
end
end
else
fprintf('Already amp\n');
end
case 'israw'
val=[];
for a=1:length(awgdata)
if ~is7k(awgdata(a))
for i = ch(awgdata(a), chans)
fprintf(awgdata(a).awg, 'AWGC:DOUT%i:STAT?',i);
val(end+1) = fscanf(awgdata(a).awg,'%f');
end
end
end
case 'exton' %adds external DC to outputs specified in chans
for a=1:length(awgdata)
if ~is7k(awgdata(a))
for i = ch(awgdata(a),chans)
fprintf(awgdata(a).awg, 'SOUR%i:COMB:FEED "ESIG"', i);
end
end
end
case 'extoff' %turns off external DC
for a=1:length(awgdata)
if ~is7k(awgdata(a))
for i = ch(awgdata(a),chans)
fprintf(awgdata(a).awg, 'SOUR%i:COMB:FEED ""', i);
end
end
end
case 'isexton'
val=[];
for a=1:length(awgdata)
if ~is7k(awgdata(a))
for i = ch(awgdata(a), chans)
fprintf(awgdata(a).awg, 'SOUR%i:COMB:FEED?',i);
val(end+1) = strcmp(fscanf(awgdata(a).awg, '%f'), 'ESIG');
end
end
end
case 'err'
for a=1:length(awgdata)
err=query(awgdata(a).awg, 'SYST:ERR?');
if strcmp(err(1:end-1), '0,"No error"')
% Supress blank error messages.
else
fprintf('%d: %s\n',a,err);
end
end
case 'clr'
for a=1:length(awgdata)
i = 0;
err2 = sprintf('n/a.\n');
while 1
err = query(awgdata(a).awg, 'SYST:ERR?');
if strcmp(err(1:end-1), '0,"No error"')
if i > 0
fprintf('%d: %i errors. Last %s', a, i, err2);
end
break;
end
err2 = err;
i = i + 1;
end
end
case 'norm'
for i = 1:4
fprintf(awgdata.awg, 'SOUR%i:VOLT:AMPL .6', i);
end
case 'dbl'
for i = 1:4
fprintf(awgdata.awg, 'SOUR%i:VOLT:AMPL 1.2', i);
end
end
end
end
function chans=ch(awg, chans)
if isempty(chans)
chans=1:length(awg.chans);
end
end
function val=is7k(awg)
val=length(awg.chans) <= 2;
end